79230525

Date: 2024-11-27 13:42:53
Score: 0.5
Natty:
Report link

how to use msal to get the access token?

Initially, I registered Microsoft Entra ID application with support account type of Single Tenant Application:

enter image description here

Use below modified Python Script:

from msal import ConfidentialClientApplication

CLIENT_ID = 'YOUR CLIENT ID'
CLIENT_SECRET = 'YOUR CLIENT SECRET'
TENANT_ID = 'YOUR TENANT ID'
AUTHORITY = f'https://login.microsoftonline.com/{TENANT_ID}'
SCOPE = ['https://graph.microsoft.com/.default']
REDIRECT_URI =  'http://localhost:5000/callback'

app_confidential_client = ConfidentialClientApplication(
    client_id=CLIENT_ID,
    client_credential=CLIENT_SECRET,
    authority=AUTHORITY
)

result = app_confidential_client.acquire_token_for_client(scopes=SCOPE)


if 'access_token' in result:
    print("Access Token:", result['access_token'])
else:
    print("Error:", result.get("error_description", result))

Response:

enter image description here

If still issue persists try to register another application and try the same.

Reference:

ConfidentialClientApplicationClass

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): how to use
  • Low reputation (0.5):
Posted by: Pratik Jadhav