AADTokenGenerator

class pfore_cloud_utilities.AADTokenGenerator(azure_tenant_id=None, spn_client_id=None, spn_client_secret=None)[source]

Singleton class to handle AAD token generation of AAD resources.

Connection is created using either a Managed Identity or an SPN.

If azure_tenant_id, spn_client_id and spn_client_secret are all set to None, the client will assume Managed Identity as an authentication method.

Parameters:
  • azure_tenant_id (Optional[str]) – Azure tenant ID

  • spn_client_id (Optional[str]) – Service Principal client ID

  • spn_client_secret (Optional[str]) – Service Principal client secret

Raises:

ValueError – If one of the arguments for SPN-based auth is missing

get_token()

AADTokenGenerator.get_token(aad_resource_name)[source]

Generates AAD token.

Helper method that uses _credentials variables to make calls to the AAD API to generate token using Managed Identities or SPNs based connection.

Parameters:

aad_resource_name (str) – AAD resource name

Return type:

str

Returns:

AAD token, valid for 60 minutes.

Raises:

NotImplementedError – If the specified aad_resource_name does not exist in AAD_RESOURCE_NAME_TO_ID, defined in define.py