Auth0-PHP

Auth0
in package
implements Auth0Interface

FinalYes

Table of Contents

Interfaces

Auth0Interface

Constants

VERSION  : string = '9.2.0'

Properties

$authentication  : Authentication|null
Authentication Client.
$configuration  : SdkConfiguration|array<string|int, mixed>
$state  : SdkState|null
Instance of SdkState, for shared state across classes.
$transient  : TransientStoreHandler|null
Instance of TransientStoreHandler for storing ephemeral data.
$validatedConfiguration  : SdkConfiguration|null
Instance of SdkConfiguration, for shared configuration across classes.

Methods

__construct()  : mixed
Auth0 Constructor.
authentication()  : AuthenticationInterface
Create, configure, and return an instance of the Authentication class.
clear()  : self
Delete any persistent data and clear out all stored properties.
configuration()  : SdkConfiguration
Retrieve the SdkConfiguration instance.
decode()  : TokenInterface
Verifies and decodes an ID token using the properties in this class.
exchange()  : bool
Exchange authorization code for access, ID, and refresh tokens.
getAccessToken()  : string|null
Get access token from an active session.
getAccessTokenExpiration()  : int|null
Get token expiration from an active session.
getAccessTokenScope()  : array<string|int, string>
Get token scopes from an active session.
getBackchannel()  : string|null
Get the OIDC backchannel logout key generated during exchange(). This is used for session matching with getCredentials() calls, for comparison against cached requests from handleBackchannelLogout().
getBearerToken()  : TokenInterface|null
Get an available bearer token from a variety of input sources.
getCredentials()  : object|null
Return an object representing the current session credentials (including id token, access token, access token expiration, refresh token and user data) without triggering an authorization flow. Returns null when session data is not available.
getExchangeParameters()  : object|null
Get the code exchange details from the GET request.
getIdToken()  : string|null
Get ID token from an active session.
getInvitationParameters()  : null|array{invitation: string, organization: string, organizationName: string}
Get the invitation details from the GET request.
getRefreshToken()  : string|null
Get refresh token from an active session.
getRequestParameter()  : string|null
Get the specified parameter from POST or GET, depending on configured response mode.
getUser()  : null|array<string|int, mixed>
Get userinfo from an active session.
handleBackchannelLogout()  : TokenInterface
Store a OIDC Backchannel Logout request in the cache. Matching sessions will be invalidated on future requests when getCredentials() is called.
handleInvitation()  : string|null
If invitation parameters are present in the request, handle extraction and return a URL for redirection to Universal Login to accept. Returns null if no invitation parameters were found.
isAuthenticated()  : bool
Returns true if a session is present. Your application must check if the session's access token has expired.
login()  : string
Return the url to the login page.
loginWithCustomTokenExchange()  : bool
Exchange an external or custom token for Auth0 tokens (RFC 8693) and establish a session, logging the user in. Requires a stateful `strategy` with sessions configured.
logout()  : string
Delete any persistent data and clear out all stored properties, and return the URI to Auth0 /logout endpoint for redirection.
refreshState()  : self
Updates the SDK's internal state by clearing it's credentials cache, and retrieving the current credentials from the configured session medium. Use this when you directly make changes to the configured session medium to ensure the SDK reflects those changes.
renew()  : self
Renews the access token and ID token using an existing refresh token.
setAccessToken()  : self
Sets and persists the access token.
setAccessTokenExpiration()  : self
Sets and persists the access token expiration unix timestamp.
setAccessTokenScope()  : self
Sets and persists the access token scope.
setBackchannel()  : self
Sets and persists an identifier used for OIDC backchannel logout requests.
setConfiguration()  : self
Set the configuration for the SDK instance.
setIdToken()  : self
Updates the active session's stored Id Token.
setRefreshToken()  : self
Sets and persists the refresh token.
setUser()  : self
Set the user property to a userinfo array and, if configured, persist.
signup()  : string
Return the url to the signup page when using the New Universal Login Experience.
deferStateSaving()  : self
Defer saving transient or session states to destination medium.
getState()  : SdkState
Retrieve state from session storage and configure SDK state.
getTransientStore()  : TransientStoreHandler|null
Create a transient storage handler using the configured transientStorage medium.
processBearerToken()  : TokenInterface|null

