-
Notifications
You must be signed in to change notification settings - Fork 1k
MsalUIRequiredException: No Account or login hint was passed to the AcquireTokenSilent call #540
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
Comments
@Pruzzo do you get this exception on the debugger and the app re-signs-in the user? or does it just crash? |
I get the error in the debugger, if i logout and login again it works fine but the exception is just thrown, nothing else |
But when you continue the execution on the debugger, you are automatically re-signed-in? aren't you? |
No i am not re-signed in automatically :) |
you mean the application crashes? you don't see the sign-in dialog? |
No, when this error comes i do not see the signin dialog |
I mean when you continue. I'm trying to understand if the app crashes? |
I'm assuming you have |
Yes, that is what i have. ` MsalUiRequiredException msalUiRequiredException = context.Exception as MsalUiRequiredException;
this works and msalUiRequiredException is not null but i did not manage to make the filter work properly (an exception is thrown on `public class MsalUIExceptionFilter : ExceptionFilterAttribute /// Scopes to request /// public string[] Scopes { get; set; }
|
Hello @Pruzzo |
Hi @aremo-ms, it was necessary to me to carry out with the job and so i found a walkaround, setting a control that simpy tries to use the token and if it gives an exception the user is logged out forcing the login again. |
@Pruzzo |
I was not reffering at the sample, my case is that i was just expection the token to auto refresh using the AcquireTokenSilent but it seems to not be working. |
Closing this issue after 14 days without response |
Hi, ive been having the same issue. I am currently building a .net core mvc application and I keep getting the "no account or login hint was passed to the acquiretokensilent call" error. I have tried it with the same code as provide here as well as using the GraphServiceClient provided by the controller. It works on initial loading of the page, but once the page is reloaded the error reappears. It looks asif the cache gets cleared, but i have no way of confirming this first code section : GraphServiceClient graphServiceClient = new GraphServiceClient("https://graph.microsoft.com/v1.0", User user = await graphServiceClient.Me.Request().GetAsync(); second code section: and the error -> MsalUiRequiredException : No account or login hint was passed to the AcquireTokenSilent call. |
If it could help you i found this walkaround. This logs out the user forcing to login again |
I have the same issue... I set up graph client in the startup class like below. I thought adding
I have the below code in a Graph API service method like so...
Is there a way to use the example you have said, in my graph API service, to make sure a new access token is passed in each time I call the graph api on behalf of a user? |
|
Thanks, I'll take a look at the example. My workaround has been to add the Its weird as in a development environment the I'll have a read of the example to see if I can maybe refactor my code to call the |
This is not a workaround, @crobbo. There can be exceptions anyway in some scenarios, so it's better for the attribute (which is an ExceptionFilter) to process them. This is the way to do. See https://github.com/AzureAD/microsoft-identity-web/wiki/Managing-incremental-consent-and-conditional-access |
Does [AuthorizeForScopes(Scopes = new[] { "{scopes}" })] not process and handle As mentioned, since I added AthourizeForScopes to my controller it works when deployed, the app does not crash due to the exception, I get a new user token and the user is able to access SharePoint via the app as intended. The exception only forces the code to stop in development locally and once I continue through the exception the app works as intended... I followed your guide adding the extra code to the startup class and Micrsoft.Web.Indentity.UI. I also manually called Ihink I'll try the clearing cookie method next... |
@crobbo : yes it does. That's what exception filters do. |
So, is there any solution to this problem? or any workaround at least?? I too am stuck here... |
I am also stuck, I've spent so many hours trying to find a workaround. The workaround listed here doesn't work for me. |
So you take several months to respond to the issue, then close the issue just 2 weeks of not getting a response when there is clearly an issue I'm going through this now and still not seeing a straightforward solution |
Have you all tried adding the AuthorizeForScopes to the controller? It worked for me but as I wrote above it raises an exception, not ideal, but the app will still work in production. In local development environment just get Visual studio to ignore to the exception too. |
I am yes, I'm using.... [Authorize(AuthenticationSchemes = OpenIdConnectDefaults.AuthenticationScheme)] The issue is that it works fine if the user doesn't have a token, it forces the login. However if the user has a token but it's expired it does not force the login and the code in the method continues. When I then try to get graph user information, I get the error posted in this issue. So I'm in a state where it won't force the user to re-login and I can't get the user information. |
In addition to this, this solution only works when you hit the controller, I want to refresh the token in Blazor UI before calling web API |
@StevTechy: doesn't this work in your blazor page? |
I suggest you re-open this @aremo-ms. We see this issue occurring in our Blazor Server app regularly. The issue goes away if we clear the browser cookies, but persists until we do. This is not a viable solution for large-scale applications with thousands of users. I have set up everything as per the documentation as far as I can tell. AAD redirect works fine for the most part, but at some point - I think when a cached token expires and / or does not match the cookie, the call to
We are using SQL Server caching, and need to handle everything on the blazor-server side; we cannot apply attributes to the downstream API, because the same software is used with different authorisation mechanisms depending on the deployment. The auth-related setup is as follows:
I have updated to the latest assemblies, but still get the same issue. The only way I can see to fix it at present is to somehow know that I have enabled verbose logging for MSAL, which produces the following output when attempting to connect to the app (sanitised):
The last error is because the This is difficult to replicate, I am only able to provide this right now because my workstation is in the correct state. |
Further information: as soon as a clear the |
This is happening for me each time I relaunch visual studio. The cookie is bound to the session. So to counter-act this problem I create a GUID with each session and name the cookie after the GUID. That way the cookie is bound to the session also.
|
Same error on my project, which is using .Net 6 Blazor Server.
It would worked when user login for the first time, then it will fail with error:user_null when page reloaded. I guess the login action triggered the method to add user token in request, and fail when page reload does not add the token back into request header:
So, can we have some configuration in the method |
I have the same problem using he sample code. The exception occurs only when calling the second line of the code below.
|
This needs a proper solution for Blazor rather than a workaround. Still a pain to handle. |
For Blazor (net9) adding: builder.Services.AddMicrosoftIdentityConsentHandler(); did a job. var user = await graph.Me.GetAsync(); started working on component |
Also having this error when trying to obtain an access token from AD B2C
|
Hi, where do you use the GraphServiceClient and how is it injected? |
This issue is for a: (mark with an
x
)The issue was found for the following scenario:
Please add an 'x' for the scenario(s) where you found an issue
Repro-ing the issue
Repro steps
I've configured an App registration with delegated permission to create an onlineMeeting (onlineMeetings.ReadWrite).
I've configured a .Net Core 5 app to call api in this way
`services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"))
.EnableTokenAcquisitionToCallDownstreamApi(new string[] { "user.read", "onlineMeetings.readWrite" })
.AddMicrosoftGraph(Configuration.GetSection("DownstreamApi"))
.AddDistributedTokenCaches();
Try to call the Graph api through
await graphServiceClient.Me.OnlineMeetings.Request().AddAsync(onlineMeeting).ConfigureAwait(false);
Expected behavior
i am expecting the token to refresh what it's expired
Actual behavior
but after token is expired i receive the error MsalUiRequiredException: No Account or login hint was passed to the AcquireSilent call.
First login everything works fine and the token is correctly saved on the db
Possible Solution
I followed all the threads opened and i've tried to use
[AuthorizeForScopes(Scopes = new[] { "<TheScopeThatYouArePassingOnAcquireTokenMethod>" })]
found herei've also tried to get the token manually
var pca = PublicClientApplicationBuilder.Create(clientId).WithRedirectUri("https://localhost:44341").Build();
but seems that the https doen not work infact i get the error:
var pca = PublicClientApplicationBuilder.Create("07ee5b5a-dec2-4904-ae26-b2f2901e2f06").WithRedirectUri("https://localhost:44341").Build();
Additional context/ Error codes / Screenshots
Any log messages given by the failure
Add any other context about the problem here, such as logs.
This is the log of the exception:
`2021-09-23 09:43:29.0079|1|ERROR|Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware|An unhandled exception has occurred while executing the request. Status Code: 0
Microsoft.Graph.ServiceException: Code: generalException
Message: An error occurred sending the request.
---> 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.36.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.Internal.Requests.Silent.SilentRequest.ExecuteAsync(CancellationToken cancellationToken)
at Microsoft.Identity.Client.Internal.Requests.Silent.SilentRequest.ExecuteAsync(CancellationToken cancellationToken)
at Microsoft.Identity.Client.Internal.Requests.RequestBase.RunAsync(CancellationToken cancellationToken)
at Microsoft.Identity.Client.ApiConfig.Executors.ClientApplicationBaseExecutor.ExecuteAsync(AcquireTokenCommonParameters commonParameters, AcquireTokenSilentParameters silentParameters, CancellationToken cancellationToken)
at Microsoft.Identity.Web.TokenAcquisition.GetAuthenticationResultForWebAppWithAccountFromCacheAsync(IConfidentialClientApplication application, ClaimsPrincipal claimsPrincipal, IEnumerable
1 scopes, String authority, MergedOptions mergedOptions, String userFlow, TokenAcquisitionOptions tokenAcquisitionOptions) at Microsoft.Identity.Web.TokenAcquisition.GetAuthenticationResultForUserAsync(IEnumerable
1 scopes, String authenticationScheme, String tenantId, String userFlow, ClaimsPrincipal user, TokenAcquisitionOptions tokenAcquisitionOptions)StatusCode: 0
ResponseBody:
Headers:
--- End of inner exception stack trace ---`
OS and Version?
Versions
Attempting to troubleshooting yourself:
Mention any other details that might be useful
The text was updated successfully, but these errors were encountered: