Skip to content

Blazor Wasm AAD B2C authentication issue #28969

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

Closed
ismailhozza opened this issue Jan 1, 2021 · 9 comments
Closed

Blazor Wasm AAD B2C authentication issue #28969

ismailhozza opened this issue Jan 1, 2021 · 9 comments
Labels
area-blazor Includes: Blazor, Razor Components investigate

Comments

@ismailhozza
Copy link

Describe the bug

Hi, I am struggling with the below error. Can't figure out the root cause. I have a Blazor Wasm application with AAD B2C authentication. Login works fine, but after some time I get the below error. Any ideas what could be the problem?

image

Based on the console logs, it seems that ID token is undefined.

ClientAuthError: null_or_empty_id_token: The idToken is null or empty. Please review the trace to determine the root cause. Raw ID Token Value: undefined

Further technical details

  • Dotnet version: 5.0.100
  • Project dependencies

`

<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.1" PrivateAssets="all" />

<PackageReference Include="Microsoft.Authentication.WebAssembly.Msal" Version="5.0.1" />

<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="5.0.0" />

<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />

`

@Pilchie Pilchie added the area-blazor Includes: Blazor, Razor Components label Jan 1, 2021
@mkArtakMSFT
Copy link
Contributor

Thanks for contacting us.
Are you able to reliably reproduce this issue? If so, please share a small repro project so that we can investigate this.

@mkArtakMSFT mkArtakMSFT added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Jan 4, 2021
@andersson09
Copy link

andersson09 commented Jan 6, 2021

I get this error too, if I'm logged in and leave it for a while (around 30mins or so), then later refresh tab. In order to get the spa working again I need to close the session and open a new tab

@juho-hanhimaki
Copy link
Contributor

I ran into this too after the initial token has expired (60 minutes?).

Just followed the steps in the documentation:
https://docs.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/hosted-with-azure-active-directory-b2c?view=aspnetcore-5.0

@juho-hanhimaki
Copy link
Contributor

I did change the CacheLocation to localStorage (otherwise default template):

builder.Services.AddMsalAuthentication(options =>
{
options.ProviderOptions.Cache.CacheLocation = "localStorage";

Don't yet know if the change has something to do with the issue.

@ghost
Copy link

ghost commented Jan 11, 2021

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

See our Issue Management Policies for more information.

@andersson09
Copy link

Hi, I don't think this should be marked as stale, there is clearly an issue as multiple people are receiving the same exception.

@juho-hanhimaki
Copy link
Contributor

juho-hanhimaki commented Jan 12, 2021

I did manually build a updated version of AuthenticationService.js which included patch #28498 AND updated the msal-browser library to 2.8.0 (#29010) (required some changes in the typescript source, but somehow got it working 😅).

Now the issue is gone for me. Don't know which one of those two things fixed the issue, but the main thing for me is that the issue seems to be gone with those steps.

@morganc9
Copy link

morganc9 commented Jan 12, 2021

Hello,
I have exactly the same error on my blazor project using B2C... +1
It happen when I let my tab open too long. I guess it's an issue with the token renewal mechanism...

blazor.webassembly.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: null_or_empty_id_token: The idToken is null or empty. Please review the trace to determine the root cause. Raw ID Token Value: undefined
ClientAuthError: null_or_empty_id_token: The idToken is null or empty. Please review the trace to determine the root cause. Raw ID Token Value: undefined

mkArtakMSFT pushed a commit that referenced this issue Jan 13, 2021
#### Description

This PR updates the version of the MSAL.js dependency that we redistribute in our Authentication.Msal library in response to user requests and recommendation from the MSAL team.

#### Technical Description

This PR contains some code changes in response to some changes in type definition over in MSAL.js:

- AzureAD/microsoft-authentication-library-for-js#2105
- AzureAD/microsoft-authentication-library-for-js#2512

#### Customer Impact

Without these changes, if users want to pick up required bug fixes in the downstream MSAL.js library, they would have to compile their own version of JavaScript dependencies and integrate them into their project.

This PR allows users to consume bug fixes blocking customer login and platform support without having to put in difficult workarounds.

#### Regression?
- [ ] Yes
- [X] No

#### Risk
- [ ] High
- [ ] Medium
- [X] Low

Change contains no breaking changes and was made on recommendation of the MSAL team. Manual verification completed.

#### Verification
- [X] Manual (required)
- [ ] Automated

Verified navigating to the authorized-only fetch data page, logging in, confirming redirect, logging out, logging in again on:
- Azure B2C + Blazor WASM Hosted
- Azure B2C + Blazor Standalone
- Azure AAD + Blazor WASM Hosted
- Azure AAD + Blazor WASM Standalone

#### Packaging changes reviewed?
- [ ] Yes
- [ ] No
- [X] N/A

Addresses #29010, #28969, #28956
@ismailhozza
Copy link
Author

Hi, I think this issue is resolved for me also. I did several changes, so I am not sure which one possibly fixed the issue. I updated the dependencies like @juho-hanhimaki and added couple of scopes (openid and offline_access) to the authentication config. So, I guess it can be closed for now.

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Jan 13, 2021
@javiercn javiercn removed the Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. label Jan 14, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Feb 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components investigate
Projects
None yet
Development

No branches or pull requests

7 participants