1234567891011121314151617181920 |
- def get_azure_bearer_token(resource_url, azure_directory_id, azure_admin_application_id,
- azure_admin_application_secret):
- """
- Uses OAuth 2.0 to get the bearer token based on the client id and client secret.
- """
- api_url = "https://login.microsoftonline.com/" + azure_directory_id + "/oauth2/token"
- client = {'grant_type': 'client_credentials',
- 'client_id': azure_admin_application_id,
- 'client_secret': azure_admin_application_secret,
- 'resource': resource_url,
- }
- response = requests.post(api_url, data=client)
- if "access_token" in response.json():
- return response.json()["access_token"]
- print("Could not get Bearer token")
- return None
|