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

fix for 1738 #1743

Merged
merged 2 commits into from
Jun 3, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/Microsoft.Identity.Web/TokenAcquisition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -852,11 +852,25 @@ private IConfidentialClientApplication BuildConfidentialClientApplication(Merged
if (builder != null)
{
builder.WithSendX5C(mergedOptions.SendX5C);

ClaimsPrincipal? user = GetUserFromHttpContext();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that IdWeb should use validatedToken's TID claim, as that is guaranteed to be there in web api scenario. Is there a ClaimsPrincipal available in web api? Where does ASP.NET Core get that from - I was under the impression that in Web API scenario there is no Id Token.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is what is happening. The ClaimsPrincipal contains the result of the validated token.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have tests for GetTenantId(), for example: GetTenantId_WithTidOrTenantIdClaims_ReturnsTenantId

Testing the entire flow will be a bit more challenging and I would need a multi-tenant web API.

var userTenant = string.Empty;
if (user != null)
{
userTenant = user.GetTenantId();
builder.WithCcsRoutingHint(user.GetObjectId(), userTenant);
}
if (!string.IsNullOrEmpty(tenantId))
{
builder.WithTenantId(tenantId);
}

else
{
if (!string.IsNullOrEmpty(userTenant))
{
builder.WithTenantId(userTenant);
}
}
if (tokenAcquisitionOptions != null)
{
builder.WithExtraQueryParameters(tokenAcquisitionOptions.ExtraQueryParameters);
Expand All @@ -867,13 +881,7 @@ private IConfidentialClientApplication BuildConfidentialClientApplication(Merged
{
builder.WithProofOfPossession(tokenAcquisitionOptions.PoPConfiguration);
}
}

ClaimsPrincipal? user = GetUserFromHttpContext();
if (user != null)
{
builder.WithCcsRoutingHint(user.GetObjectId(), user.GetTenantId());
}
}

return await builder.ExecuteAsync(tokenAcquisitionOptions != null ? tokenAcquisitionOptions.CancellationToken : CancellationToken.None)
.ConfigureAwait(false);
Expand Down