AzureAD / MSAL.PS

MIT License
159 stars 29 forks source link

AADSTS50196: The server terminated an operation because it encountered a client request loop #28

Closed ToninoBruno closed 2 years ago

ToninoBruno commented 3 years ago

Hi,

I use your module to acquire an access token to consult the MS Graph API which is working great, but when I run my script I bump into the following error after the 5th entry being processed:

AADSTS50196: The server terminated an operation because it encountered a client request loop

What I am doing is essentially the following in a Function:

    $MyVarAccessToken = Get-MsalToken -ClientId $ClientID -TenantId $TenantID -UserCredential $MyVarPSCredentials
    $MyVarAuthHeader = @{
        Authorization = $MyVarAccessToken.CreateAuthorizationHeader()
        UserAgent = $UserAgent
    }

And in my script body I just call the function for each object I want to query.

Isn't it possible to use the cached token until its about to expire?

ps: thanks for your great module!

jazuntee commented 2 years ago

I think using the UserCredential parameter will re-authenticate the password everytime it is called which might be why you saw this error. Regardless, I would recommend moving to a confidential client with client secret or cert for scenarios where a user is not present for interactive auth. I would further recommend that for any API calls to MS Graph, you should consider using the Microsoft Graph PowerShell SDK modules.