abstract class OpenIdProvider extends AbstractProvider

Traits

Properties

protected string|null $contextNamespace

The unique context namespace for this provider instance.

from  HasProviderContext
protected array $parameters

The custom parameters to be sent with the request.

from  AbstractProvider
protected bool $stateless

Indicates if the session state should be utilized.

from  AbstractProvider
protected array $additionalConfig

The provider's baseline configuration.

from  AbstractProvider
protected array $scopes

The scopes being requested.

from  AbstractProvider
protected string $scopeSeparator

The separating character for the requested scopes.

from  AbstractProvider
protected int $encodingType

The type of the encoding in the query.

from  AbstractProvider
protected bool $usesPKCE

Indicates if PKCE should be used.

from  AbstractProvider
protected bool $usesNonce

Indicates if the nonce should be utilized.

protected array $openidConfig

The OpenID Connect configuration.

protected array|null $jwks

The JSON Web Key Set (JWKS) for the provider.

protected int|null $jwksRefreshAttemptedAt

The timestamp of the last forced JWKS refresh attempt.

protected int $jwksRefreshCooldownSeconds

The minimum seconds between forced JWKS refreshes.

Methods

mixed
getContext(string $key, mixed $default = null)

No description

mixed
setContext(string $key, mixed $value)

No description

mixed
getOrSetContext(string $key, mixed $value)

No description

string
getContextKey(string $key)

No description

__construct(Request $request, string $clientId, string $clientSecret, string $redirectUrl, array $guzzle = [])

Create a new provider instance.

withConfig(array $config)

Set the baseline provider configuration.

setConfig(array $config)

Override provider configuration for the current request.

mixed
getConfig(string|null $key = null, mixed $default = null)

Get a value from the provider configuration.

Client
getHttpClient()

Get an instance of the Guzzle HTTP client.

setHttpClient(Client $client)

Set the Guzzle HTTP client instance.

setRequest(Request $request)

Set the request instance.

getRequest()

Get the request instance.

bool
usesState()

Determine if the provider is operating with state.

bool
isStateless()

Determine if the provider is operating as stateless.

stateless()

Indicate that the provider should operate as stateless.

string
getState()

Get the string used for session state.

with(array $parameters)

Set the custom parameters of the request.

array
getParameters()

Get the custom parameters of the request.

string
getAuthUrl(string|null $state, string|null $nonce = null)

Get the authentication URL for the provider.

string
getTokenUrl()

Get the token URL for the provider.

mixed
getUserByToken(string $token)

Get the raw user for the given access token.

mapUserToObject(array $user)

Map the raw user array to a Socialite User instance.

redirect()

Redirect the user of the application to the provider's authentication screen.

string
buildAuthUrlFromBase(string $url, string|null $state, string|null $nonce = null)

Build the authentication URL for the provider from the given base URL.

array
getCodeFields(string|null $state = null, string|null $nonce = null)

Get the GET parameters for the code request.

string
formatScopes(array $scopes, string $scopeSeparator)

Format the given scopes.

user()

Receive data from auth/callback route code, id_token, scope, state, session_state.

User|null
getUser()

Get the user instance from the context.

setUser(User $user)

Set the user instance in the context.

userInstance(array $response, array $user)

Create a user instance from the given data.

userFromToken(string $token)

Get a Social User instance from a known access token.

bool
hasInvalidState()

Determine if the current request / session has a mismatching "state".

mixed
getAccessTokenResponse(string $code)

Get the access token response for the given code.

array
getTokenHeaders(string $code)

Get the headers for the access token request.

array
getTokenFields(string $code)

Get the POST fields for the token request.

refreshToken(string $refreshToken)

Refresh a user's access token with a refresh token.

mixed
getRefreshTokenResponse(string $refreshToken)

Get the refresh token response for the given refresh token.

string
getCode()

Get the code from the request.

scopes(array|string $scopes)

Merge the scopes of the requested access.

setScopes(array|string $scopes)

Set the scopes of the requested access.

array
getScopes()

Get the current scopes.

redirectUrl(string $url)

Set the redirect URL.

string
getRedirectUrl()

Get the redirect URL.

string
getClientId()

Get the client ID.

string
getClientSecret()

Get the client secret.

bool
usesPKCE()

Determine if the provider uses PKCE.

enablePKCE()

Enable PKCE for the provider.

string
getCodeVerifier()

Generate a random string of the right length for the PKCE code verifier.

string
getCodeChallenge()

Generate the PKCE code challenge based on the PKCE code verifier in the session.

string
getCodeChallengeMethod()

Return the hash method used to calculate the PKCE code challenge.

string
getBaseUrl()

Get the base URL for the OIDC provider.

string|null
getUserInfoUrl()

Get the user_info URL for the provider.

string
getJwksUri(bool $refresh = false)

Get the jwks URI for the provider.

bool
usesNonce()

Determine if the provider is operating with nonce.

string
getNonce()

Get the string used for nonce.

string|null
getCurrentNonce()

Get the current string used for nonce.

array
getOpenIdConfig(bool $refresh = false)

No description

string
getOpenIdConfigUrl()

Get the OpenID Connect configuration URL.

array
getJwks(bool $refresh = false)

Get the JSON Web Key Set (JWKS) for the provider.

bool
canRefreshJwks(bool $refresh)

Determine if the JWKS can be force-refreshed.

array|null
getUserByTokenResponse(array $response)

Get user data by the response from the provider.

bool
isInvalidNonce(string $nonce)

Determine if the current token has a mismatching "nonce".

array|null
getUserByOIDCToken(string $token)

Get user based on the OIDC token.

void
validateOIDCPayload(array $data)

Validate the OIDC payload.

array
appendOIDCPayload(array $payload)

No description

Details

in HasProviderContext at line 19
mixed getContext(string $key, mixed $default = null)

No description

Parameters

string $key
mixed $default

Return Value

mixed

in HasProviderContext at line 24
mixed setContext(string $key, mixed $value)

No description

Parameters

string $key
mixed $value

Return Value

mixed

in HasProviderContext at line 29
mixed getOrSetContext(string $key, mixed $value)

No description

Parameters

string $key
mixed $value

Return Value

mixed

in HasProviderContext at line 34
protected string getContextKey(string $key)

No description

Parameters

string $key

Return Value

string

in AbstractProvider at line 48
__construct(Request $request, string $clientId, string $clientSecret, string $redirectUrl, array $guzzle = [])

Create a new provider instance.

Parameters

Request $request
string $clientId

the client ID

string $clientSecret

the client secret

string $redirectUrl

the redirect URL

array $guzzle

in AbstractProvider at line 58
AbstractProvider withConfig(array $config)

Set the baseline provider configuration.

Called once at registration time (e.g. from a builder or an extend callback). Writes to the instance property so config survives across coroutines. For per-request overrides, use setConfig() instead.

Parameters

array $config

Return Value

AbstractProvider

in AbstractProvider at line 409
AbstractProvider setConfig(array $config)

Override provider configuration for the current request.

Extends the base setConfig to also handle OAuth2-specific credential keys (client_id, client_secret, redirect) in coroutine context.

Parameters

array $config

Return Value

AbstractProvider

in AbstractProvider at line 83
protected mixed getConfig(string|null $key = null, mixed $default = null)

Get a value from the provider configuration.

Reads per-request context first, falls back to baseline instance property.

Parameters

string|null $key
mixed $default

Return Value

mixed

in AbstractProvider at line 93
protected Client getHttpClient()

Get an instance of the Guzzle HTTP client.

Return Value

Client

in AbstractProvider at line 103
AbstractProvider setHttpClient(Client $client)

Set the Guzzle HTTP client instance.

Parameters

Client $client

Return Value

AbstractProvider

in AbstractProvider at line 116
AbstractProvider setRequest(Request $request)

Set the request instance.

Stores the request in coroutine context so cached providers read the current request without leaking it to concurrent coroutines.

Parameters

Request $request

Return Value

AbstractProvider

in AbstractProvider at line 126
protected Request getRequest()

Get the request instance.

Return Value

Request

in AbstractProvider at line 135
protected bool usesState()

Determine if the provider is operating with state.

Return Value

bool

in AbstractProvider at line 143
protected bool isStateless()

Determine if the provider is operating as stateless.

Return Value

bool

in AbstractProvider at line 151
AbstractProvider stateless()

Indicate that the provider should operate as stateless.

Return Value

AbstractProvider

in AbstractProvider at line 161
protected string getState()

Get the string used for session state.

Return Value

string

in AbstractProvider at line 169
AbstractProvider with(array $parameters)

Set the custom parameters of the request.

Parameters

array $parameters

Return Value

AbstractProvider

in AbstractProvider at line 179
protected array getParameters()

Get the custom parameters of the request.

Return Value

array

at line 80
protected string getAuthUrl(string|null $state, string|null $nonce = null)

Get the authentication URL for the provider.

Parameters

string|null $state
string|null $nonce

Return Value

string

at line 100
protected string getTokenUrl()

Get the token URL for the provider.

Return Value

string

at line 324
protected mixed getUserByToken(string $token)

Get the raw user for the given access token.

Parameters

string $token

Return Value

mixed

in AbstractProvider at line 76
abstract protected User mapUserToObject(array $user)

Map the raw user array to a Socialite User instance.

Parameters

array $user

Return Value

User

at line 57
RedirectResponse redirect()

Redirect the user of the application to the provider's authentication screen.

Return Value

RedirectResponse

at line 92
protected string buildAuthUrlFromBase(string $url, string|null $state, string|null $nonce = null)

Build the authentication URL for the provider from the given base URL.

Parameters

string $url
string|null $state
string|null $nonce

Return Value

string

at line 124
protected array getCodeFields(string|null $state = null, string|null $nonce = null)

Get the GET parameters for the code request.

Parameters

string|null $state
string|null $nonce

Return Value

array

in AbstractProvider at line 131
protected string formatScopes(array $scopes, string $scopeSeparator)

Format the given scopes.

Parameters

array $scopes
string $scopeSeparator

Return Value

string

at line 233
User user()

Receive data from auth/callback route code, id_token, scope, state, session_state.

Return Value

User

in AbstractProvider at line 156
protected User|null getUser()

Get the user instance from the context.

Return Value

User|null

in AbstractProvider at line 164
protected AbstractProvider setUser(User $user)

Set the user instance in the context.

Parameters

User $user

Return Value

AbstractProvider

in AbstractProvider at line 174
protected User userInstance(array $response, array $user)

Create a user instance from the given data.

Parameters

array $response
array $user

Return Value

User

in AbstractProvider at line 189
User userFromToken(string $token)

Get a Social User instance from a known access token.

Parameters

string $token

Return Value

User

in AbstractProvider at line 199
protected bool hasInvalidState()

Determine if the current request / session has a mismatching "state".

Return Value

bool

in AbstractProvider at line 213
mixed getAccessTokenResponse(string $code)

Get the access token response for the given code.

Parameters

string $code

Return Value

mixed

in AbstractProvider at line 226
protected array getTokenHeaders(string $code)

Get the headers for the access token request.

Parameters

string $code

Return Value

array

in AbstractProvider at line 234
protected array getTokenFields(string $code)

Get the POST fields for the token request.

Parameters

string $code

Return Value

array

in AbstractProvider at line 254
Token refreshToken(string $refreshToken)

Refresh a user's access token with a refresh token.

Parameters

string $refreshToken

Return Value

Token

in AbstractProvider at line 269
protected mixed getRefreshTokenResponse(string $refreshToken)

Get the refresh token response for the given refresh token.

Parameters

string $refreshToken

Return Value

mixed

in AbstractProvider at line 285
protected string getCode()

Get the code from the request.

Return Value

string

in AbstractProvider at line 293
AbstractProvider scopes(array|string $scopes)

Merge the scopes of the requested access.

Parameters

array|string $scopes

Return Value

AbstractProvider

in AbstractProvider at line 305
AbstractProvider setScopes(array|string $scopes)

Set the scopes of the requested access.

Parameters

array|string $scopes

Return Value

AbstractProvider

in AbstractProvider at line 318
array getScopes()

Get the current scopes.

Return Value

array

in AbstractProvider at line 328
AbstractProvider redirectUrl(string $url)

Set the redirect URL.

Parameters

string $url

Return Value

AbstractProvider

in AbstractProvider at line 338
protected string getRedirectUrl()

Get the redirect URL.

Return Value

string

in AbstractProvider at line 346
protected string getClientId()

Get the client ID.

Return Value

string

in AbstractProvider at line 354
protected string getClientSecret()

Get the client secret.

Return Value

string

in AbstractProvider at line 362
protected bool usesPKCE()

Determine if the provider uses PKCE.

Return Value

bool

in AbstractProvider at line 370
AbstractProvider enablePKCE()

Enable PKCE for the provider.

Return Value

AbstractProvider

in AbstractProvider at line 380
protected string getCodeVerifier()

Generate a random string of the right length for the PKCE code verifier.

Return Value

string

in AbstractProvider at line 388
protected string getCodeChallenge()

Generate the PKCE code challenge based on the PKCE code verifier in the session.

Return Value

string

in AbstractProvider at line 398
protected string getCodeChallengeMethod()

Return the hash method used to calculate the PKCE code challenge.

Return Value

string

at line 52
abstract protected string getBaseUrl()

Get the base URL for the OIDC provider.

Return Value

string

at line 108
protected string|null getUserInfoUrl()

Get the user_info URL for the provider.

Return Value

string|null

at line 116
protected string getJwksUri(bool $refresh = false)

Get the jwks URI for the provider.

Parameters

bool $refresh

Return Value

string

at line 138
protected bool usesNonce()

Determine if the provider is operating with nonce.

Return Value

bool

at line 146
protected string getNonce()

Get the string used for nonce.

Return Value

string

at line 154
protected string|null getCurrentNonce()

Get the current string used for nonce.

Return Value

string|null

at line 168
protected array getOpenIdConfig(bool $refresh = false)

No description

Parameters

bool $refresh

Return Value

array

Exceptions

ConfigurationFetchingException

at line 189
protected string getOpenIdConfigUrl()

Get the OpenID Connect configuration URL.

This is used to fetch the OIDC configuration.

Return Value

string

at line 197
protected array getJwks(bool $refresh = false)

Get the JSON Web Key Set (JWKS) for the provider.

Parameters

bool $refresh

Return Value

array

at line 222
protected bool canRefreshJwks(bool $refresh)

Determine if the JWKS can be force-refreshed.

Parameters

bool $refresh

Return Value

bool

at line 253
protected array|null getUserByTokenResponse(array $response)

Get user data by the response from the provider.

Parameters

array $response

Return Value

array|null

at line 262
protected bool isInvalidNonce(string $nonce)

Determine if the current token has a mismatching "nonce".

nonce must be validated to prevent replay attacks.

Parameters

string $nonce

Return Value

bool

at line 274
protected array|null getUserByOIDCToken(string $token)

Get user based on the OIDC token.

Parameters

string $token

Return Value

array|null

at line 297
protected void validateOIDCPayload(array $data)

Validate the OIDC payload.

Parameters

array $data

Return Value

void

at line 312
protected array appendOIDCPayload(array $payload)

No description

Parameters

array $payload

Return Value

array