MONet.auth module#

MONet.auth.get_token(username, password)[source]#

Obtain an authentication token from the KTH IAM OpenID Connect service.

Parameters:
  • username (str) – The username for authentication.

  • password (str) – The password for authentication.

Return type:

str

Returns:

str – The authentication token as a string.

Raises:

requests.HTTPError – If the request to the authentication service fails.

MONet.auth.verify_valid_token_exists(username)[source]#

Checks if a valid authentication token exists for the specified user. This function looks for an authentication token file in the user’s home directory, loads the token, and verifies its validity by decoding the JWT token. It also prints the token’s expiration time if available.

Parameters:

username (str) – The username for which to check the authentication token.

Return type:

bool

Returns:

bool – True if a valid token exists and is not expired, False otherwise.

Raises:

None

MONet.auth.welcome_message(token)[source]#

Generates a welcome message using the preferred username from a JWT token. Decodes the provided JWT token without verifying its signature, extracts the expiration time, prints when the token expires, and returns a welcome message including the preferred username.

Parameters:

token (str) – The JWT token as a string.

Return type:

str

Returns:

str – A welcome message containing the preferred username from the token, or ‘User’ if not present.