Models

This module provides the ndb models used in EngineAuth.

class engineauth.models.User(*args, **kwds)[source]

Stores user authentication credentials or authorization ids.

classmethod get_by_auth_id(auth_id)

Returns a user object based on a auth_id.

Parameters:auth_id

String representing a unique id for the user. Examples:

  • own:username
  • google:username
Returns:A user object.
classmethod create_user(auth_ids, **user_values)

Creates a new user.

Parameters:
  • auth_id

    A string that is unique to the user. Users may have multiple auth ids. Example auth ids:

    • own:username
    • own:email@example.com
    • google:username
    • yahoo:username

    The value of auth_id must be unique.

  • user_values – Keyword arguments to create a new user entity. Since the model is an Expando, any provided custom properties will be saved. To hash a plain password, pass a keyword password_raw.
Returns:

A tuple (boolean, info). The boolean indicates if the user was created. If creation succeeds, info is the user entity; otherwise it is a list of duplicated unique properties that caused creation to fail.

class engineauth.models.UserProfile(*args, **kwds)[source]

ndb.Expando is used to store the user_info object as well as any additional information specific to a strategy.

classmethod get_or_create(auth_id, user_info, **kwargs)[source]
class engineauth.models.UserToken(*args, **kwds)[source]

Stores validation tokens for users.

classmethod get_key(user, subject, token)[source]

Returns a token key.

Parameters:
  • user – User unique ID.
  • subject

    The subject of the key. Examples:

    • ‘auth’
    • ‘signup’
  • token – Randomly generated token.
Returns:

model.Key containing a string id in the following format: {user_id}.{subject}.{token}

classmethod create(user, subject, token=None)[source]

Creates a new token for the given user.

Parameters:
  • user – User unique ID.
  • subject

    The subject of the key. Examples:

    • ‘auth’
    • ‘signup’
  • token – Optionally an existing token may be provided. If None, a random token will be generated.
Returns:

The newly created UserToken.

classmethod get(user=None, subject=None, token=None)[source]

Fetches a user token.

Parameters:
  • user – User unique ID.
  • subject

    The subject of the key. Examples:

    • ‘auth’
    • ‘signup’
  • token – The existing token needing verified.
Returns:

A UserToken or None if the token does not exist.

class engineauth.models.UserEmail(*args, **kwds)[source]
class engineauth.models.Session(*args, **kwds)[source]