I'm using below code snippet to get a access token. Everything works as excepted except the code itself pops up new tag in browser and then returns access token. How can avoid from the pop-up window? `
from msal import PublicClientApplication
clientID = <clientID>
scopes= ["https://graph.microsoft.com/.default"]
resource_uri = 'https://graph.microsoft.com/'
tenantID = <tenantID>
authority = "https://login.microsoftonline.com/" + tenantID
publicClientApp = PublicClientApplication(clientID, authority=authority)
accounts = publicClientApp.get_accounts()
result = publicClientApp.acquire_token_silent(scopes=["https://graph.microsoft.com/.default"])
access_token = result["access_token"]
print(access_token)
return access_token`
To avoid pop-up window or user interaction while getting token, you need to change your authentication flow to either username password(delegated) or client credentials flow (app-only).
If you want to generate access token with Delegated permissions, run below modified code by including username and password parameters:
Response:
In app-only scenario where Application permissions are granted, you can run below modified code that generates token using client credentials flow without user interaction or pop-up window:
Response:
Reference: Authentication flow support in the Microsoft Authentication Library (MSAL) - Microsoft Entra