academy.exchange.cloud.authenticate¶
Authenticate users from request headers.
Authenticator
¶
Bases: Protocol
Authenticate users from request headers.
authenticate_user
async
¶
authenticate_user(headers: Mapping[str, str]) -> ClientInfo
Authenticate user from request headers.
Warning
This method must be thread safe!
Parameters:
Returns:
-
ClientInfo–A user id upon authentication success.
Raises:
-
ForbiddenError–user is authenticated but is missing permissions or accessing forbidden resources.
-
UnauthorizedError–user authentication fails.
Source code in academy/exchange/cloud/authenticate.py
NullAuthenticator
¶
Authenticator that implements no authentication.
authenticate_user
async
¶
authenticate_user(headers: Mapping[str, str]) -> ClientInfo
Authenticate user from request headers.
Parameters:
Returns:
-
ClientInfo–Null user regardless of provided headers.
Source code in academy/exchange/cloud/authenticate.py
GlobusAuthenticator
¶
GlobusAuthenticator(
client_id: str | None = None,
client_secret: str | None = None,
*,
token_cache_limit: int = 1024,
token_ttl_s: int = 60,
group_info_cache_ttl_s: int = 60
)
Globus Auth authorizer.
Parameters:
-
client_id(str | None, default:None) –Globus application client ID. If either
client_idorclient_secretisNone, the values will be read from the environment variables as described inget_confidential_app_auth_client. Ignored ifauth_clientis provided. -
client_secret(str | None, default:None) –Globus application client secret. See
client_idfor details. Ignored ifauth_clientis provided. -
token_cache_limit(int, default:1024) –Maximum number of (token, identity) mappings to store in memory.
-
token_ttl_s(int, default:60) –Time in seconds before invalidating cached tokens.
Source code in academy/exchange/cloud/authenticate.py
auth_client
property
¶
auth_client: ConfidentialAppAuthClient
A thread local copy of the Globus AuthClient.
authenticate_user
async
¶
authenticate_user(headers: Mapping[str, str]) -> ClientInfo
Authenticate a Globus Auth user from request header.
This follows from the Globus Sample Data Portal example.
The underlying auth client is not thread safe, but this method is made thread safe using a lock.
Parameters:
Returns:
-
ClientInfo–Globus Auth identity returned via token introspection.
Raises:
-
UnauthorizedError–if the authorization header is missing or the header is malformed.
-
ForbiddenError–if the tokens have expired or been revoked.
-
ForbiddenError–if
audienceis not included in the token's audience.
Source code in academy/exchange/cloud/authenticate.py
get_authenticator
¶
get_authenticator(
config: ExchangeAuthConfig,
) -> Authenticator
Create an authenticator from a configuration.
Parameters:
-
config(ExchangeAuthConfig) –Configuration.
Returns:
-
Authenticator–Authenticator.
Raises:
-
ValueError–if the authentication method in the config is unknown.
Source code in academy/exchange/cloud/authenticate.py
get_token_from_headers
¶
Extract token from websockets headers.
The header is expected to have the format Authorization: Bearer <TOKEN>.
Parameters:
Returns:
-
str–String token.
Raises:
-
UnauthorizedError–if the authorization header is missing.
-
UnauthorizedError–if the authorization header is malformed.