You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running a Web APP which uses an API, the ITokenAcquisition.GetAccessTokenForUserAsync method throws an exception when running the second time after stopping the application. This is probably because the cookies are valid, but the in-memeory cache is empty because the application was restarted.
The GetAccessTokenForUserAsync should not throw an exception if it has no token, but get a new one. At present, this is not a good development experience. If I delete my cookies, then the app logs in again and then gets a new token.
Which version of Microsoft Identity Web are you using?
0.4.0-preview
Where is the issue?
Web app
Sign-in users
[] Sign-in users and call web APIs
Web API
Protected web APIs (validating tokens)
Protected web APIs (validating scopes)
Protected web APIs call downstream web APIs
Token cache serialization
In-memory caches
Session caches
Distributed caches
Other (please describe)
Is this a new or an existing app?
c. This is a new app or an experiment.
Expected behavior
No Exception when it runs a second time
publicvoidConfigureServices(IServiceCollectionservices){//...
services.AddMicrosoftIdentityWebApiAuthentication(Configuration);
services.AddControllers(options =>{varpolicy=new AuthorizationPolicyBuilder().RequireAuthenticatedUser()// .RequireClaim("email") // disabled this to test with users that have no email (no license added).Build(); options.Filters.Add(new AuthorizeFilter(policy));});}
An unhandled exception occurred while processing the request.
ApplicationException: Exception Microsoft.Identity.Web.MicrosoftIdentityWebChallengeUserException: IDW10502: An MsalUiRequiredException was thrown due to a challenge for the user. See https://aka.ms/ms-id-web/ca_incremental-consent.
---> MSAL.NetCore.4.18.0.0.MsalUiRequiredException:
ErrorCode: user_null
Microsoft.Identity.Client.MsalUiRequiredException: No account or login hint was passed to the AcquireTokenSilent call.
at Microsoft.Identity.Client.AcquireTokenSilentParameterBuilder.Validate()
at Microsoft.Identity.Client.AbstractAc
Greetings Damien
The text was updated successfully, but these errors were encountered:
@damienbod : Thanks for the feedback. You are right that there is a session cookie, but no access token in the cache, because you are using the In memory token cache (the default from the templates) and this cache is emptied when stopping the app.
If you were using another form of token cache serialization the user could be re-logged-in.
Happy to have a discussion with you, @jennyf19 and @onovotny
Maybe we should have a boolean option in MicrosoftIdentityOptions to control the behavior?
@jmprieur Thanks for the feedback. This means in-memory cache cannot be used for production in this setup. I usually check if I have a token, or it is expired and get another then if required. I would welcome the bool very much. I will close this then and move to the other issue.
When running a Web APP which uses an API, the
ITokenAcquisition.GetAccessTokenForUserAsync
method throws an exception when running the second time after stopping the application. This is probably because the cookies are valid, but the in-memeory cache is empty because the application was restarted.The GetAccessTokenForUserAsync should not throw an exception if it has no token, but get a new one. At present, this is not a good development experience. If I delete my cookies, then the app logs in again and then gets a new token.
Which version of Microsoft Identity Web are you using?
0.4.0-preview
Where is the issue?
Is this a new or an existing app?
c. This is a new app or an experiment.
Expected behavior
No Exception when it runs a second time
Repro
Code: https://github.com/damienbod/AzureAD-Auth-MyUI-with-MyAPI
Actual behavior
Greetings Damien
The text was updated successfully, but these errors were encountered: