All Products
Search
Document Center

Identity as a Service:Code integration

Last Updated:Mar 28, 2026

Prerequisites

Ensure that you have completed the environment preparation. For configuration details, see Environment preparation.

SDK initialization

This method initializes the IDaaS configuration by reading the configuration file you specified during environment preparation.

Important

During SDK initialization, the SDK automatically checks the configuration file and attempts to obtain a token for the scope defined in the file. If token acquisition fails, the system immediately raises an error and stops the initialization process. This design identifies potential issues early, preventing access failures after your service starts.

IDaaSCredentialProviderFactory.init()

Obtain an access token

  1. Obtain an IDaaS credential provider.

    1. Obtain an IDaaS credential provider for the scope specified in the configuration file.

    credential_provider = IDaaSCredentialProviderFactory.get_idaas_credential_provider()
    1. Obtain the IDaaS credentialProvider to retrieve an access token for a scope that you specify in the format of audience identifier|permission identifier, which corresponds to the audience identifier and permission identifier of the M2M server application that you want to access.

    credential_provider_by_scope = IDaaSCredentialProviderFactory.get_idaas_credential_provider_by_scope(scope)
  2. The access token is a bearer token. Obtain it by calling the get_bearer_token() method on the credential provider.

    access_token = credential_provider.get_bearer_token()

Code example

from cloud_idaas.core import IDaaSCredentialProviderFactory

if __name__ == "__main__":
    IDaaSCredentialProviderFactory.init()

    credential_provider = IDaaSCredentialProviderFactory.get_idaas_credential_provider()
    access_token = credential_provider.get_bearer_token()

    # scope = "urn:cloud:idaas:pam|credential:obtain"
    # credential_provider_by_scope = IDaaSCredentialProviderFactory.get_idaas_credential_provider_by_scope(scope)
    # access_token = credential_provider_by_scope.get_bearer_token()

    print("Access Token: \n" + access_token)