Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get an ACCESS token using MSAL in python?

I cannot seem to figure out how to acquire an access token using MSAL. I’ve spend time reading the source code and Microsoft documentation to no avail. I’d like to use the PublicClientApplication to acquire the token. Even when running proof of concepts with the QuickStarts using ConfidentialClientApplication I seem to only get an ID_Token not an access token. Ultimately I’m trying to build a desktop/mobile app and want to be able to use MSAL for id token claims and access tokens for access to APIs. Also worth mentioning I want to implement this using AAD B2C Thanks!

like image 950
Gabriel Colli Avatar asked Apr 18 '26 14:04

Gabriel Colli


1 Answers

I have reproduced in my environment and got expected results as below and followed Microsoft-Document:

from msal import ConfidentialClientApplication

cid = "53f3ed37d4aeac"
csecret = "AFK8MY-weud6cqP7jsvAJIojaq-"
tid = "72f981db47"
auth = f"https://login.microsoftonline.com/{tid}"

app = ConfidentialClientApplication(
    client_id=cid,
    client_credential=csecret,
    authority=auth
)
s = "https://graph.microsoft.com/.default"
result = app.acquire_token_for_client(scopes=s)
a = result.get("access_token")
print(a)

Output:

enter image description here

Here csecret is client secret

cid is client id

tid is tenant id

like image 200
RithwikBojja Avatar answered Apr 21 '26 05:04

RithwikBojja



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!