Constants

VERSION

public string VERSION = '9.2.0'

Properties

$state

Instance of SdkState, for shared state across classes.

private SdkState|null $state = null

$validatedConfiguration

Instance of SdkConfiguration, for shared configuration across classes.

private SdkConfiguration|null $validatedConfiguration = null

Methods

__construct()

Auth0 Constructor.

public __construct(array<string|int, mixed>|SdkConfiguration $configuration) : mixed
Parameters
$configuration : array<string|int, mixed>|SdkConfiguration

Required. Base configuration options for the SDK. See the SdkConfiguration class constructor for options.

clear()

Delete any persistent data and clear out all stored properties.

public clear([bool $transient = true ]) : self
Parameters
$transient : bool = true

when true, data in transient storage is also cleared

Return values
self

decode()

Verifies and decodes an ID token using the properties in this class.

public decode(string $token[, array<string|int, mixed>|null $tokenAudience = null ][, array<string|int, mixed>|null $tokenOrganization = null ][, string|null $tokenNonce = null ][, int|null $tokenMaxAge = null ][, int|null $tokenLeeway = null ][, int|null $tokenNow = null ][, int|null $tokenType = null ]) : TokenInterface
Parameters
$token : string

ID token to verify and decode

$tokenAudience : array<string|int, mixed>|null = null

Optional. An array of allowed values for the 'aud' claim. Successful if ANY match.

$tokenOrganization : array<string|int, mixed>|null = null

Optional. An array of allowed values for the 'org_id' claim. Successful if ANY match.

$tokenNonce : string|null = null

Optional. The value expected for the 'nonce' claim.

$tokenMaxAge : int|null = null

Optional. Maximum window of time in seconds since the 'auth_time' to accept the token.

$tokenLeeway : int|null = null

Optional. Leeway in seconds to allow during time calculations. Defaults to 60.

$tokenNow : int|null = null

Optional. Unix timestamp representing the current point in time to use for time calculations.

$tokenType : int|null = null
Return values
TokenInterface

exchange()

Exchange authorization code for access, ID, and refresh tokens.

public exchange([string|null $redirectUri = null ][, string|null $code = null ][, string|null $state = null ]) : bool
Parameters
$redirectUri : string|null = null

Optional. Redirect URI sent with authorize request. Defaults to the SDK's configured redirectUri.

$code : string|null = null

Optional. The value of the code parameter. One will be extracted from $_GET if not specified.

$state : string|null = null

Optional. The value of the state parameter. One will be extracted from $_GET if not specified.

Return values
bool

getAccessToken()

Get access token from an active session.

public getAccessToken() : string|null
Return values
string|null

getAccessTokenExpiration()

Get token expiration from an active session.

public getAccessTokenExpiration() : int|null
Return values
int|null

getAccessTokenScope()

Get token scopes from an active session.

public getAccessTokenScope() : array<string|int, string>
Return values
array<string|int, string>

getBackchannel()

Get the OIDC backchannel logout key generated during exchange(). This is used for session matching with getCredentials() calls, for comparison against cached requests from handleBackchannelLogout().

public getBackchannel() : string|null
Return values
string|null

getBearerToken()

Get an available bearer token from a variety of input sources.

public getBearerToken([array<string|int, mixed>|null $get = null ][, array<string|int, mixed>|null $post = null ][, array<string|int, mixed>|null $server = null ][, array<string|int, mixed>|null $haystack = null ][, array<string|int, mixed>|null $needles = null ]) : TokenInterface|null
Parameters
$get : array<string|int, mixed>|null = null

Optional. An array of viable parameter names to search against $_GET as a token candidate.

$post : array<string|int, mixed>|null = null

Optional. An array of viable parameter names to search against $_POST as a token candidate.

$server : array<string|int, mixed>|null = null

