AzureAD / microsoft-identity-web

Helps creating protected web apps and web APIs with Microsoft identity platform and Azure AD B2C
MIT License
672 stars 208 forks source link

Blazor server azure b2c redirect issue #2831

Open setin1219 opened 4 months ago

setin1219 commented 4 months ago

Microsoft.Identity.Web Library

Microsoft.Identity.Web

Microsoft.Identity.Web version

2.18.1

Web app

Sign-in users and call web APIs

Web API

Protected web APIs (validating tokens)

Token cache serialization

In-memory caches

Description

Hi team,

Application: Blazor Server Render Mode: Interactive Sign-in through Azure B2C

I am trying to fetch the access token using token acquisition but it never completes.

Reproduction steps

  1. try to fetch the token using Itokenacquisition, providing the scope public async Task GetTokenAsync() { var accessToken = await _tokenAcquisition.GetAccessTokenForUserAsync(new[] { _myAppScope }); return accessToken; }

Error message

Microsoft.Identity.Web.TokenAcquisition: Information: [MsIdWeb] An error occured during token acquisition: No account or login hint was passed to the AcquireTokenSilent call.

MSAL.NetCore.4.60.3.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.RequestBase.<>c__DisplayClass11_1.d.MoveNext() --- End of stack trace from previous location --- at Microsoft.Identity.Client.Utils.StopwatchService.MeasureCodeBlockAsync(Func1 codeBlock) 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, IEnumerable1 scopes, String tenantId, 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: Exception thrown: 'Microsoft.Identity.Web.MicrosoftIdentityWebChallengeUserException' in Microsoft.Identity.Web.TokenAcquisition.dll

Id Web logs

No response

Relevant code snippets

public async Task GetTokenAsync()
{
var accessToken = await _tokenAcquisition.GetAccessTokenForUserAsync(new[] { _myAppScope });
return accessToken;
}

Regression

Id Web 2.6.0

Expected behavior

Expected to get access token

tommyw1996 commented 2 months ago

Anyone managed to get this working with the Profile editing user flow? I can retrieve the access token when the user is logged in fine. But as soon as I change details, GetAccessTokenForUserAsync crashes with "No account or login hint was passed to the AcquireTokenSilent call.".