I'm working through the MS python tutorial on building a python app using the Graph api. However, when trying to retrieve a client token, I get an error stating the certificate for "login.microsoftonline.com" has expired? The exact error is:
ClientSecretCredential.get_token failed: Cannot connect to host login.microsoftonline.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997)')]
import asyncio
import configparser
from azure.identity.aio import ClientSecretCredential
# get credentials from config file
config = configparser.ConfigParser()
config.read(["config.cfg"])
settings = config["azure"]
# functions to get & display token
async def get_app_only_token(credentials):
graph_scope = "https://graph.microsoft.com/.default"
access_token = await credentials.get_token(graph_scope)
return access_token.token
# main function
async def main(conf):
client_id = conf["clientId"]
tenant_id = conf["tenantId"]
client_secret = conf["clientSecret"]
client_credential = ClientSecretCredential(tenant_id, client_id, client_secret)
client_token = await get_app_only_token(client_credential)
print("App-only token:", client_token, "\n")
# run it
asyncio.run(main(settings))