-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MSAL on Blazor WebAssembly refresh token expiration invalid_grant regression #48264
Comments
To learn more about what this message means, what to expect next, and how this issue will be handled you can read our Triage Process document. |
We started to get the same issue recently after updating some libraries (.NET from 7.0.5 to 7.0.8) and Microsoft.Identity.Web from 2.11.1 to 2.12.4 (but it's rather related to .NET upgrade only). In 7.0.5 version new tokens were requested automatically (MS sign in page was visible for a moment) in 7.0.8 it ends up with error from the description. |
We're having the same problem in Microsoft.Authentication.WebAssembly.Msal 7.0.0. We see the mentioned The try catch in the |
Same problem in Microsoft.Authentication.WebAssembly.Msal 7.0.10 |
To learn more about what this message means, what to expect next, and how this issue will be handled you can read our Triage Process document. |
Dont understand that this is being moved to .NET 9. This is a crucial feature for Blazor with MS authentication. I can't upgrade any of my projects because of this. Just restore it to how it was implemented in .NET 6 @javiercn |
Is there any workaround for this, how can we catch the exception and redirect to azure login? |
Hi. We have a couple of web applications that used to work seamlessly authentication side, using the standard MSAL mechanism. Originally, both apps were developed using .NET 6. Recently we upgraded to .NET 8 and consequently we upgraded all the libraries, and there started the issue described here. { Any suggestion to get it fixed? |
We'll consider patching this for both 7.0.x and 8.0.x. |
Is there any temporary workaround we can apply? Like, catch the exception and manually trigger a sign-in request? We aggressively expire refresh tokens, so this breaks our apps. |
I need this too. Cannot ship any application with this error or at least a sufficient work around. |
Had this while upgrading projects to .NET 8 from 6 (with the MS packages tracking the framework version). Workaround for me was to revert the packages |
So, is anything actually happening on this? This is a major issue for us as well. Shipping is a no-go with this bug, and rolling packages back two major versions hurts. |
A failed POST to the /token endpoint producing a 400 status with a AADSTS700084 error in the response is expected in some circumstances. You should not be alarmed to see this in your network logs.
AzureAD/microsoft-authentication-library-for-js#6765 (comment) Another reason the token refresh might fail is that the server has configured strict Content Security Policies (CSP) blocking the silent iframe-based login.
It may have worked this way previously, but this is not the documented behavior. In circumstances where silent token acquisition fails, you are expected to handle the interactive login redirect yourself rather than expect Blazor to automatically redirect for you and possibly unload your application at an unexpected time. If you are using IAccessTokenProvider.RequestAccessToken() directly, this means you should check if If you're getting an AccessTokenNotAvailableException from something like the AuthorizationMessageHandler, you're expected to call Can anyone provide a sample where the where the |
I have created a sample repo https://github.com/dino182/blazor-msal-expired-refresh-token to try to recreate the original behaviour I experienced when I opened this issue. At the time, when the error was encountered, I'm sure the application displayed the unhandled exception Blazor error UI panel, logged the error in the console and stopped processing. If I recall correctly, refreshing the browser resulted in the same behaviour, so the application was effectively unusable from a user's perspective. However, I cannot reproduce this behaviour now. This repo demonstrates the desired behaviour (in .NET6, .NET7 and .NET8), where the error is logged in the console and something (I don't know what) is causing the sign in request to be automatically retried. Perhaps other framework changes have been introduced since this issue was opened that have fixed the poor behaviour. Whatever has happened, my use-case seems to be working fine and I can't break it now. I have moved away from MSAL.js and am using same site cookie authentication instead. So, personally, I am happy for this to be closed. If anyone else still has a problem with this and can respond to @halter73's request please feel free to chip in:
If not, I'll just leave this issue to be closed automatically. |
I have the same problem. I have this Ihttpclientfactory DelegatingHandler:
If the user logs in and gets a token... EVERYTHING OK! accessTokenResult has a valid token. But, if I have the user was already logged in for 24h, with a ClaimsPrincipal but expired, then it does not refresh the token.. showing 401 error in the call to an API with JWT accessTokenResult is null |
I do not understand your answer @jornjanssen90 . The real problem in this ticket is that MSAL, once the user is already logged in +24 hours, having a valid authorization and an expired token, cannot request a new token with the access token he had.. giving error 400 in POST on the refresh token request |
As I mentioned in #48264 (comment), this is the expected behavior.
It's been a month since I've asked this, and I haven't seen a sample where this isn't the case. @chulla Has mentioned that there's an issue with their custom The built-in AuthorizationMessageHandler throws an exception before attempting any request if it fails to obtain an access token. This exception should be handled by the calling component as you can see demonstrated in my repro project. Nonetheless, I updated my repro project to implement a custom You can take look at the updated repro project here: https://github.com/halter73/BlazorHostedWasmAAD/compare/custom-delegating-handler If someone can provide a full repro project on GitHub where the |
EDIT: It looks like the As a sidenote for anyone coming across this in the future who, like me, doesn't want to have to do a try/catch/redirect on every single API request like in the provided sample, I believe something like this should work inside your handler which inherits
|
They blinded us with science. Result: no resolution. Just some workarounds every developer has to implement himself. Users will be bothered will a full refresh potentially loosing data and for sure context. Feels like the old days with sessions. If that is the best, the best won't do. |
Hi I agree 100% with @hjrb Hi @halter73 Its very un-fortunate that you people are not having a solution even after an year. Please show this issue to someone who developed this AuthenticationService.ts, they can fix this quickly. I understand that browser blocks the 3rd party cookie and the silent token renew fails. so what is the ideal solutions? @halter73 Instead of closing the issue blindly please review this issue correctly and give us a proper fix and we are waiting for more than an year and please be responsible to the community. Please re-open this issue |
I am also getting the same error. I am using v8.0.8 with blazor wsam. AADSTS700084: The refresh token was issued to a single page app (SPA), and therefore has a fixed, limited lifetime of 1.00:00:00, which cannot be extended. It is now expired and a new sign in request must be sent by the SPA to the sign in page. The token was issued on 2024-09-12T12:42:36.3844597Z. Trace ID: 034cf4b8-f420-4aec-a924-4fd7a2d64301 Correlation ID: dbdac564-39c4-45d8-9ab6-a6c66b83f520 Timestamp: 2024-09-16 07:09:19Z |
@suntaurus you have to do the redirect yourself now. i have made a 'FetchService' class where i use the httpclient with my own exceptionhandling. Here is an example of my Get function:
|
I have added to the AuthorizationHandler as mentioned by @ShawnTheBeachy. I need to check whether this fixes it. public class AuthorizationHandler : AuthorizationMessageHandler |
Is there an existing issue for this?
Describe the bug
The fix for #28151 in #28498 appears to have been regressed by the c1d16e3#diff-e93d88646a9c7b8accad9fd0d381af964d3f5e6bba9d4e72c22f602565a3c4cc commit. This impacts the 7.x versions of the Microsoft.Authentication.WebAssembly.Msal. The 6.x versions still contain the previous fix.
The bug is exactly as described in #28151. The only difference is that the error message returned from the failed POST request to the token endpoint is:
Expected Behavior
The AuthenticationService should handle this exception and automatically trigger a new sign in request. It should not result in an unhandled error bubbling up to the Blazor app.
Steps To Reproduce
Exceptions (if any)
No response
.NET Version
7.0.203
Anything else?
The text was updated successfully, but these errors were encountered: