Credentials Cache (fixie_creds.cache)

Represents a credentials cache that is backed by the file system. This cache is the underlying registration and verification engine for credentials.

Importantly, while the credtials may generate a token for a user, that token is NEVER stored. Instead, the hash of the token is stored. Verification compares the hash of token provided by the user to the stored hashed token.

class fixie_creds.cache.Cache(credsdir=None, seed=None, nbytes=20)[source]

A cache for fixie credentials.

Parameters:

credsdir : str or None, optional

Path to credentials directory, if None, defaults to $FIXIE_CREDS_DIR.

seed : int, bytes, or None, optional

Value to seed to Pythons RNG. This is provided for testing purpose, For production, this should be set to None so that reseeding is done based on system time and other parameters.

nbytes : int, optional

Number of bits to use when generating for tokens.

deregister(user, token)[source]

Deregisters a user.

Parameters:

user : str

Name of the user to deregister.

token : str

The user’s token

Returns:

message : str

Message for status of deregistration

flag : bool

Whether or not the deregistration was successful.

get_user(user)[source]

Returns the user, loading it from the file system if needed.

hash_token(token)[source]

Hashes a token.

load_user(user)[source]

Loads a user into the cache from the filesystem.

register(user, email)[source]

Registers a new user and provides their token.

Parameters:

user : str

Name of the user to register.

email : str

Email address for the user.

Returns:

token or message : str

The token if the registration was successful, and an error message if it wasn’t.

flag : bool

Whether or not the registration was successful.

remove_user(user)[source]

Remove the user from the cache and the file system.

reset(user, email)[source]

Resets a user’s token on the system. The email address here must match the one originally provided.

Parameters:

user : str

Name of the user to register.

email : str

Email address for the user.

Returns:

token or message : str

The token if the registration was successful, and an error message if it wasn’t.

flag : bool

Whether or not the registration was successful.

user_cred_file(user)[source]

Returns the credential filename for a user.

user_exists(user)[source]

Returns whether or not a user exists (ie has been registered).

verify(user, token)[source]

Verifies whether or not the user-token pair match.

Parameters:

user : str

Name of the user.

token : str

The token to verify for the user.

Returns:

verified : bool

Whether or not the user-token pair is valid.

message : str

A message string, if needed.

flag : bool

Whether or not the verification itself could be completed successfully.

write_user(user, email, hashed_token)[source]

Writes a user’s credential file.

credsdir
class fixie_creds.cache.User(user, email, hashed_token)

Create new instance of User(user, email, hashed_token)

count(value) → integer -- return number of occurrences of value
index(value[, start[, stop]]) → integer -- return first index of value.

Raises ValueError if the value is not present.

email

Alias for field number 1

hashed_token

Alias for field number 2

user

Alias for field number 0