oauth2.tokengenerator — Generate Tokens¶
Provides various implementations of algorithms to generate an Access Token or Refresh Token.
Base Class¶
-
class
oauth2.tokengenerator.TokenGenerator[source]¶ Base class of every token generator.
-
create_access_token_data(data, grant_type, user_id)[source]¶ Create data needed by an access token.
Parameters: - data (dict) – Arbitrary data as returned by the
authenticate()method of aSiteAdapter. - grant_type (str) –
- user_id (int) – Identifier of the current user as returned by the
authenticate()method of aSiteAdapter.
Returns: A
dictcontaining theaccess_tokenand thetoken_type. If the value ofTokenGenerator.expires_inis larger than 0, arefresh_tokenwill be generated too.Return type: dict
Changed in version 1.1.0: New parameters
dataanduser_id- data (dict) – Arbitrary data as returned by the
-
generate(data=None, user_id=None)[source]¶ Implemented by generators extending this base class.
Parameters: - data (dict) – Arbitrary data as returned by the
authenticate()method of aSiteAdapter. - user_id (int) – Identifier of the current user as returned by the
authenticate()method of aSiteAdapter.
Raises: NotImplementedError –
Changed in version 1.1.0: New parameters
dataanduser_id- data (dict) – Arbitrary data as returned by the
-
Implementations¶
-
class
oauth2.tokengenerator.URandomTokenGenerator(length=40)[source]¶ Bases:
oauth2.tokengenerator.TokenGeneratorCreate a token using
os.urandom().
-
class
oauth2.tokengenerator.Uuid4[source]¶ Bases:
oauth2.tokengenerator.TokenGeneratorGenerate a token using uuid4.