Cert Expired Error when using Graph API python example

Practical Stranger 10 Reputation points
2024-03-14T03:06:59.6133333+00:00

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))
Microsoft Security | Microsoft Graph
{count} vote

1 answer

Sort by: Most helpful
  1. AsithwMSFT 1,445 Reputation points Microsoft External Staff
    2024-03-16T03:25:31.56+00:00

    Your application's client secret has expired. You can create a new secret from the location where you created the Azure app registration. Go to the 'Certificates & Secrets' section, then create a new secret and update the application accordingly.

    User's image

    I hope this helps. If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.