Auth Controller

Module containing the AuthController class for JWToken-based authentication

class genomcore.controllers.auth.AuthController(config: dict, token: str = None, refresh_token: str = None, env: str = None)

Bases: object

JWToken based auth system

Parameters:
  • token (str | JWToken) – access token

  • refresh_token (str) – token to refresh access token when expired

  • env (str) – authentication environment

property env

Current environment

Getter:

Returns the current environment.

Type:

str

property token

Current token

Getter:

Returns the current token.

Type:

str

property refresh_token

Current refresh token

Getter:

Returns the current refresh token.

Type:

str

property token_type

Current token type

Getter:

Returns the token type.

Type:

str

property host: str

Current authentication host

Getter:

Returns the current authentication host.

Type:

str

property decoded_token: dict

Decoded representation of the JWT token.

If there is no decoded token, return a new one.

Getter:

Returns the decoded token.

Type:

dict

property bearer: str

JWT as Bearer string to format headers.

If the token is expiring in less than 15min compared to current timestamp, return a renewed one.

Getter:

Returns the JWT token as a Bearer string.

Return type:

str

classmethod login(username: str, password: str, organization_id: str, project_id: str | None = None, env: str = 'prod') Tuple[str, str]

Log in to the Biomed system using username, password, and organization.

Parameters:
  • username (str) – User’s username.

  • password (str) – User’s password.

  • organization_id (str) – ID of the organization.

  • project_id (str|optional) – Project identifier, defaults to None

Returns:

A tuple containing the access token and refresh token.

Raises:

Exception – If an error occurs during the request.

Note

The project_id parameter is optional. If provided, the login will be scoped to the specified project. If it’s not provided, the login will be scoped to the default project of the user.

Example:

From genomcore.client import Genomcore

api = Genomcore()
api.auth.login(
    username = "A_VALID_USERNAME",
    password = "A_VALID_PASSWORD",
    organization_id = "A_VALID_ORGANIZATION_ID"
)
decode_jwt(public_key: str | None = None) dict
get_project_id() int

Extracts the project ID from the token.

Returns:

The project ID extracted from the token.

Example:

from genomcore.client import Genomcore

api = Genomcore(token="A_VALID_TOKEN", refresh_token="A_VALID_REFRESH_TOKEN")
api.auth.get_project_id()
refresh(project_id: str | None = None) Dict[str, Any]

Refresh the access token using the refresh token.

This method refreshes the access token using the provided refresh token. It can optionally scope the refresh to a specific project identified by its ID.

Parameters:

project_id (str|optional) – ID of the project to scope the refresh, Defaults to None

Raises:

Exception – If an error occurs during the request.

Returns:

A dictionary containing the new access token and refresh token.

Example:

from genomcore.client import Genomcore

api = Genomcore(token="A_VALID_TOKEN", refresh_token="A_VALID_REFRESH_TOKEN")
api.auth.refresh()
to_json() Dict[str, Any]

Serialize object to json. Ideal to export auth config accross different clients.

Returns:

A dictionary containing the serialized authentication configuration.

Example:

from genomcore.client import Genomcore

api = Genomcore(token="A_VALID_TOKEN", refresh_token="A_VALID_REFRESH_TOKEN")
api.auth.to_json()
__firstlineno__ = 17
__static_attributes__ = ('_auth_host', '_config', '_decoded_token', '_env', '_project_id', '_refresh_token', '_token', '_token_type')