Optional. An array of viable parameter names to search against $_SERVER as a token candidate.

$haystack : array<string|int, mixed>|null = null

Optional. A key-value array in which to search for $needles as token candidates.

$needles : array<string|int, mixed>|null = null

Optional. An array of viable keys to search against $haystack as token candidates.

Return values
TokenInterface|null

getCredentials()

Return an object representing the current session credentials (including id token, access token, access token expiration, refresh token and user data) without triggering an authorization flow. Returns null when session data is not available.

public getCredentials() : object|null
Return values
object|null

getExchangeParameters()

Get the code exchange details from the GET request.

public getExchangeParameters() : object|null
Return values
object|null

getIdToken()

Get ID token from an active session.

public getIdToken() : string|null
Return values
string|null

getInvitationParameters()

Get the invitation details from the GET request.

public getInvitationParameters() : null|array{invitation: string, organization: string, organizationName: string}
Return values
null|array{invitation: string, organization: string, organizationName: string}

getRefreshToken()

Get refresh token from an active session.

public getRefreshToken() : string|null
Return values
string|null

getRequestParameter()

Get the specified parameter from POST or GET, depending on configured response mode.

public getRequestParameter(string $parameterName[, int $filter = FILTER_SANITIZE_FULL_SPECIAL_CHARS ][, array<string|int, mixed> $filterOptions = [] ]) : string|null
Parameters
$parameterName : string

name of the parameter to pull from the request

$filter : int = FILTER_SANITIZE_FULL_SPECIAL_CHARS

Defaults to \FILTER_SANITIZE_FULL_SPECIAL_CHARS. The type of PHP filter_var() filter to apply.

$filterOptions : array<string|int, mixed> = []

Optional. Any additional filter_var() sanitization filters to pass. See: https://www.php.net/manual/en/filter.filters.sanitize.php

Return values
string|null

getUser()

Get userinfo from an active session.

public getUser() : null|array<string|int, mixed>
Return values
null|array<string|int, mixed>

handleBackchannelLogout()

Store a OIDC Backchannel Logout request in the cache. Matching sessions will be invalidated on future requests when getCredentials() is called.

public handleBackchannelLogout(string $logoutToken) : TokenInterface
Parameters
$logoutToken : string

An encoded logout token to validate and process.

Return values
TokenInterface

handleInvitation()

If invitation parameters are present in the request, handle extraction and return a URL for redirection to Universal Login to accept. Returns null if no invitation parameters were found.

public handleInvitation([string|null $redirectUrl = null ][, array<string|int, mixed>|null $params = null ]) : string|null
Parameters
$redirectUrl : string|null = null

Optional. URI to return to after logging out. Defaults to the SDK's configured redirectUri.

$params : array<string|int, mixed>|null = null

additional parameters to include with the request

Return values
string|null

isAuthenticated()

Returns true if a session is present. Your application must check if the session's access token has expired.

public isAuthenticated() : bool
Return values
bool

login()

Return the url to the login page.

public login([string|null $redirectUrl = null ][, array<string|int, mixed>|null $params = null ]) : string
Parameters
$redirectUrl : string|null = null

Optional. URI to return to after logging out. Defaults to the SDK's configured redirectUri.

$params : array<string|int, mixed>|null = null

additional parameters to include with the request

Return values
string

loginWithCustomTokenExchange()

Exchange an external or custom token for Auth0 tokens (RFC 8693) and establish a session, logging the user in. Requires a stateful `strategy` with sessions configured.

public loginWithCustomTokenExchange(string $subjectToken, string $subjectTokenType[, string|null $actorToken = null ][, string|null $actorTokenType = null ][, array<string|int, mixed>|null $params = null ]) : bool
Parameters
$subjectToken : string

the token being exchanged

$subjectTokenType : string

a URI identifying the type of subjectToken. Any custom URI scheme is accepted (e.g. urn:acme:token).

$actorToken : string|null = null

Optional. A token representing the acting party for delegation. Requires actorTokenType.

$actorTokenType : string|null = null

Optional. A URI identifying the type of actorToken. Requires actorToken.

