trait AuthorizationCodeGrant

Traits

Properties

protected OAuthConfig|null $oauthConfig

The immutable OAuth 2 configuration.

from  HasOAuthConfig

Methods

oauthConfig()

Get the OAuth 2 configuration.

defaultOAuthConfig()

Define the default OAuth 2 configuration.

array
parseOAuthTokenResponse(Response $response)

Parse the access token, expiry and data of a token response.

array|null
resolveOAuthScopes(mixed $scopes)

Resolve the scopes reported by the provider.

resolveOAuthExpiry(mixed $expiresIn)

Resolve an OAuth token expiry.

accountAuthenticator(OAuthAccount $account, callable|null $requestModifier = null)

Authenticate a connected account and renew its stored credentials when needed.

authorizationUrl(array $scopes = [], string|null $state = null, string $scopeSeparator = ' ', array $additionalQueryParameters = [], string|null $codeChallenge = null, string $codeChallengeMethod = 'S256')

Create an authorization URL and its paired state.

getAccessToken(string $code, string|null $state = null, string|null $expectedState = null, bool $returnResponse = false, callable|null $requestModifier = null, string|null $codeVerifier = null)

Exchange an authorization code for an access token.

refreshAccessToken(OAuthAuthenticator|string $refreshToken, bool $returnResponse = false, callable|null $requestModifier = null)

Refresh an OAuth access token.

createOAuthAuthenticatorFromResponse(Response $response, string|null $fallbackRefreshToken = null)

Create an OAuth authenticator from a token response.

createOAuthAuthenticator(string $accessToken, string|null $refreshToken = null, DateTimeImmutable|null $expiresAt = null, array|null $scopes = null)

Create an OAuth authenticator.

getUser(OAuthAuthenticator $oauthAuthenticator, callable|null $requestModifier = null)

Retrieve the authenticated OAuth user.

resolveAccessTokenRequest(string $code, OAuthConfig $oauthConfig)

Resolve the access-token request.

resolveRefreshTokenRequest(OAuthConfig $oauthConfig, string $refreshToken)

Resolve the refresh-token request.

resolveUserRequest(OAuthConfig $oauthConfig)

Resolve the authenticated-user request.

void
validateState(string|null $state, string|null $expectedState)

Validate returned OAuth state against the expected state.

Details

in HasOAuthConfig at line 24
OAuthConfig oauthConfig()

Get the OAuth 2 configuration.

Return Value

OAuthConfig

in HasOAuthConfig at line 32
abstract protected OAuthConfig defaultOAuthConfig()

Define the default OAuth 2 configuration.

Return Value

OAuthConfig

protected array parseOAuthTokenResponse(Response $response)

Parse the access token, expiry and data of a token response.

Parameters

Response $response

Return Value

array

protected array|null resolveOAuthScopes(mixed $scopes)

Resolve the scopes reported by the provider.

Parameters

mixed $scopes

Return Value

array|null

protected CarbonImmutable|null resolveOAuthExpiry(mixed $expiresIn)

Resolve an OAuth token expiry.

Parameters

mixed $expiresIn

Return Value

CarbonImmutable|null

at line 41
OAuthAccountAuthenticator accountAuthenticator(OAuthAccount $account, callable|null $requestModifier = null)

Authenticate a connected account and renew its stored credentials when needed.

Parameters

OAuthAccount $account
callable|null $requestModifier

Return Value

OAuthAccountAuthenticator

at line 60
AuthorizationUrl authorizationUrl(array $scopes = [], string|null $state = null, string $scopeSeparator = ' ', array $additionalQueryParameters = [], string|null $codeChallenge = null, string $codeChallengeMethod = 'S256')

Create an authorization URL and its paired state.

Parameters

array $scopes
string|null $state
string $scopeSeparator
array $additionalQueryParameters
string|null $codeChallenge
string $codeChallengeMethod

Return Value

AuthorizationUrl

at line 116
OAuthAuthenticator|Response getAccessToken(string $code, string|null $state = null, string|null $expectedState = null, bool $returnResponse = false, callable|null $requestModifier = null, string|null $codeVerifier = null)

Exchange an authorization code for an access token.

Parameters

string $code
string|null $state
string|null $expectedState
bool $returnResponse
callable|null $requestModifier
string|null $codeVerifier

Return Value

OAuthAuthenticator|Response

at line 160
OAuthAuthenticator|Response refreshAccessToken(OAuthAuthenticator|string $refreshToken, bool $returnResponse = false, callable|null $requestModifier = null)

Refresh an OAuth access token.

Parameters

OAuthAuthenticator|string $refreshToken
bool $returnResponse
callable|null $requestModifier

Return Value

OAuthAuthenticator|Response

at line 196
protected OAuthAuthenticator createOAuthAuthenticatorFromResponse(Response $response, string|null $fallbackRefreshToken = null)

Create an OAuth authenticator from a token response.

Parameters

Response $response
string|null $fallbackRefreshToken

Return Value

OAuthAuthenticator

at line 217
protected OAuthAuthenticator createOAuthAuthenticator(string $accessToken, string|null $refreshToken = null, DateTimeImmutable|null $expiresAt = null, array|null $scopes = null)

Create an OAuth authenticator.

Parameters

string $accessToken
string|null $refreshToken
DateTimeImmutable|null $expiresAt
array|null $scopes

Return Value

OAuthAuthenticator

at line 234
Response getUser(OAuthAuthenticator $oauthAuthenticator, callable|null $requestModifier = null)

Retrieve the authenticated OAuth user.

Parameters

OAuthAuthenticator $oauthAuthenticator
callable|null $requestModifier

Return Value

Response

at line 250
protected Request resolveAccessTokenRequest(string $code, OAuthConfig $oauthConfig)

Resolve the access-token request.

Parameters

string $code
OAuthConfig $oauthConfig

Return Value

Request

at line 258
protected Request resolveRefreshTokenRequest(OAuthConfig $oauthConfig, string $refreshToken)

Resolve the refresh-token request.

Parameters

OAuthConfig $oauthConfig
string $refreshToken

Return Value

Request

at line 269
protected Request resolveUserRequest(OAuthConfig $oauthConfig)

Resolve the authenticated-user request.

Parameters

OAuthConfig $oauthConfig

Return Value

Request

at line 277
protected void validateState(string|null $state, string|null $expectedState)

Validate returned OAuth state against the expected state.

Parameters

string|null $state
string|null $expectedState

Return Value

void