trait AuthorizationCodeGrant

Traits

Properties

protected OAuthConfig|null $oauthConfig

The immutable OAuth 2 configuration.

from  HasOAuthConfig

Methods

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

Create an OAuth authenticator from a token response.

createOAuthAuthenticator(string $accessToken, string|null $refreshToken = null, CarbonInterface|null $expiresAt = null)

Create an OAuth authenticator.

CarbonInterface|null
resolveOAuthExpiry(mixed $expiresIn)

Resolve an OAuth token expiry.

oauthConfig()

Get the OAuth 2 configuration.

defaultOAuthConfig()

Define the default OAuth 2 configuration.

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.

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

Retrieve the authenticated OAuth user.

resolveAccessTokenRequest(string $code, OAuthConfig $oauthConfig, string|null $codeVerifier = null)

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

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

protected OAuthAuthenticator createOAuthAuthenticator(string $accessToken, string|null $refreshToken = null, CarbonInterface|null $expiresAt = null)

Create an OAuth authenticator.

Parameters

string $accessToken
string|null $refreshToken
CarbonInterface|null $expiresAt

Return Value

OAuthAuthenticator

protected CarbonInterface|null resolveOAuthExpiry(mixed $expiresIn)

Resolve an OAuth token expiry.

Parameters

mixed $expiresIn

Return Value

CarbonInterface|null

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

at line 37
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 93
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 128
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 161
Response getUser(OAuthAuthenticator $authenticator, callable|null $requestModifier = null)

Retrieve the authenticated OAuth user.

Parameters

OAuthAuthenticator $authenticator
callable|null $requestModifier

Return Value

Response

at line 173
protected Request resolveAccessTokenRequest(string $code, OAuthConfig $oauthConfig, string|null $codeVerifier = null)

Resolve the access-token request.

Parameters

string $code
OAuthConfig $oauthConfig
string|null $codeVerifier

Return Value

Request

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

Resolve the refresh-token request.

Parameters

OAuthConfig $oauthConfig
string $refreshToken

Return Value

Request

at line 197
protected Request resolveUserRequest(OAuthConfig $oauthConfig)

Resolve the authenticated-user request.

Parameters

OAuthConfig $oauthConfig

Return Value

Request

at line 205
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