Cheetah
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
OAuth2\Storage\Redis Class Reference
Inheritance diagram for OAuth2\Storage\Redis:
OAuth2\OpenID\Storage\AuthorizationCodeInterface OAuth2\Storage\ScopeInterface OAuth2\Storage\JwtBearerInterface OAuth2\Storage\RefreshTokenInterface OAuth2\Storage\UserCredentialsInterface OAuth2\Storage\ClientCredentialsInterface OAuth2\Storage\AccessTokenInterface OAuth2\Storage\AuthorizationCodeInterface

Public Member Functions

 __construct ($redis, $config=array())
 
 getAuthorizationCode ($code)
 
 setAuthorizationCode ($authorization_code, $client_id, $user_id, $redirect_uri, $expires, $scope=null, $id_token=null)
 
 expireAuthorizationCode ($code)
 
 checkUserCredentials ($username, $password)
 
 getUserDetails ($username)
 
 getUser ($username)
 
 setUser ($username, $password, $first_name=null, $last_name=null)
 
 checkClientCredentials ($client_id, $client_secret=null)
 
 isPublicClient ($client_id)
 
 getClientDetails ($client_id)
 
 setClientDetails ($client_id, $client_secret=null, $redirect_uri=null, $grant_types=null, $scope=null, $user_id=null)
 
 checkRestrictedGrantType ($client_id, $grant_type)
 
 getRefreshToken ($refresh_token)
 
 setRefreshToken ($refresh_token, $client_id, $user_id, $expires, $scope=null)
 
 unsetRefreshToken ($refresh_token)
 
 getAccessToken ($access_token)
 
 setAccessToken ($access_token, $client_id, $user_id, $expires, $scope=null)
 
 unsetAccessToken ($access_token)
 
 scopeExists ($scope)
 
 getDefaultScope ($client_id=null)
 
 setScope ($scope, $client_id=null, $type='supported')
 
 getClientKey ($client_id, $subject)
 
 setClientKey ($client_id, $key, $subject=null)
 
 getClientScope ($client_id)
 
 getJti ($client_id, $subject, $audience, $expiration, $jti)
 
 setJti ($client_id, $subject, $audience, $expiration, $jti)
 
- Public Member Functions inherited from OAuth2\Storage\AuthorizationCodeInterface
 setAuthorizationCode ($code, $client_id, $user_id, $redirect_uri, $expires, $scope=null)
 
- Public Member Functions inherited from OAuth2\ResponseType\AuthorizationCodeInterface
 enforceRedirect ()
 
 createAuthorizationCode ($client_id, $user_id, $redirect_uri, $scope=null)
 
- Public Member Functions inherited from OAuth2\ResponseType\ResponseTypeInterface
 getAuthorizeResponse ($params, $user_id=null)
 

Protected Member Functions

 getValue ($key)
 
 setValue ($key, $value, $expire=0)
 
 expireValue ($key)
 

Protected Attributes

 $redis
 
 $config
 

Additional Inherited Members

- Public Attributes inherited from OAuth2\Storage\AuthorizationCodeInterface
const RESPONSE_TYPE_CODE = "code"
 

Detailed Description

redis storage for all storage types

To use, install "predis/predis" via composer

Register client: $storage = new OAuth2\Storage\Redis($redis); $storage->setClientDetails($client_id, $client_secret, $redirect_uri);

Definition at line 18 of file Redis.php.

Constructor & Destructor Documentation

◆ __construct()

OAuth2\Storage\Redis::__construct (   $redis,
  $config = array() 
)

Redis Storage!

Parameters
\Predis\Client$redis
array$config

Definition at line 42 of file Redis.php.

Member Function Documentation

◆ checkClientCredentials()

OAuth2\Storage\Redis::checkClientCredentials (   $client_id,
  $client_secret = null 
)

Make sure that the client credentials is valid.

Parameters
$client_idClient identifier to be check with.
$client_secret(optional) If a secret is required, check that they've given the right one.
Returns
TRUE if the client credentials are valid, and MUST return FALSE if it isn't.
See also
http://tools.ietf.org/html/rfc6749#section-3.1

Implements OAuth2\Storage\ClientCredentialsInterface.

Definition at line 149 of file Redis.php.

◆ checkRestrictedGrantType()

OAuth2\Storage\Redis::checkRestrictedGrantType (   $client_id,
  $grant_type 
)

Check restricted grant types of corresponding client identifier.

If you want to restrict clients to certain grant types, override this function.

Parameters
$client_idClient identifier to be check with.
$grant_typeGrant type to be check with
Returns
TRUE if the grant type is supported by this client identifier, and FALSE if it isn't.

