Skip to content

User.Identity.Name in v.1.9.0 now shows displayname instead of account nameΒ #1136

Closed

Description

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): "account@TENANT.onmicrosoft.com"

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

Activity

  1. jmprieur commented on Apr 13, 2021

    @jmprieur
    Collaborator

    Jeffrey Jangli (@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?
  2. Yomodo commented on Apr 13, 2021

    @Yomodo
    Author

    This is a .NET 5 blazor server web app.

  3. jmprieur commented on Apr 13, 2021

    @jmprieur
    Collaborator

    Jeffrey Jangli (@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.*" />
    
  4. Yomodo commented on Apr 13, 2021

    @Yomodo
    Author

    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" />
    
  5. jmprieur commented on Apr 13, 2021

    @jmprieur
    Collaborator

    I understand, Jeffrey Jangli (@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)

  6. Yomodo commented on Apr 13, 2021

    @Yomodo
    Author
    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

  7. jmprieur commented on Apr 13, 2021

    @jmprieur
    Collaborator

    Thank you very much Jeffrey Jangli (@Yomodo) for trying this.
    BrentSchmaltz (@brentschmaltz) Maria Furman (@mafurman) George Krechar (@GeoK) could it be that Wilson 8.10 has changed the mapping of the Name claim?

  8. travisneale commented on Apr 13, 2021

    @travisneale

    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/OS (@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.

  9. jennyf19 commented on Apr 13, 2021

    @jennyf19
    Collaborator

    thanks for the quick update Travis Neale (@travisneale) and investigation.
    cc: Jean-Marc Prieur (@jmprieur) George Krechar (@GeoK)

  10. brentschmaltz commented on Apr 13, 2021

    @brentschmaltz
    Contributor

    jennyf19 Travis Neale (@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.

  11. jennyf19 commented on Apr 13, 2021

    @jennyf19
    Collaborator

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

  12. Yomodo commented on Apr 13, 2021

    @Yomodo
    Author

    My issue started with the exact same code as provided by Travis Neale (@travisneale).

  13. jmprieur commented on Apr 13, 2021

    @jmprieur
    Collaborator

    Identity.Model just added an issue for this regression: AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet#1627

  14. travisneale commented on Apr 13, 2021

    @travisneale

    Travis Neale (@travisneale) Jeffrey Jangli (@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.

  15. jennyf19 commented on Apr 14, 2021

    @jennyf19
    Collaborator

    Travis Neale (@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.

  16. added this to the 1.9.1 milestone on Apr 14, 2021
  17. travisneale commented on Apr 14, 2021

    @travisneale

    jennyf19 Thank you for the quick patch!

  18. jmprieur commented on Apr 14, 2021

    @jmprieur
    Collaborator

    Jeffrey Jangli (@Yomodo) Travis Neale (@travisneale) we just released Microsoft.Identity.Web 1.9.1 which works around this issue until IdentityModel provides a definitive fix.

  19. Yomodo commented on Apr 14, 2021

    @Yomodo
    Author

    Thanks a lot everyone!

  20. jennyf19 commented on Apr 16, 2021

    @jennyf19
    Collaborator

    Travis Neale (@travisneale) Jeffrey Jangli (@Yomodo) Are you able to try out this branch which removes the workaround we had in place? BrentSchmaltz (@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 Travis Neale (@travisneale) provided and seems to work as expected. Would one of you mind confirming? This will be in our next release (1.10).

    cc: Jean-Marc Prieur (@jmprieur)

  21. Yomodo commented on Apr 16, 2021

    @Yomodo
    Author

    Yes, all is fine now. Thanks again!

  22. added a commit that references this issue on Apr 29, 2021
  23. added a commit that references this issue on May 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions