Skip to content

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¤

ProvidedToken(provider_object, method_name)

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¤

from_cmempy(config)

Create an authentication provider from a cmempy environment.

from_context¤

from_context(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) – An ExecutionContext or PluginContext instance from cmem-plugin-base. Must expose a user attribute (UserContext) with a token() method that returns a valid bearer token.

Returns:

  • AuthProvider – A ProvidedToken authentication provider backed by the
  • AuthProvider – context’s UserContext.token() method.

from_dict¤

from_dict(config, d)

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. The OAUTH_GRANT_TYPE key controls which provider is created. Remaining keys are forwarded to the selected provider’s from_dict factory.

Returns:

Raises:

  • ClientEnvConfigError – If OAUTH_GRANT_TYPE is not a supported value or if required keys for the selected provider are missing.

from_env¤

from_env(config)

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:

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_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¤

logger: logging.Logger = logging.getLogger(__name__)

method_name¤

method_name: str = method_name

preferred_username¤

preferred_username: str

The preferred username for the authentication provider.

provider_object¤

provider_object: object = provider_object

Comments