Implements OAuth2\Storage\ClientInterface.

Definition at line 182 of file Redis.php.

◆ checkUserCredentials()

OAuth2\Storage\Redis::checkUserCredentials (   $username,
  $password 
)

Grant access tokens for basic user credentials.

Check the supplied username and password for validity.

You can also use the $client_id param to do any checks required based on a client, if you need that.

Required for OAuth2::GRANT_TYPE_USER_CREDENTIALS.

Parameters
$usernameUsername to be check with.
$passwordPassword to be check with.
Returns
TRUE if the username and password are valid, and FALSE if it isn't. Moreover, if the username and password are valid, and you want to
See also
http://tools.ietf.org/html/rfc6749#section-4.3

Implements OAuth2\Storage\UserCredentialsInterface.

Definition at line 116 of file Redis.php.

◆ expireAuthorizationCode()

OAuth2\Storage\Redis::expireAuthorizationCode (   $code)

once an Authorization Code is used, it must be exipired

See also
http://tools.ietf.org/html/rfc6749#section-4.1.2

The client MUST NOT use the authorization code more than once. If an authorization code is used more than once, the authorization server MUST deny the request and SHOULD revoke (when possible) all tokens previously issued based on that authorization code

Implements OAuth2\Storage\AuthorizationCodeInterface.

Definition at line 107 of file Redis.php.

◆ expireValue()

OAuth2\Storage\Redis::expireValue (   $key)
protected

Definition at line 85 of file Redis.php.

◆ getAccessToken()

OAuth2\Storage\Redis::getAccessToken (   $oauth_token)

Look up the supplied oauth_token from storage.

We need to retrieve access token data as we create and verify tokens.

Parameters
$oauth_tokenoauth_token to be check with.
Returns
An associative array as below, and return NULL if the supplied oauth_token is invalid:
  • expires: Stored expiration in unix timestamp.
  • client_id: (optional) Stored client identifier.
  • user_id: (optional) Stored user identifier.
  • scope: (optional) Stored scope values in space-separated string.
  • id_token: (optional) Stored id_token (if "use_openid_connect" is true).

Implements OAuth2\Storage\AccessTokenInterface.

Definition at line 216 of file Redis.php.

◆ getAuthorizationCode()

OAuth2\Storage\Redis::getAuthorizationCode (   $code)

Fetch authorization code data (probably the most common grant type).

Retrieve the stored data for the given authorization code.

Required for OAuth2::GRANT_TYPE_AUTH_CODE.

Parameters
$codeAuthorization code to be check with.
Returns
An associative array as below, and NULL if the code is invalid
return array(
"client_id" => CLIENT_ID, // REQUIRED Stored client identifier
"user_id" => USER_ID, // REQUIRED Stored user identifier
"expires" => EXPIRES, // REQUIRED Stored expiration in unix timestamp
"redirect_uri" => REDIRECT_URI, // REQUIRED Stored redirect URI
"scope" => SCOPE, // OPTIONAL Stored scope values in space-separated string
);
See also
http://tools.ietf.org/html/rfc6749#section-4.1

Implements OAuth2\Storage\AuthorizationCodeInterface.

Definition at line 93 of file Redis.php.

◆ getClientDetails()

OAuth2\Storage\Redis::getClientDetails (   $client_id)

Get client details corresponding client_id.

OAuth says we should store request URIs for each registered client. Implement this function to grab the stored URI for a given client id.

Parameters
$client_idClient identifier to be check with.
Returns
array Client details. The only mandatory key in the array is "redirect_uri". This function MUST return FALSE if the given client does not exist or is invalid. "redirect_uri" can be space-delimited to allow for multiple valid uris. return array( "redirect_uri" => REDIRECT_URI, // REQUIRED redirect_uri registered for the client "client_id" => CLIENT_ID, // OPTIONAL the client id "grant_types" => GRANT_TYPES, // OPTIONAL an array of restricted grant types "user_id" => USER_ID, // OPTIONAL the user identifier associated with this client "scope" => SCOPE, // OPTIONAL the scopes allowed for this client );

Implements OAuth2\Storage\ClientInterface.

Definition at line 169 of file Redis.php.

◆ getClientKey()

OAuth2\Storage\Redis::getClientKey (   $client_id,
  $subject 
)

Get the public key associated with a client_id

Parameters
$client_idClient identifier to be checked with.
Returns
STRING Return the public key for the client_id if it exists, and MUST return FALSE if it doesn't.

Implements OAuth2\Storage\JwtBearerInterface.

Definition at line 272 of file Redis.php.

◆ getClientScope()

OAuth2\Storage\Redis::getClientScope (   $client_id)

Get the scope associated with this client

Returns
STRING the space-delineated scope list for the specified client_id

Implements OAuth2\Storage\ClientInterface.

Definition at line 293 of file Redis.php.

◆ getDefaultScope()

OAuth2\Storage\Redis::getDefaultScope (   $client_id = null)

The default scope to use in the event the client does not request one. By returning "false", a request_error is returned by the server to force a scope request by the client. By returning "null", opt out of requiring scopes

Parameters
$client_idAn optional client id that can be used to return customized default scopes.
Returns
string representation of default scope, null if scopes are not defined, or false to force scope request by the client

ex: 'default' ex: null

Implements OAuth2\Storage\ScopeInterface.

Definition at line 247 of file Redis.php.

◆ getJti()

OAuth2\Storage\Redis::getJti (   $client_id,
  $subject,
  $audience,
  $expiration,
  $jti 
)

Get a jti (JSON token identifier) by matching against the client_id, subject, audience and expiration.

Parameters
$client_idClient identifier to match.
$subjectThe subject to match.
$audienceThe audience to match.
$expirationThe expiration of the jti.
$jtiThe jti to match.
Returns
An associative array as below, and return NULL if the jti does not exist.
  • issuer: Stored client identifier.
  • subject: Stored subject.
  • audience: Stored audience.
  • expires: Stored expiration in unix timestamp.
  • jti: The stored jti.

Implements OAuth2\Storage\JwtBearerInterface.

Definition at line 306 of file Redis.php.

◆ getRefreshToken()

OAuth2\Storage\Redis::getRefreshToken (   $refresh_token)

Grant refresh access tokens.

Retrieve the stored data for the given refresh token.

Required for OAuth2::GRANT_TYPE_REFRESH_TOKEN.

Parameters
$refresh_tokenRefresh token to be check with.
Returns
An associative array as below, and NULL if the refresh_token is invalid:
  • refresh_token: Refresh token identifier.
  • client_id: Client identifier.
  • user_id: User identifier.
  • expires: Expiration unix timestamp, or 0 if the token doesn't expire.
  • scope: (optional) Scope values in space-separated string.
See also
http://tools.ietf.org/html/rfc6749#section-6

Implements OAuth2\Storage\RefreshTokenInterface.

Definition at line 196 of file Redis.php.

◆ getUser()

OAuth2\Storage\Redis::getUser (   $username)

Definition at line 128 of file Redis.php.

◆ getUserDetails()

OAuth2\Storage\Redis::getUserDetails (   $username)
Returns
ARRAY the associated "user_id" and optional "scope" values This function MUST return FALSE if the requested user does not exist or is invalid. "scope" is a space-separated list of restricted scopes.
return array(
"user_id" => USER_ID, // REQUIRED user_id to be stored with the authorization code or access token
"scope" => SCOPE // OPTIONAL space-separated list of restricted scopes
);

Implements OAuth2\Storage\UserCredentialsInterface.

Definition at line 123 of file Redis.php.

◆ getValue()

OAuth2\Storage\Redis::getValue (   $key)
protected

Definition at line 56 of file Redis.php.

◆ isPublicClient()

OAuth2\Storage\Redis::isPublicClient (   $client_id)

Determine if the client is a "public" client, and therefore does not require passing credentials for certain grant types

Parameters
$client_idClient identifier to be check with.
Returns
TRUE if the client is public, and FALSE if it isn't.
See also
http://tools.ietf.org/html/rfc6749#section-2.3
https://github.com/bshaffer/oauth2-server-php/issues/257

Implements OAuth2\Storage\ClientCredentialsInterface.

Definition at line 159 of file Redis.php.

◆ scopeExists()

OAuth2\Storage\Redis::scopeExists (   $scope)

Check if the provided scope exists.

Parameters
$scopeA space-separated string of scopes.
Returns
TRUE if it exists, FALSE otherwise.

Implements OAuth2\Storage\ScopeInterface.

Definition at line 236 of file Redis.php.

◆ setAccessToken()

OAuth2\Storage\Redis::setAccessToken (   $oauth_token,
  $client_id,
  $user_id,
  $expires,
  $scope = null 
)

Store the supplied access token values to storage.

We need to store access token data as we create and verify tokens.

Parameters
$oauth_tokenoauth_token to be stored.
$client_idclient identifier to be stored.
$user_iduser identifier to be stored.
int$expiresexpiration to be stored as a Unix timestamp.
string$scopeOPTIONAL Scopes to be stored in space-separated string.

Implements OAuth2\Storage\AccessTokenInterface.

Definition at line 221 of file Redis.php.

◆ setAuthorizationCode()

OAuth2\Storage\Redis::setAuthorizationCode (   $code,
  $client_id,
  $user_id,
  $redirect_uri,
  $expires,
  $scope = null,
  $id_token = null 
)

Take the provided authorization code values and store them somewhere.

This function should be the storage counterpart to getAuthCode().

If storage fails for some reason, we're not currently checking for any sort of success/failure, so you should bail out of the script and provide a descriptive fail message.

Required for OAuth2::GRANT_TYPE_AUTH_CODE.

Parameters
$codeauthorization code to be stored.
$client_idclient identifier to be stored.
$user_iduser identifier to be stored.
string$redirect_uriredirect URI(s) to be stored in a space-separated string.
int$expiresexpiration to be stored as a Unix timestamp.
string$scopeOPTIONAL scopes to be stored in space-separated string.
string$id_tokenOPTIONAL the OpenID Connect id_token.

Implements OAuth2\OpenID\Storage\AuthorizationCodeInterface.

Definition at line 98 of file Redis.php.

◆ setClientDetails()

OAuth2\Storage\Redis::setClientDetails (   $client_id,
  $client_secret = null,
  $redirect_uri = null,
  $grant_types = null,
  $scope = null,
  $user_id = null 
)

Definition at line 174 of file Redis.php.

◆ setClientKey()

OAuth2\Storage\Redis::setClientKey (   $client_id,
  $key,
  $subject = null 
)

Definition at line 285 of file Redis.php.

◆ setJti()

OAuth2\Storage\Redis::setJti (   $client_id,
  $subject,
  $audience,
  $expiration,
  $jti 
)

Store a used jti so that we can check against it to prevent replay attacks.

Parameters
$client_idClient identifier to insert.
$subjectThe subject to insert.
$audienceThe audience to insert.
$expirationThe expiration of the jti.
$jtiThe jti to insert.

Implements OAuth2\Storage\JwtBearerInterface.

Definition at line 312 of file Redis.php.

◆ setRefreshToken()

OAuth2\Storage\Redis::setRefreshToken (   $refresh_token,
  $client_id,
  $user_id,
  $expires,
  $scope = null 
)

Take the provided refresh token values and store them somewhere.

This function should be the storage counterpart to getRefreshToken().

If storage fails for some reason, we're not currently checking for any sort of success/failure, so you should bail out of the script and provide a descriptive fail message.

Required for OAuth2::GRANT_TYPE_REFRESH_TOKEN.

Parameters
$refresh_tokenRefresh token to be stored.
$client_idClient identifier to be stored.
$user_idUser identifier to be stored.
$expiresExpiration timestamp to be stored. 0 if the token doesn't expire.
$scope(optional) Scopes to be stored in space-separated string.

Implements OAuth2\Storage\RefreshTokenInterface.

Definition at line 201 of file Redis.php.

◆ setScope()

OAuth2\Storage\Redis::setScope (   $scope,
  $client_id = null,
  $type = 'supported' 
)

Definition at line 256 of file Redis.php.

◆ setUser()

OAuth2\Storage\Redis::setUser (   $username,
  $password,
  $first_name = null,
  $last_name = null 
)

Definition at line 140 of file Redis.php.

◆ setValue()

OAuth2\Storage\Redis::setValue (   $key,
  $value,
  $expire = 0 
)
protected

Definition at line 69 of file Redis.php.

◆ unsetAccessToken()

OAuth2\Storage\Redis::unsetAccessToken (   $access_token)

Definition at line 230 of file Redis.php.

◆ unsetRefreshToken()

OAuth2\Storage\Redis::unsetRefreshToken (   $refresh_token)

Expire a used refresh token.

This is not explicitly required in the spec, but is almost implied. After granting a new refresh token, the old one is no longer useful and so should be forcibly expired in the data store so it can't be used again.

If storage fails for some reason, we're not currently checking for any sort of success/failure, so you should bail out of the script and provide a descriptive fail message.

Parameters
$refresh_tokenRefresh token to be expirse.

Implements OAuth2\Storage\RefreshTokenInterface.

Definition at line 210 of file Redis.php.

Member Data Documentation

◆ $config

OAuth2\Storage\Redis::$config
protected

Definition at line 34 of file Redis.php.

◆ $redis

OAuth2\Storage\Redis::$redis
protected

Definition at line 31 of file Redis.php.


The documentation for this class was generated from the following file: