imednet.auth package

Authentication helpers.

Submodules

imednet.auth.api_key module

API Key authentication strategy.

class imednet.auth.api_key.ApiKeyAuth[source]

Bases: object

Authentication strategy using API Key and Security Key.

__init__(api_key, security_key)[source]

Initialize the API Key authentication strategy.

Parameters:
  • api_key (str) – The iMednet API key.

  • security_key (str) – The iMednet security key.

Return type:

None

get_headers()[source]

Return the API key and security key headers.

Return type:

dict[str, str]

get_user_id()[source]

Return the ID of the authenticated user.

Returns:

A placeholder user ID for API key users.

Return type:

str | None

get_user_roles()[source]

Return the roles associated with the authenticated user.

Returns:

An empty list, as roles are handled by the API.

Return type:

list[str]

imednet.auth.credentials module

Explicit, in-memory credential capabilities; no persistent storage or renewal.

class imednet.auth.credentials.CredentialSource[source]

Bases: Protocol

Read a caller-owned credential snapshot; None permits environment fallback.

get_credentials()[source]

Return current credentials without logging or persisting their contents.

Return type:

Credentials | None

class imednet.auth.credentials.Credentials[source]

Bases: object

A credential snapshot whose representation never includes secret values.

api_key: str | None = ...
security_key: str | None = ...
oidc_token: str | None = ...
class imednet.auth.credentials.MemoryCredentialStore[source]

Bases: object

Caller-owned ephemeral store, with explicit overwrite and deletion.

Reads return immutable snapshots. Clearing drops this store’s reference; Python does not guarantee zeroization of strings or revoke existing clients.

__init__(credentials=None)[source]

Initialize a store without reading the environment or touching disk.

Parameters:

credentials (Credentials | None) –

Return type:

None

clear()[source]

Delete this store’s snapshot without changing existing clients.

Return type:

None

get_credentials()[source]

Return the current immutable snapshot.

Return type:

Credentials | None

set_credentials(credentials)[source]

Replace the snapshot for future client construction.

Parameters:

credentials (Credentials) –

Return type:

None

imednet.auth.oidc module

OIDC authentication strategy.

class imednet.auth.oidc.OIDCAuth[source]

Bases: object

Authentication strategy using OIDC token.

__init__(token, *, public_key=None, jwks_url=None, jwks=None, audience=None, algorithms=None, issuer=None, leeway=0.0)[source]

Initialize the OIDC authentication strategy.

Parameters:
  • token (str) – The OIDC bearer token to use for authentication.

  • public_key (str | bytes | Any | None) – Optional cryptographic public key or secret for verification.

  • jwks_url (str | None) – Optional JWKS endpoint URL to fetch verification keys.

  • jwks (dict[str, Any] | None) – Optional in-memory JWKS dictionary.

  • audience (str | list[str] | None) – Optional expected audience or list of audiences.

  • algorithms (list[str] | None) – Optional list of allowed algorithms.

  • issuer (str | None) – Optional expected issuer.

  • leeway (float) – Clock skew leeway in seconds for time-based claims.

Return type:

None

property claims: dict[str, Any]

Return a read-only copy of currently active verified JWT claims.

get_headers()[source]

Return the Authorization header or raise an ImednetError on invalid/expired tokens.

Return type:

dict[str, str]

get_user_id()[source]

Extract the user identifier from active verified token claims.

Returns:

The user ID (sub or preferred_username) if found and valid, otherwise None.

Return type:

str | None

get_user_roles()[source]

Extract and map user roles from active verified token claims.

Returns:

A list of mapped system roles.

Return type:

list[str]

imednet.auth.oidc.build_oidc_auth(oidc_token, *, api_key=None, security_key=None)[source]

Create OIDCAuth composed with ApiKeyAuth when both API keys are configured.

Parameters:
  • oidc_token (str) –

  • api_key (str | None) –

  • security_key (str | None) –

Return type:

OIDCAuth

imednet.auth.strategy module

Authentication strategy protocol.

class imednet.auth.strategy.AuthStrategy[source]

Bases: Protocol

Protocol for authentication strategies.

Strategies must provide headers to be injected into requests.

get_headers()[source]

Return authentication headers.

Return type:

dict[str, str]

get_user_id()[source]

Return user identity, if available.

Return type:

str | None

get_user_roles()[source]

Return resolved roles for the user, if available.

Return type:

list[str]