schrodinger.maestro.auth.utils module

schrodinger.maestro.auth.utils.generate_pkce_pair() Tuple[str, str]

Generate PKCE code verifier and code challenge pair.

Returns:

Tuple of (code_verifier, code_challenge).

schrodinger.maestro.auth.utils.build_auth_url(auth_url: str, client_id: str, redirect_uri: str, scope: str, code_challenge: str, code_challenge_method: str) str

Build the authorization URL for Auth0.

Parameters:
  • auth_url – Auth0 authorization endpoint.

  • client_id – Auth0 client ID.

  • redirect_uri – Redirect URI.

  • scope – OAuth2 scopes.

  • code_challenge – PKCE code challenge.

  • code_challenge_method – PKCE code challenge method.

Returns:

Complete authorization URL.

schrodinger.maestro.auth.utils.is_valid_callback_request(data: str) bool

Check if the received HTTP request is a valid GET callback request.

Parameters:

data – Raw HTTP request data.

Returns:

True if this is a valid GET callback request, False otherwise.

schrodinger.maestro.auth.utils.extract_code_from_callback(callback_data: str) str

Extract authorization code from callback data.

Note: This function assumes the callback_data has already been validated by is_valid_callback_request() and is a valid GET request to /callback.

Parameters:

callback_data – Raw HTTP request data from callback.

Returns:

Authorization code if successful.

Raises:

RuntimeError – If authentication failed or no code received.

schrodinger.maestro.auth.utils.exchange_code_for_tokens(config: Auth0Config, code: str, code_verifier: str) Dict[str, Any]

Exchange authorization code for access and refresh tokens.

Parameters:
  • config – Auth0 configuration object.

  • code – Authorization code received from callback.

  • code_verifier – PKCE code verifier.

Returns:

Tokens dictionary.

Raises:

RuntimeError – If token exchange fails or returns non-200 status.

schrodinger.maestro.auth.utils.refresh_access_token(config: Auth0Config, refresh_token: str) Dict[str, Any]

Refresh access token using a refresh token.

Parameters:
  • config – Auth0 configuration object.

  • refresh_token – The refresh token to use for obtaining new tokens.

Returns:

Tokens dictionary containing new access_token and optionally new refresh_token.

Raises:

RuntimeError – If token refresh fails or returns non-200 status.

schrodinger.maestro.auth.utils.create_success_response() bytes

Create HTTP response for successful authentication.

Returns:

HTTP response bytes.

schrodinger.maestro.auth.utils.create_error_response(error: str) bytes

Create HTTP response for authentication error.

Parameters:

error – Error message.

Returns:

HTTP response bytes.