Skip to content

[Bug] Additional claims are not being requested #1296

Closed

Description

Which version of Microsoft Identity Web are you using?
Issue first identified in 1.12 but still present in 1.14.

Where is the issue?

  • Web app
    • Sign-in users
    • Sign-in users and call web APIs
  • Web API
    • Protected web APIs (validating tokens)
    • Protected web APIs (validating scopes)
    • Protected web APIs call downstream web APIs
  • Token cache serialization
    • In-memory caches
    • Session caches
    • Distributed caches
  • Other (please describe)

Is this a new or an existing app?
The app is in production and I have upgraded to a new version of Microsoft Identity Web.

Repro
Configure the scopes (either in code or in a config file) to add an additional scope (e.g. email) beyond the default openid and profile scopes.

The expected email claim will not be returned and when looking at the request using a web proxy (e.g. Fiddler) the scope will not be part of the request.

I have tried this with both the AddMicrosoftIdentityWebAppAuthentication and AddMicrosoftIdentityWebApp methods.

Example config:

"AzureAd": {
    "Instance": "https://login.microsoftonline.com/",
    "Domain": "[domain].onmicrosoft.com",
    "TenantId": "organizations",
    "ClientId": "xxx",
    "ClientSecret": "xxx",
    "CallbackPath": "/signin-oidc",
    "SignedOutCallbackPath ": "/signout-callback-oidc",
    "Scope": [
      "openid",
      "profile",
      "email"
    ]
  },
authServices.AddMicrosoftIdentityWebApp(options =>
            {
                _configuration.Bind("AzureAd", options);
            }, openIdConnectScheme: ExternalProviders.AzureActiveDirectory, cookieScheme: ExternalProviders.GetCookieScheme(ExternalProviders.AzureActiveDirectory));

Expected behavior
The additional email scope should be part of the authorise request as a query string parameter in the request to login.microsoftonline.com.

Actual behavior
Only the openid and profile scopes are provided, which was verified by using Fiddler. Therefore, the email claim is not provided in a response.

E.g. The request is: https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize?client_id=xx&redirect_uri=xxx&response_type=id_token&scope=openid%20profile&response_mode=form_post&nonce=xx&client_info=1 etc...

Possible solution
I have ran a debugger and I believe that the issue is to due to the logic inside MicrosoftIdentityWebAppAuthenticationBuilderExtensions.AddMicrosoftIdentityWebAppInternal on approximately line 286.

MergedOptions mergedOptions = mergedOptionsMonitor.Get(openIdConnectScheme);
MergedOptions.UpdateMergedOptionsFromMicrosoftIdentityOptions(msIdOptions.Value, mergedOptions);

MergedOptions.UpdateMergedOptionsFromMicrosoftIdentityOptions(msIdOptionsMonitor.Get(openIdConnectScheme), mergedOptions);

In the last line msIdOptionsMonitor.Get(openIdConnectScheme) will correctly retrieve the options with the 3 scopes, however, the call to UpdateMergedOptionsFromMicrosoftIdentityOptions does not merge the scopes collection.

Additional context / logs / screenshots
This only started to be a problem for us in the last 48 hours. We have some users who have an email address different from their username. But the way one of our vendors maps to our users is via the email address. I'm not sure if this is due to a recent change in AAD, but we're no longer receiving the email address and therefore the vendor is unable to correlate our AAD user with a user on their platform.

Activity

  1. jmprieur commented on Jul 3, 2021

    @jmprieur
    Collaborator

    Thanks for reporting and investigating, Stephen Kennedy (@DevEnable).
    Until we fix this, a possible workaround would be to try to set the OpenIdConnect options afterwards?

    services.Configure<OpenIdConnectOptions>(ExternalProviders.AzureActiveDirectory, options =>
    {
        options.Scope = new []
       {
          "openid",
          "profile",
          "email"
       };
    });
  2. DevEnable commented on Jul 4, 2021

    @DevEnable
    Author

    Jean-Marc Prieur (@jmprieur) Unfortunately options.Scope has no setter so I can't use your proposed workaround. I did take a clone of this repository and modify it a bit (to get it running, e.g. removing the requirement for strongly signing) and modified MergedOptions.cs at line 199 to add the following code:

    foreach (var scope in microsoftIdentityOptions.Scope)
                {
                    if (!string.IsNullOrWhiteSpace(scope) && !mergedOptions.Scope.Any(s => string.Equals(s, scope, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        mergedOptions.Scope.Add(scope);
                    }
                }

    This fixed the issue for me. The scope was part of the request to Microsoft AAD and the email claim was returned.

    I'd make a PR for this but selfishly I just don't have the time especially as I don't run Windows meaning I can't test the .NET Framework impact or use the instructions related to Visual Studio.

  3. jmprieur commented on Jul 4, 2021

    @jmprieur
    Collaborator

    Thanks Stephen Kennedy (@DevEnable) for sharing your solution.
    Indeed, this seems like a good fix.
    cc: jennyf19

  4. added a commit that references this issue on Jul 5, 2021
  5. added a commit that references this issue on Jul 12, 2021
  6. jennyf19 commented on Jul 15, 2021

    @jennyf19
    Collaborator

    Included in 1.14.1 release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingregressionregression between Microsoft Identity Web versions

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions