BOOK THIS SPACE FOR AD
ARTICLE AD4- ARIA-azure-credential
# Define the authentication parameters
tenant_id = "{tenant_id}"
client_id = "{client_id}"
client_secret = "{client_secret}"
scope = "https://sub.cloudapp.domain.com/.default"
# URL to get the OAuth token
token_url = f"https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token"
# Define the request payload
payload = {
"grant_type": "client_credentials",
"client_id": client_id,
"client_secret": client_secret,
"scope": scope
}
# Make a POST request to get the token
response = requests.post(token_url, data=payload)
# Check if the request was successful
if response.status_code == 200:
# Parse the JSON response
token_response = response.json()
access_token = token_response.get("access_token")
print("Access Token:", access_token)
else:
# If the request failed, print the error
print("Failed to get the access token:", response.status_code, response.text)