application package#

Subpackages#

Submodules#

application.md module#

Adjust Markdown to handle line breaks in lists and other edge cases.

application.tokens module#

This module handles JWT token creation, decoding, and validation for user sessions and API keys.

application.tokens.create_user_token(username)#

Generate a JWT token for a given username and start a session.

This function creates a JWT token using the provided username and a randomly generated token ID. The token is signed using a private key and the RS256 algorithm. After generating the token, it starts a session with the token and username.

Parameters:

username (str) – The username for which the token is being created.

Returns:

The generated JWT token.

Return type:

str

application.tokens.decode_cookies(cookies)#

Decodes a string of cookies into a dictionary.

Parameters:

cookies (str) – A string containing cookies in the format ‘key1=value1; key2=value2; …’.

Returns:

A dictionary where the keys are cookie names and the values are cookie values.

Return type:

dict

application.tokens.decode_user_token(token)#

Decodes a JWT token using a global public key.

Parameters:

token (str) – The JWT token to decode.

Returns:

The decoded token payload.

Return type:

dict

Raises:

InvalidJWTError – If the token is expired or invalid.

application.tokens.get_request_token()#

Extracts the authorization token from the request headers.

The function checks for the ‘Authorization’ header first. If not found, it looks for the ‘Cookie’ header and attempts to decode it to find the ‘Authorization’ token. If neither is found, it returns None.

Returns:

The extracted token if present and valid, otherwise None.

Return type:

str

application.tokens.init()#

Initialize the JWT token system by loading the private and public keys.

Return type:

None

application.tokens.token_is_valid(token)#

Check if the provided token is valid.

This function checks the validity of a token by verifying if it is either a valid session token or a valid API key.

Parameters:

token (str) – The token to be validated.

Returns:

True if the token is valid, False otherwise.

Return type:

bool

Module contents#

This module initializes the Flask application and sets up the database.

It includes the application configuration, schema loading, and route initialization.

application.init(*, no_auth=False, blob_path=None, data_db_url='')#

Initialize the application and database.

Parameters:
  • no_auth (bool) – Flag to disable authentication. Default is False.

  • blob_path (str, optional) – Path to the blob storage. Default is None.

  • data_db_url (str) – URL to the database. Default is an empty string.

Returns:

The initialized Flask application instance.

Return type:

Flask