-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Adding flexibility for the authority and audience to support Azure AD v2.0 #7913
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
Changes from all commits
21fb647
0db0dc8
3d0ccfd
efefe03
3cc8016
bf5923c
723463e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,8 +30,10 @@ public void Configure(string name, JwtBearerOptions options) | |
| return; | ||
| } | ||
|
|
||
| options.Audience = azureADOptions.ClientId; | ||
| options.Authority = new Uri(new Uri(azureADOptions.Instance), azureADOptions.TenantId).ToString(); | ||
| options.Audience = string.Format(azureADOptions.Audience?.Replace("{ClientId}", "{0}"), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should add some parameter checks for nulls. |
||
| azureADOptions.ClientId); | ||
| options.Authority = string.Format(azureADOptions.Authority.Replace("{Instance}", "{0}").Replace("{TenantId}", "{1}"), | ||
| azureADOptions.Instance, azureADOptions.TenantId); | ||
| } | ||
|
|
||
| public void Configure(JwtBearerOptions options) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method doesn't seem to do anything.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It implements the interface https://github.com/aspnet/Extensions/blob/master/src/Options/Options/src/IConfigureOptions.cs#L11 Though I'm not sure if this is correct - should it be doing something?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine, as this class only targets named configuration instances.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A code comment might be useful, then. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.using Microsoft.AspNetCore.Authorization; | ||
|
|
||
| using Microsoft.AspNetCore.Authentication.Cookies; | ||
|
|
@@ -30,30 +30,62 @@ public class AzureADOptions | |
| public string JwtBearerSchemeName { get; internal set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the client Id. | ||
| /// Gets or sets the client Id (Application Id) of the Azure AD application | ||
| /// </summary> | ||
| public string ClientId { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the client secret. | ||
| /// Gets or sets the client secret for the application (application password) | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// The client secret is only used if the Web app or Web API | ||
| /// calls a Web API | ||
| /// </remarks> | ||
| public string ClientSecret { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the tenant Id. | ||
| /// Gets or sets the tenant id. The tenant id can have one of the following values: | ||
| /// <list type="table"> | ||
| /// <item><term>a proper tenant ID</term><description>A GUID representing the ID of the Azure Active Directory Tenant (directory ID)</description></item> | ||
| /// <item><term>a domain name</term><description>associated with the Azure Active Directory tenant</description></item> | ||
| /// <item><term>common</term><description>if the <see cref="Authority"/> is Azure AD v2.0, enables to sign-in users from any | ||
| /// Work and School account or Microsoft Personal Account. If Authority is Azure AD v1.0, enables sign-in from any Work and School accounts</description></item> | ||
| /// <item><term>organizations</term><description>if the <see cref="Authority"/> is Azure AD v2.0, enables to sign-in users from any | ||
| /// Work and School account</description></item> | ||
| /// <item><term>consumers</term><description>if the <see cref="Authority"/> is Azure AD v2.0, enables to sign-in users from any | ||
| /// Microsoft personal account</description></item> | ||
| /// </list> | ||
| /// </summary> | ||
| public string TenantId { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the Azure Active Directory instance. | ||
| /// Typical values are: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Defaults to "https://login.microsoftonline.com/" |
||
| /// <list type="table"> | ||
| /// <item><term>https://login.microsoftonline.com/</term><description>For Microsoft Azure public cloud</description></item> | ||
| /// <item><term>https://login.microsoftonline.us/</term><description>For Azure US Government</description></item> | ||
| /// <item><term>https://login.partner.microsoftonline.cn/</term><description>For Azure China 21Vianet</description></item> | ||
| /// <item><term>https://login.microsoftonline.de/</term><description>For Azure Germany</description></item> | ||
| /// </list> | ||
| /// </summary> | ||
| public string Instance { get; set; } | ||
| public string Instance { get; set; } = "https://login.microsoftonline.com/"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there ever a time when these can be empty or null? |
||
|
|
||
| /// <summary> | ||
| /// Gets or sets the domain of the Azure Active Directory tennant. | ||
| /// Gets or sets the domain associated with the Azure Active Directory tenant. | ||
| /// </summary> | ||
| public string Domain { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Azure Active Directory Authority | ||
| /// </summary> | ||
| public string Authority { get; set; } = "{Instance}{TenantId}/"; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the audience for a Web API (This audience needs | ||
| /// to match the audience of the tokens sent to access this application) | ||
| /// </summary> | ||
| public string Audience { get; set; } = "{ClientId}"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we allow the setters to accept null or empty strings? |
||
|
|
||
| /// <summary> | ||
| /// Gets or sets the sign in callback path. | ||
| /// </summary> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1,37 @@ | ||
| { | ||
| ////#if (IndividualB2CAuth) | ||
| // "AzureAdB2C": { | ||
| // "Instance": "https:////login.microsoftonline.com/tfp/", | ||
| // "ClientId": "11111111-1111-1111-11111111111111111", | ||
| // "CallbackPath": "/signin-oidc", | ||
| // "Domain": "qualified.domain.name", | ||
| // "SignUpSignInPolicyId": "MySignUpSignInPolicyId", | ||
| // "ResetPasswordPolicyId": "MyResetPasswordPolicyId", | ||
| // "EditProfilePolicyId": "MyEditProfilePolicyId" | ||
| // }, | ||
| ////#elseif (OrganizationalAuth) | ||
| // "AzureAd": { | ||
| //#if (MultiOrgAuth) | ||
| // "Instance": "https:////login.microsoftonline.com/common", | ||
| //#elseif (SingleOrgAuth) | ||
| // "Instance": "https:////login.microsoftonline.com/", | ||
| // "Domain": "qualified.domain.name", | ||
| // "TenantId": "22222222-2222-2222-2222-222222222222", | ||
| //#endif | ||
| // "ClientId": "11111111-1111-1111-11111111111111111", | ||
| // "CallbackPath": "/signin-oidc" | ||
| // }, | ||
| //#endif | ||
| ////#if (IndividualLocalAuth) | ||
| // "ConnectionStrings": { | ||
| ////#if (UseLocalDB) | ||
| // "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-Company.WebApplication1-53bc9b9d-9d6a-45d4-8429-2a2761773502;Trusted_Connection=True;MultipleActiveResultSets=true" | ||
| ////#else | ||
| // "DefaultConnection": "DataSource=app.db" | ||
| //#endif | ||
| // }, | ||
| //#endif | ||
| ////#if (IndividualB2CAuth) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this just a whitespace change? If so revert. |
||
| // "AzureAdB2C": { | ||
| // "Instance": "https:////login.microsoftonline.com/tfp/", | ||
| // "ClientId": "11111111-1111-1111-11111111111111111", | ||
| // "CallbackPath": "/signin-oidc", | ||
| // "Domain": "qualified.domain.name", | ||
| // "SignUpSignInPolicyId": "MySignUpSignInPolicyId", | ||
| // "ResetPasswordPolicyId": "MyResetPasswordPolicyId", | ||
| // "EditProfilePolicyId": "MyEditProfilePolicyId" | ||
| // }, | ||
| ////#elseif (OrganizationalAuth) | ||
| // "AzureAd": { | ||
| // "Instance": "https:////login.microsoftonline.com/", | ||
| // "Autority": "{Instance}{TenantId}/v2.0", | ||
| //#if (MultiOrgAuth) | ||
| // "TenantId": "organizations", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this now? MultiOrg is kind of it's own beast and it used to point to Asa general principle we don't introduce concepts in the template if we don't absolutely need to, so could this go back to the way it was before?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So in Azure AD v2.0, common means AAD+MSA whereas in Azure AD v1.0 it used to mean "AAD multi-org. |
||
| //#elseif (SingleOrgAuth) | ||
| // "Domain": "qualified.domain.name", | ||
| // "TenantId": "22222222-2222-2222-2222-222222222222", | ||
| //#endif | ||
| // "ClientId": "11111111-1111-1111-11111111111111111", | ||
| // "CallbackPath": "/signin-oidc" | ||
| // }, | ||
| //#endif | ||
| ////#if (IndividualLocalAuth) | ||
| // "ConnectionStrings": { | ||
| ////#if (UseLocalDB) | ||
| // "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-Company.WebApplication1-53bc9b9d-9d6a-45d4-8429-2a2761773502;Trusted_Connection=True;MultipleActiveResultSets=true" | ||
| ////#else | ||
| // "DefaultConnection": "DataSource=app.db" | ||
| //#endif | ||
| // }, | ||
| //#endif | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Warning", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,10 +11,11 @@ | |
| // }, | ||
| ////#elseif (OrganizationalAuth) | ||
| // "AzureAd": { | ||
| // "Instance": "https:////login.microsoftonline.com/", | ||
| // "Autority": "{Instance}{TenantId}/v2.0", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the same order in both templates.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation too
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Tratcher : the templates are in a different order already today (I was surprised too). I did not change the order. |
||
| //#if (MultiOrgAuth) | ||
| // "Instance": "https:////login.microsoftonline.com/common", | ||
| // "TenantId": "organizations", | ||
| //#elseif (SingleOrgAuth) | ||
| // "Instance": "https:////login.microsoftonline.com/", | ||
| // "Domain": "qualified.domain.name", | ||
| // "TenantId": "22222222-2222-2222-2222-222222222222", | ||
| //#endif | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has several problems.
azureADOptions.Audience?.Replace("{ClientId}", "{0}"There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@javiercn : how can we use string interpollation for a string which is not in the code, but in a config file? could you please show me an example on how to do it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jmprieur how is azureADOptions populated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@javiercn is there a way to enforce some type of validation, For example, azureADOptions.Audience must be populated correctly from config?