abstract class AbstractTokenStorage implements TokenStorageInterface, TokenStorageManagementInterface

Base class for all token storage classes

Properties

protected OAuthClientInterface $client The Oauth client object using this storage.
protected array $parameters Parameters of this token storage.
protected string $sessionId The id of the session
protected string $sessionPath The path on the server in which the cookie will be available on.

Methods

__construct(OAuthClientInterface $client, array $parameters = [])

Constructs a token storage object derived from this class

string
getSessionId()

Returns the id of the session

string
getSessionCookieName()

Returns the name of a cookie that will be used to store the session id regardless of the token storage system

string
getSessionCookie()

Returns the session id stored in a cookie regardless of the token storage system

string
getSessionPath()

Returns the path on the server in which the cookie will be available on

setSessionId(string $sessionId)

Sets the id of the session

setSessionPath(string $sessionPath)

Sets the path on the server in which the cookie will be available on

deleteSessionCookie()

Deletes the session cookie that holds the session id

initializeOAuthSession()

Creates an OAuthSession object and initializes it.

fetchOAuthSession()

Retrieves the OAuth session or create it if it does not exist

array
getProvidersInCookie()

Returns the OAuth configuration for all providers where the user has logged on.

void
addProviderInCookie()

Adds the OAuth configuration of the current provider to the list of providers where the user has logged on.

void
removeProviderFromCookie()

Removes the OAuth configuration of the current provider from the list of providers where the user has logged on.

bool
createOAuthSession(OAuthSession|null $session)

Creates and saves a new OAuth session

bool
getOAuthSession($session, string $provider, OAuthSession|null $oauthSession)

Retrieves an OAuth session for a given provider

bool
saveOAuthSession(OAuthSession $session)

Saves a session for later use

bool
storeAccessToken(array $accessToken)

Store the values of the access token when it is succefully retrieved from the OAuth provider.

storeUserid(string $userId)

Stores the user ID returned by the OAuth provider

array|bool
getStoredAccessToken()

Retrieve the OAuth access token if it was already previously stored by the storeAccessToken method.

string|null
getStoredState()

Returns the stored state

string|null
getStoredNonce()

Returns the stored nonce

string|null
getStoredUserId()

Returns the stored user ID

Details

at line 60
__construct(OAuthClientInterface $client, array $parameters = [])

Constructs a token storage object derived from this class

Parameters

OAuthClientInterface $client
array $parameters Possible key values are :

  • type

    • session : usage of the superglobal $_SESSION to store the token
    • pdo : usage of a PDO database to store the token
    • cookie : usage of encrypted cookies to store the token
    • apcu : usage of the PHP APC User Cache (APCu) to store the token
  • key (only for type = cookie) : the key used to encrypt the cookie

  • dsn (only for type = pdo) : the information required to connect to the database.

at line 70
protected string getSessionId()

Returns the id of the session

Return Value

string the id of the session

at line 80
protected string getSessionCookieName()

Returns the name of a cookie that will be used to store the session id regardless of the token storage system

Return Value

string the name of the cookie

at line 90
protected string getSessionCookie()

Returns the session id stored in a cookie regardless of the token storage system

Return Value

string

at line 100
protected string getSessionPath()

Returns the path on the server in which the cookie will be available on

Return Value

string the path on the server

at line 111
protected AbstractTokenStorage setSessionId(string $sessionId)

Sets the id of the session

Parameters

string $sessionId the id of the session

Return Value

AbstractTokenStorage

at line 123
protected AbstractTokenStorage setSessionPath(string $sessionPath)

Sets the path on the server in which the cookie will be available on

Parameters

string $sessionPath the path on the server

Return Value

AbstractTokenStorage

at line 132
protected deleteSessionCookie()

Deletes the session cookie that holds the session id

at line 142
protected OAuthSession initializeOAuthSession()

Creates an OAuthSession object and initializes it.

Return Value

OAuthSession the initialized OAuthSession object

at line 157
protected OAuthSession fetchOAuthSession()

Retrieves the OAuth session or create it if it does not exist

Return Value

OAuthSession the OAuthSession object

at line 185
protected array getProvidersInCookie()

Returns the OAuth configuration for all providers where the user has logged on.

Return Value

array the OAuth configuration by provider

at line 200
protected void addProviderInCookie()

Adds the OAuth configuration of the current provider to the list of providers where the user has logged on.

Return Value

void

at line 218
protected void removeProviderFromCookie()

Removes the OAuth configuration of the current provider from the list of providers where the user has logged on.

Return Value

void

at line 232
abstract bool createOAuthSession(OAuthSession|null $session)

Creates and saves a new OAuth session

Parameters

OAuthSession|null $session The variable receiving information about the new session

Return Value

bool true if the session is created, false if not

at line 237
abstract bool getOAuthSession($session, string $provider, OAuthSession|null $oauthSession)

Retrieves an OAuth session for a given provider

Parameters

$session
string $provider The provider
OAuthSession|null $oauthSession The variable receiving information about the session

Return Value

bool

at line 242
abstract bool saveOAuthSession(OAuthSession $session)

Saves a session for later use

Parameters

OAuthSession $session The information about the session

Return Value

bool true if the session is successfully saved, false otherwise

at line 247
bool storeAccessToken(array $accessToken)

Store the values of the access token when it is succefully retrieved from the OAuth provider.

This method is meant to be only be called from inside the class.

Actual implementations should create a sub-class and override this function to make the access token values be stored in other types of containers, like for instance databases.

Parameters

array $accessToken Associative array with properties of the access token. The array may have set the following properties:

  • value: string value of the access token
  • authorized: boolean value that determines if the access token was obtained successfully
  • expiry: (optional) timestamp in ISO format relative to UTC time zone of the access token expiry time
  • type: (optional) type of OAuth token that may determine how it should be used when sending API call requests.
  • refresh: (optional) token that some servers may set to allowing refreshing access tokens when they expire.

Return Value

bool This function should return true if the access token was stored successfully.

at line 258
storeUserid(string $userId)

Stores the user ID returned by the OAuth provider

Parameters

string $userId

at line 269
array|bool getStoredAccessToken()

Retrieve the OAuth access token if it was already previously stored by the storeAccessToken method.

This method is meant to be only be called from inside the class.

Actual implementations should create a sub-class and override this method to retrieve the access token values from other types of containers, like for instance databases.

Return Value

array|bool the properties of the access token in an associative array. If the access token was not yet stored, it returns an empty array. Otherwise, the properties it may return are the same that may be passed to the storeAccessToken. This function should return true if the access token was retrieved successfully.

at line 281
string|null getStoredState()

Returns the stored state

Return Value

string|null the stored state

at line 291
string|null getStoredNonce()

Returns the stored nonce

Return Value

string|null the stored nonce

at line 301
string|null getStoredUserId()

Returns the stored user ID

Return Value

string|null the stored user ID