oauth2.store.memory — In-memory store adapters

Read or write data from or to local memory.

Though not very valuable in a production setup, these store adapters are great for testing purposes.

class oauth2.store.memory.ClientStore[source]

Stores clients in memory.

add_client(client_id, client_secret, redirect_uris, authorized_grants=None, authorized_response_types=None)[source]

Add a client app.

  • client_id – Identifier of the client app.
  • client_secret – Secret the client app uses for authentication against the OAuth 2.0 provider.
  • redirect_uris – A list of URIs to redirect to.

Retrieve a client by its identifier.

Parameters:client_id – Identifier of a client app.
Returns:An instance of oauth2.Client.
class oauth2.store.memory.TokenStore[source]

Stores tokens in memory.

Useful for testing purposes or APIs with a very limited set of clients. Use memcache or redis as storage to be able to scale.


Deletes an authorization code after use

Parameters:code – The authorization code.

Deletes a refresh token after use

Parameters:refresh_token – The refresh_token.

Returns an AuthorizationCode.

Parameters:code – The authorization code.
Returns:An instance of oauth2.datatype.AuthorizationCode.
Raises:AuthCodeNotFound if no data could be retrieved for given code.

Find an access token by its refresh token.

Parameters:refresh_token – The refresh token that was assigned to an AccessToken.
Returns:The oauth2.datatype.AccessToken.

Returns data associated with an access token or None if no data was found.

Useful for cases like validation where the access token needs to be read again.

Parameters:token – A access token code.
Returns:An instance of oauth2.datatype.AccessToken.
fetch_existing_token_of_user(client_id, grant_type, user_id)[source]

Fetches an access token identified by its client id, type of grant and user id. This method must be implemented to make use of unique access tokens.

  • client_id – Identifier of the client a token belongs to.
  • grant_type – The type of the grant that created the token
  • user_id – Identifier of the user a token belongs to.

An instance of oauth2.datatype.AccessToken.


oauth2.error.AccessTokenNotFound if no data could be retrieved.


Stores the data belonging to an authorization code token.

Parameters:authorization_code – An instance of oauth2.datatype.AuthorizationCode.

Stores an access token and additional data in memory.

Parameters:access_token – An instance of oauth2.datatype.AccessToken.