Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSAL token expires after 1 hour

I am using MSAL for Azure AD authentication in a Xamarin app. The validity of the token is 1 day (seen using the value of ExpiresOn of AuthenticationResult). My problem is that, after 1 hour, AcquireTokenSilentAsync fails and then AcquireToken needs to be called.

I am not able to understand that even though the token validity is 1 day, and the validity of refresh token is even more, why is it asking for authentication after every 1 hour ? Can this be changed using any parameter value or any other way ?

like image 862
V. G. Avatar asked Jun 13 '17 10:06

V. G.


People also ask

How long is Msal token valid?

MSAL Token Expires after a day.

How long should token expire?

Access tokens are short-lived and last 2 hours but refresh tokens do not expire. When the access token expires, instead of sending the user back through the authorisation flow you can use the refresh token to retrieve a new access token with the same permissions as the old one.

How long is azure token valid?

The default lifetime of the token is 1 hour.


1 Answers

Just to make a small clarification, MSAL doesn't actually issue tokens or decide a token expiration, but rather ingests an acquires token from the Azure AD STS.

MSAL will automatically refresh your access token after expiration when calling AcquireTokenSilentAsync. You're likely not getting automatic silent refreshes due to some kind of token cache miss. It's hard to say the specific issue without seeing your code, but i'll recommend comparing it against the official MSAL Xamarin code sample.

If you're building a Xamarin app, then it's a public client. The default token expirations right now are:

Access Tokens: 1 hour

Refresh Tokens: 90 days, 14 day inactive sliding window

Azure AD does allow you to configure these token expirations in PowerShell. You can define a token lifetime policy and then assign it to the specific Service Principal, across the tenant/organization, or on the application object. The other thing to keep in mind is if you're requesting a token for a specific resource, then the policy must be set on that resource rather than the requesting service principal or app. For more info on this, checkout configuring token lifetime in Azure AD.

like image 141
Daniel Dobalian Avatar answered Sep 28 '22 17:09

Daniel Dobalian