$params : array<string|int, mixed>|null = null

Optional. Additional content to include in the body of the API request, such as audience, scope, and organization.

Return values
bool

logout()

Delete any persistent data and clear out all stored properties, and return the URI to Auth0 /logout endpoint for redirection.

public logout([string|null $returnUri = null ][, array<string|int, mixed>|null $params = null ]) : string
Parameters
$returnUri : string|null = null

Optional. URI to return to after logging out. Defaults to the SDK's configured redirectUri.

$params : array<string|int, mixed>|null = null

Optional. Additional parameters to include with the request.

Return values
string

refreshState()

Updates the SDK's internal state by clearing it's credentials cache, and retrieving the current credentials from the configured session medium. Use this when you directly make changes to the configured session medium to ensure the SDK reflects those changes.

public refreshState() : self
Return values
self

renew()

Renews the access token and ID token using an existing refresh token.

public renew([array<string|int, mixed>|null $params = null ]) : self

Scope "offline_access" must be declared in order to obtain refresh token for later token renewal.

Parameters
$params : array<string|int, mixed>|null = null

Optional. Additional parameters to include with the request.

Return values
self

setAccessToken()

Sets and persists the access token.

public setAccessToken(string $accessToken) : self
Parameters
$accessToken : string

access token returned from the code exchange

Return values
self

setAccessTokenExpiration()

Sets and persists the access token expiration unix timestamp.

public setAccessTokenExpiration(int $accessTokenExpiration) : self
Parameters
$accessTokenExpiration : int

unix timestamp representing the expiration time on the access token

Return values
self

setAccessTokenScope()

Sets and persists the access token scope.

public setAccessTokenScope(array<string|int, mixed> $accessTokenScope) : self
Parameters
$accessTokenScope : array<string|int, mixed>

an array of scopes for the access token

Return values
self

setBackchannel()

Sets and persists an identifier used for OIDC backchannel logout requests.

public setBackchannel(string $backchannel) : self
Parameters
$backchannel : string

an OIDC backchannel logout identifier composed of the sub, iss and sid claims from the source ID Token.

Return values
self

setConfiguration()

Set the configuration for the SDK instance.

public setConfiguration(SdkConfiguration|array<string|int, mixed> $configuration) : self
Parameters
$configuration : SdkConfiguration|array<string|int, mixed>

Required. Base configuration options for the SDK. See the SdkConfiguration class constructor for options.

Return values
self

setIdToken()

Updates the active session's stored Id Token.

public setIdToken(string $idToken) : self
Parameters
$idToken : string

id token returned from the code exchange

Return values
self

setRefreshToken()

Sets and persists the refresh token.

public setRefreshToken(string $refreshToken) : self
Parameters
$refreshToken : string

refresh token returned from the code exchange

Return values
self

setUser()

Set the user property to a userinfo array and, if configured, persist.

public setUser(array<string|int, mixed> $user) : self
Parameters
$user : array<string|int, mixed>

user data to store

Return values
self

signup()

Return the url to the signup page when using the New Universal Login Experience.

public signup([string|null $redirectUrl = null ][, array<string|int, mixed>|null $params = null ]) : string
Parameters
$redirectUrl : string|null = null

Optional. URI to return to after logging out. Defaults to the SDK's configured redirectUri.

$params : array<string|int, mixed>|null = null

additional parameters to include with the request

Return values
string

deferStateSaving()

Defer saving transient or session states to destination medium.

private deferStateSaving([bool $deferring = true ]) : self

Improves performance during large blocks of changes.

Parameters
$deferring : bool = true

whether to defer persisting the storage state

Return values
self

getState()

Retrieve state from session storage and configure SDK state.

private getState([bool $reset = false ]) : SdkState
Parameters
$reset : bool = false
Return values
SdkState

getTransientStore()

Create a transient storage handler using the configured transientStorage medium.

private getTransientStore([bool $reset = false ]) : TransientStoreHandler|null
Parameters
$reset : bool = false
Return values
TransientStoreHandler|null
On this page

Search results