Microsoft-identity-web: User.Identity.Name in v.1.9.0 now shows displayname instead of account name

Created on 13 Apr 2021  路  20Comments  路  Source: AzureAD/microsoft-identity-web

Which version of Microsoft Identity Web are you using?
Microsoft.Identity.Web 1.9.0

Microsoft.Identity.Web 1.8.2: user.Identity.Name contains my account name (UPN): "[email protected]"

Microsoft.Identity.Web 1.9.0: user.Identity.Name contains my account display name.

P1 external investigate

Most helpful comment

@travisneale the repro was super helpful. thank you so much. we should have a workaround out in our next release 1.9.1 on 4.14.

All 20 comments

@Yomodo : do you have repro steps?

  • Is it in web apps or web APIs?
  • Is it with .NET Core 3.1 or .NET 5.0 or both?

This is a .NET 5 blazor server web app.

@Yomodo : could you please check what happens if you force Microsoft.IdentityModel assemblies to be version="6.8.*" ?

    <PackageReference Include="Microsoft.IdentityModel.Logging" Version="6.8.*" />
    <PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="6.8.*" />
    <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.8.*" />

These are the used package references:

    <PackageReference Include="Humanizer.Core" Version="2.8.26" />
    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.17.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="5.0.5" />
    <PackageReference Include="Microsoft.Identity.Web" Version="1.9.0" />
    <PackageReference Include="Microsoft.Identity.Web.UI" Version="1.9.0" />
    <PackageReference Include="MudBlazor" Version="5.0.7" />
    <PackageReference Include="System.Linq.Async" Version="5.0.0" />

I understand, @Yomodo
I'm asking if you could add the three package references I provided above to your csproj, in order to see if this still reproes ? I'd like to rule out a change in Microsoft.IdentityModel (as I don't see change in Microsoft.Identity.Web for this)

  1. Removed v1.9.0
  2. Added the 3 references
  3. Added v1.8.2
  4. Adding v1.9.0 now throws these nuget errors:

Microsoft.Identity.Web 1.9.0:
image

Microsoft.Identity.Web.UI 1.9.0:
image

Thank you very much @Yomodo for trying this.
@brentschmaltz @mafurman @GeoK could it be that Wilson 8.10 has changed the mapping of the Name claim?

I think I'm seeing something similar. Downgrading System.IdentityModel.Tokens.Jwt to 6.8.0 resolved my problem.

To repo:
From Blazor server template, connect to Azure AD authentication and using AuthorizeRouteView:
In Index.razor add:
`
@code {

[CascadingParameter]
private Task<AuthenticationState> authenticationStateTask { get; set; }

private string currUserID;

protected override async Task OnInitializedAsync()
{
    var user = (await authenticationStateTask).User;

    currUserID = user.FindFirst("name").Value.ToString();

}

}`

You will get a
System.NullReferenceException: 'Object reference not set to an instance of an object.'

Reverting back to Microsoft.Identity.Web 1.8.2 resolves issue.
Staying with 1.9.0 and reverting back System.IdentityModel.Tokens.Jwt to 6.8.0
and Microsoft.IdentityModel.Protocols.OpenIdConnect to 6.8.0 also removes the error and returns the proper Name.

thanks for the quick update @travisneale and investigation.
cc: @jmprieur @GeoK

@jennyf19 @travisneale while we look into this, in general the pattern:
use.FindFirst("<someclaimname>").Value.ToString();
Can always throw a null exception.

It would be helpful to have the jwt token that was used.

@travisneale @Yomodo i'm not able to repro it w/a Blazor server web app, which calls Graph. Can you provide repro code?

My issue started with the exact same code as provided by @travisneale.

@travisneale @Yomodo i'm not able to repro it w/a Blazor server web app, which calls Graph. Can you provide repro code?

https://github.com/travisneale/MID-1136

To get this app to work: You will need to add domain name, tenant ID, client ID to the appsettings.json file to point to your AzureAD, which will need the app registration with a Redirect URI pointing to https://localhost:44367/signin-oidc (or whatever local host port number you set).
It's currently set to Microsoft.Identity.Web 1.8.2 so that it will work. Update to 1.9.0 to see the error.

@travisneale the repro was super helpful. thank you so much. we should have a workaround out in our next release 1.9.1 on 4.14.

@jennyf19 Thank you for the quick patch!

@Yomodo @travisneale we just released Microsoft.Identity.Web 1.9.1 which works around this issue until IdentityModel provides a definitive fix.

Thanks a lot everyone!

@travisneale @Yomodo Are you able to try out this branch which removes the workaround we had in place? @brentschmaltz made the fix in Wilson, so I've removed the workaround in MS Id Web and we automatically pick up the latest wilson build (6.10.2 has the fix in this case).

I tested w/the sample @travisneale provided and seems to work as expected. Would one of you mind confirming? This will be in our next release (1.10).

cc: @jmprieur

Yes, all is fine now. Thanks again!

Was this page helpful?
0 / 5 - 0 ratings