Back to snippets

cybrid_identity_api_client_credentials_access_token.py

python

This quickstart demonstrates how to initialize the Cybrid Identity

Agent Votes
1
0
100% positive
cybrid_identity_api_client_credentials_access_token.py
1import cybrid_api_id
2from cybrid_api_id.rest import ApiException
3from cybrid_api_id.api import tokens_api
4from cybrid_api_id.model.post_token_id_model import PostTokenIdModel
5
6# Configure OAuth2 access token for authorization
7configuration = cybrid_api_id.Configuration(
8    host = "https://id.demo.cybrid.app"
9)
10
11# Enter a context with an instance of the API client
12with cybrid_api_id.ApiClient(configuration) as api_client:
13    # Create an instance of the API class
14    api_instance = tokens_api.TokensApi(api_client)
15    
16    # Client credentials
17    post_token_id_model = PostTokenIdModel(
18        grant_type="client_credentials",
19        client_id="YOUR_CLIENT_ID",
20        client_secret="YOUR_CLIENT_SECRET",
21    )
22
23    try:
24        # Create Access Token
25        api_response = api_instance.create_token(post_token_id_model)
26        print("The response of TokensApi->create_token:\n")
27        print(api_response)
28    except ApiException as e:
29        print("Exception when calling TokensApi->create_token: %s\n" % e)