cmem_client.auth_provider.provided_token¤
Provided token authentication provider.
This module provides an authentication provider for scenarios where access tokens are obtained by calling a method on a user-provided object. This enables integration with custom authentication systems, third-party libraries, or dynamic token generation logic that is managed outside the cmem-client library.
The ProvidedToken provider delegates token retrieval to a callable method on an external object, allowing maximum flexibility for custom authentication workflows while maintaining compatibility with the Corporate Memory client interface.
Classes:
- ProvidedToken – Authentication provider that retrieves tokens by calling a method on a provided object.
ProvidedToken¤
Bases: AuthProvider
Authentication provider that retrieves tokens by calling a method on a provided object.
This provider enables integration with custom authentication systems by delegating token retrieval to a callable method on an external object.
Attributes:
- provider_object (
object) – The object containing the token retrieval method. - method_name (
str) – The name of the method to call for retrieving tokens. - logger (
Logger) – Logger for the authentication provider.
Functions:
- from_cmempy – Create an authentication provider from a cmempy environment.
- from_context – Create an authentication provider from a cmem-plugin-base context object.
- from_dict – Create an authentication provider from a plain dictionary.
- from_env – Create an authentication provider from environment variables.
- get_access_token – Get the access token for Bearer Authorization header.
Parameters:
- provider_object (
object) – Object with a callable method that returns access tokens. - method_name (
str) – Name of the method to call on provider_object.
Raises:
AttributeError– If provider_object does not have the specified method.
from_cmempy¤
Create an authentication provider from a cmempy environment.
from_context¤
Create an authentication provider from a cmem-plugin-base context object.
Wraps the token callable exposed by the context’s UserContext in a
ProvidedToken provider.
Parameters:
- context (
object) – AnExecutionContextorPluginContextinstance fromcmem-plugin-base. Must expose auserattribute (UserContext) with atoken()method that returns a valid bearer token.
Returns:
AuthProvider– AProvidedTokenauthentication provider backed by theAuthProvider– context’sUserContext.token()method.
from_dict¤
Create an authentication provider from a plain dictionary.
Selects and configures the appropriate authentication provider based
on the OAUTH_GRANT_TYPE key in the dictionary, defaulting to
"client_credentials" when not specified.
Parameters:
- config (
Config) – Configuration object containing Corporate Memory connection details and endpoint URLs. - d (
dict[str, str]) – Dictionary of configuration values. TheOAUTH_GRANT_TYPEkey controls which provider is created. Remaining keys are forwarded to the selected provider’sfrom_dictfactory.
Returns:
AuthProvider– A configured AuthProvider instance.
Raises:
ClientEnvConfigError– IfOAUTH_GRANT_TYPEis not a supported value or if required keys for the selected provider are missing.
from_env¤
Create an authentication provider from environment variables.
This factory method automatically selects and configures the appropriate authentication provider based on the OAUTH_GRANT_TYPE environment variable. It supports multiple OAuth 2.0 flows and authentication methods.
Parameters:
- config (
Config) – Configuration object containing Corporate Memory connection details and endpoint URLs.
Returns:
AuthProvider– A configured AuthProvider instance appropriate for the environmentAuthProvider– configuration.
Raises:
ClientEnvConfigError– If the OAUTH_GRANT_TYPE is not supported or if required environment variables for the selected provider are missing.
Environment Variables
OAUTH_GRANT_TYPE (optional): The OAuth flow type. Defaults to “client_credentials”. Supported values: - “client_credentials”: Client Credentials Flow for M2M auth - “password”: Resource Owner Password Flow for trusted apps - “prefetched_token”: Use externally obtained access token
get_access_token¤
Get the access token for Bearer Authorization header.
Also sets the preferred username for the authentication provider via the extracted token.
Returns:
str– A valid access token string.
Raises:
ValueError– If the provider returned no access token.
Note
Implementations should handle token refresh logic internally when tokens expire, ensuring this method always returns a valid token.
logger¤
method_name¤
preferred_username¤
The preferred username for the authentication provider.