Skip to main content
IntegrationCredential stores OAuth tokens and other credentials that are obtained dynamically and cannot be hardcoded in config files. Credentials are encrypted at rest using Laravel’s encrypted:array cast.

Usage

// Store
IntegrationCredential::put('BusinessCentral', 'sweden', [
    'clientId' => 'abc123',
    'clientSecret' => 'secret456',
    'tenantId' => 'tenant789',
]);

// Retrieve
$credentials = IntegrationCredential::get('BusinessCentral', 'sweden');
// Returns the array, or null if not found

// Check existence
$exists = IntegrationCredential::exists('BusinessCentral', 'sweden');
The first argument is the integration name, the second is a context key (e.g. company identifier or environment).

Pattern: Config Fallback

A common pattern is to check for stored credentials first and fall back to config values:
$credentials = IntegrationCredential::get('BusinessCentral', $company->value);

if ($credentials) {
    return new BusinessCentral(
        clientId: $credentials['clientId'],
        clientSecret: $credentials['clientSecret'],
    );
}

return new BusinessCentral(
    clientId: config('businesscentral.client_id'),
    clientSecret: config('businesscentral.client_secret'),
);
This allows seamless transition from static config to dynamic OAuth-based credentials.