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.
An access token and associated data.
Base class for persisting an access token after it has been generated.
Used in two-legged and three-legged authentication flows.
Fetches an access token from the store using its refresh token to identify it.
Parameters: | refresh_token – A string containing the refresh token. |
---|
Stores an access token and additional data.
Parameters: | access_token – An instance of oauth2.AccessToken. |
---|
Base class for writing and retrieving an auth token during the Authorization Code Grant flow.
Returns an AuthorizationCode fetched from a storage.
Parameters: | code – The authorization code. |
---|---|
Returns: | An instance of oauth2.AuthorizationCode. |
Raises : | AuthCodeNotFound if no data could be retrieved for given code. |
Stores the data belonging to an authorization code token.
Parameters: | authorization_code – An instance of oauth2.AuthorizationCode. |
---|
Base class for handling OAuth2 clients.
Retrieve a client by its identifier.
Parameters: | client_id – Identifier of a client app. |
---|---|
Returns: | An instance of oauth2.Client. |
Raises : | ClientNotFoundError |
Bases: oauth2.store.ClientStore
Stores clients in memory.
Add a client app.
Parameters: |
|
---|
Retrieve a client by its identifier.
Parameters: | client_id – Identifier of a client app. |
---|---|
Returns: | An instance of oauth2.Client. |
Raises : | ClientNotFoundError |
Bases: oauth2.store.AccessTokenStore, oauth2.store.AuthCodeStore
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.
Returns an AuthorizationCode.
Parameters: | code – The authorization code. |
---|---|
Returns: | An instance of oauth2.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.AccessToken. |
Raises : | oauth2.error.AccessTokenNotFound |
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.AccessToken. |
Stores the data belonging to an authorization code token.
Parameters: | authorization_code – An instance of oauth2.AuthorizationCode. |
---|
Stores an access token and additional data in memory.
Parameters: | client_id – An instance of oauth2.AccessToken. |
---|
Bases: oauth2.store.AccessTokenStore, oauth2.store.AuthCodeStore
Uses memcache to store access tokens and auth tokens.
This Store supports pylibmc and python-memcached. It tries to use pylibmc first and falls back to python-memcached. Arguments are passed to the underlying client implementation.
Initialization by passing an object:
# This example uses python-memcached
import memcache
# Somewhere in your application
mc = memcache.Client(servers=['127.0.0.1:11211'], debug=0)
# ...
token_store = MemcacheTokenStore(mc=mc)
Initialization using pylibmc:
token_store = MemcacheTokenStore(servers=["127.0.0.1"], binary=True,
behaviors={"tcp_nodelay": True,
"ketama": True})
Initialization using python-memcached:
token_store = MemcacheTokenStore(servers=['127.0.0.1:11211'], debug=0)
Returns data belonging to an authorization code from memcache or None if no data was found.
Stores the data belonging to an authorization code token in memcache.