Skip to content
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

"utid" (home tenant id) missing in claims after update from 2.14.0 to 2.15.1 #2508

Closed
rufer7 opened this issue Oct 6, 2023 · 2 comments
Closed
Labels
question Further information is requested

Comments

@rufer7
Copy link

rufer7 commented Oct 6, 2023

Microsoft.Identity.Web Library

Microsoft.Identity.Web

Microsoft.Identity.Web version

2.15.1

Web app

Sign-in users

Web API

Protected web APIs call downstream web APIs

Token cache serialization

Distributed caches

Description

I have a .NET Core 7 Web API that registers a delegate to the OnTokenValidated event and then uses the claim utid in the event handler. However after updating from 2.14.0 to 2.15.1 I don't get the utid claim (home tenant id) not anymore.

Reproduction steps

  1. Logout
  2. Login

Error message

None

Id Web logs

No response

Relevant code snippets

ServiceCollectionExtensions.cs

        services.AddMicrosoftIdentityWebAppAuthentication(configuration)
            .EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
            .AddMicrosoftGraph(defaultScopes: initialScopes)
            .AddDistributedTokenCaches();

        services.AddScoped<CustomClaimsTransformator>();

        services.Configure<MicrosoftIdentityOptions>(OpenIdConnectDefaults.AuthenticationScheme, options =>
        {
            options.Events.OnTokenValidated = async context =>
            {
                var applicationServices = context.HttpContext.RequestServices;
                if (context.Principal != null)
                {
                    using var scope = applicationServices.CreateScope();
                    context.Principal = await scope.ServiceProvider
                        .GetRequiredService<CustomClaimsTransformator>()
                        .TransformAsync(context.Principal);
                }
            };
        });

CustomClaimsTransformator.cs

public class CustomClaimsTransformator
{
    public async Task<ClaimsPrincipal> TransformAsync(ClaimsPrincipal principal)
    {
        var homeTenantId = principal.GetHomeTenantId(); // THIS RETURNS NULL AFTER UPDATE TO 2.15.1

Regression

No response

Expected behavior

As the version change from 2.14.0 to 2.15.1 is a minor version bump I would expect the utid claim as in v 2.14.0.

@rufer7
Copy link
Author

rufer7 commented Oct 24, 2023

Just verified with version 2.15.2 - is now working again. Therefore I close the issue

@rufer7 rufer7 closed this as completed Oct 24, 2023
@jmprieur
Copy link
Collaborator

Thanks for confirming @rufer7

@jmprieur jmprieur reopened this Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants