Repository navigation
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
jmprieur commentedon Jul 3, 2021
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?
DevEnable commentedon Jul 4, 2021
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:
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.
jmprieur commentedon Jul 4, 2021
Thanks Stephen Kennedy (@DevEnable) for sharing your solution.
Indeed, this seems like a good fix.
cc: jennyf19
fix for #1296
fix for #1296 (#1297)
jennyf19 commentedon Jul 15, 2021
Included in 1.14.1 release