core Module

Functions

decode_jwt

Decodes a JWT token to extract its payload claims.

decode_jwt(token: str) -> dict[str, Any]

Parameters

Name Description
token
Required
str

The JWT token string in the standard three-part format.

Returns

Type Description

A dictionary containing the claims extracted from the token payload.

Exceptions

Type Description
azure_postgresql_auth.TokenDecodeError

If the token format is invalid or cannot be decoded.

get_entra_conninfo

Synchronously obtains connection information from Entra authentication for Azure PostgreSQL.

This function acquires an access token from Microsoft Entra ID and extracts the username from the token claims. It tries multiple claim sources to determine the username.

get_entra_conninfo(credential: TokenCredential) -> dict[str, str]

Parameters

Name Description
credential
Required

The credential used for token acquisition.

Returns

Type Description

A dictionary with 'user' and 'password' keys for database authentication.

Exceptions

Type Description
azure_postgresql_auth.TokenDecodeError

If the JWT token cannot be decoded.

azure_postgresql_auth.UsernameExtractionError

If the username cannot be extracted.

azure_postgresql_auth.ScopePermissionError

If the management scope token cannot be acquired.

get_entra_conninfo_async

Asynchronously obtains connection information from Entra authentication for Azure PostgreSQL.

This function acquires an access token from Microsoft Entra ID and extracts the username from the token claims. It tries multiple claim sources to determine the username.

async get_entra_conninfo_async(credential: AsyncTokenCredential) -> dict[str, str]

Parameters

Name Description
credential
Required

The async credential used for token acquisition.

Returns

Type Description

A dictionary with 'user' and 'password' keys for database authentication.

Exceptions

Type Description
azure_postgresql_auth.TokenDecodeError

If the JWT token cannot be decoded.

azure_postgresql_auth.UsernameExtractionError

If the username cannot be extracted.

azure_postgresql_auth.ScopePermissionError

If the management scope token cannot be acquired.

get_entra_token

Acquires an Entra authentication token for Azure PostgreSQL synchronously.

get_entra_token(credential: TokenCredential, scope: str) -> str

Parameters

Name Description
credential
Required

Credential object used to obtain the token.

scope
Required
str

The scope for the token request.

Returns

Type Description
str

The acquired authentication token to be used as the database password.

get_entra_token_async

Asynchronously acquires an Entra authentication token for Azure PostgreSQL.

async get_entra_token_async(credential: AsyncTokenCredential, scope: str) -> str

Parameters

Name Description
credential
Required

Asynchronous credential used to obtain the token.

scope
Required
str

The scope for the token request.

Returns

Type Description
str

The acquired authentication token to be used as the database password.

parse_principal_name

Parses the principal name from an Azure resource path.

parse_principal_name(xms_mirid: str) -> str | None

Parameters

Name Description
xms_mirid
Required
str

The xms_mirid claim value containing the Azure resource path.

Returns

Type Description
str,

The extracted principal name, or None if parsing fails.