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 a SiteAdapter.
  • grant_type (str) –
  • user_id (int) – Identifier of the current user as returned by the authenticate() method of a SiteAdapter.
Returns:

A dict containing the access_token and the token_type. If the value of TokenGenerator.expires_in is larger than 0, a refresh_token will be generated too.

Return type:

dict

Changed in version 1.1.0: New parameters data and user_id

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 a SiteAdapter.
  • user_id (int) – Identifier of the current user as returned by the authenticate() method of a SiteAdapter.
Raises:

NotImplementedError

Changed in version 1.1.0: New parameters data and user_id

Implementations

class oauth2.tokengenerator.URandomTokenGenerator(length=40)[source]

Bases: oauth2.tokengenerator.TokenGenerator

Create a token using os.urandom().

generate(data=None, user_id=None)[source]
Returns:A new token
Return type:str
class oauth2.tokengenerator.Uuid4[source]

Bases: oauth2.tokengenerator.TokenGenerator

Generate a token using uuid4.

generate(data=None, user_id=None)[source]
Returns:A new token
Return type:str