- Python 3.x
requests
library
import os
import requests
import json
def get_new_token(client_id, client_secret, tenant):
auth_server_url = f"https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token"
token_req_payload = {
'grant_type': 'client_credentials',
'scope': 'https://management.azure.com/.default'
}
token_response = requests.post(
auth_server_url,
data = token_req_payload,
auth = (client_id, client_secret),
verify = True,
allow_redirects = False
)
tokens = json.loads(token_response.text)
return tokens['access_token']