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

[BUG] OwinTokenAcquisitionHost GetAuthenticatedUserAsync does not respect the passed in argument #2585

Closed
Danthar opened this issue Nov 15, 2023 · 0 comments · Fixed by #2617
Assignees
Labels
bug Something isn't working good first issue Good for newcomers owin
Milestone

Comments

@Danthar
Copy link

Danthar commented Nov 15, 2023

Microsoft.Identity.Web Library

Microsoft.Identity.Web.OWIN

Microsoft.Identity.Web version

2.15.1

Web app

Not Applicable

Web API

Not Applicable

Token cache serialization

Not Applicable

Description

https://github.com/AzureAD/microsoft-identity-web/blob/efd1dec1f49cac8a7e7e4c821478c1af95cbc758/src/Microsoft.Identity.Web.OWIN/OwinTokenAcquisitionHost.cs#L35C1-L38C10

    public Task<ClaimsPrincipal?> GetAuthenticatedUserAsync(ClaimsPrincipal? user)
    {
        return Task.FromResult<ClaimsPrincipal?>(HttpContext.Current.User as ClaimsPrincipal);
    }

This code ignores the passed ClaimsPrincipal user. So if you where to manually resolve the ITokenAquirer as depicted in various example apps, and pass along a user when calling for example GetTokenForUserAsync it will never use the user you provided.

Reproduction steps

  • Initialise microsoft.identity.web using the OwinTokenAcquirerFactory.
  • Authenticate then call code which executes:
ITokenAcquirerFactory tokenAcquirerFactory = TokenAcquirerFactory.GetDefaultInstance<OwinTokenAcquirerFactory>();
            ITokenAcquirer acquirer = tokenAcquirerFactory.GetTokenAcquirer()!;
            AcquireTokenResult tokenResult = await acquirer.GetTokenForUserAsync(new[] { "offline_access", "user.read" }, null, myOwnClaimsPrincipalUser);

Note that the loggedin user is used in the background, and not the user you provided.

Error message

No response

Id Web logs

No response

Relevant code snippets

see description

Regression

No response

Expected behavior

I Expect the OwinTokenAcquisitionHost to respect the claimsprincipal thats passed along

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers owin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants