oauth2.store — Storing and retrieving data

Store adapters to persist and retrieve data during the OAuth 2.0 process or for later use. This module provides base classes that can be extended to implement your own solution specific to your needs. It also includes implementations for popular storage systems like memcache.

Data types

class oauth2.datatype.AccessToken(client_id, grant_type, token, data={}, expires_at=None, refresh_token=None, scopes=[])[source]

An access token and associated data.

class oauth2.datatype.AuthorizationCode(client_id, code, expires_at, redirect_uri, scopes, data=None)[source]

Holds an authorization code and additional information.

class oauth2.datatype.Client(identifier, secret, redirect_uris=[])[source]

Representation of a client application.

Base classes

class oauth2.store.AccessTokenStore[source]

Base class for persisting an access token after it has been generated.

Used in two-legged and three-legged authentication flows.

fetch_by_refresh_token(refresh_token)[source]

Fetches an access token from the store using its refresh token to identify it.

Parameters:refresh_token – A string containing the refresh token.
save_token(access_token)[source]

Stores an access token and additional data.

Parameters:access_token – An instance of oauth2.datatype.AccessToken.
class oauth2.store.AuthCodeStore[source]

Base class for writing and retrieving an auth token during the Authorization Code Grant flow.

fetch_by_code(code)[source]

Returns an AuthorizationCode fetched from a storage.

Parameters:code – The authorization code.
Returns:An instance of oauth2.datatype.AuthorizationCode.
Raises:AuthCodeNotFound if no data could be retrieved for given code.
save_code(authorization_code)[source]

Stores the data belonging to an authorization code token.

Parameters:authorization_code – An instance of oauth2.AuthorizationCode.
class oauth2.store.ClientStore[source]

Base class for handling OAuth2 clients.

fetch_by_client_id(client_id)[source]

Retrieve a client by its identifier.

Parameters:client_id – Identifier of a client app.
Returns:An instance of oauth2.Client.
Raises:ClientNotFoundError