-
Notifications
You must be signed in to change notification settings - Fork 21
Proposes more flexible AzureADOptions, and defaulting to AzureAD v2.0 #49
base: master
Are you sure you want to change the base?
Proposes more flexible AzureADOptions, and defaulting to AzureAD v2.0 #49
Conversation
- make it possible to specify the Audience of the tokens that will be accepted (with a default which is consistent with the Azure AD experience). For the moment it's hardcoded to {ClientId} - make it possible tp specity the Authority (for the moment it's hardcoded to {Instance}/{TenantId}. This is needed to make v2.0 primary without having users to have the change app generated by dotnet new mvc - Proposing to remove Domain, and rename TenantId in Tenant as the tenant identification can be specified as a TenantID (a Guid), or a domain, or some well known metatenant (common, organizations and consumers) Proposing that Web applications are now v2.0 apps by default.
@blowdart @BillHiebert This would need to be accompanied with template and tooling changes to get the right fields populated in config. |
Without tooling changes this can't be merged, the VS UI would get everything wrong. So it's not as simple as this PR :) |
I'm well aware of this, @blowdart : this is a proposal to help the discussion that @Tratcher and I have been having offline. Some of the things we'd want to consider is the breaking changes:
Then as far as template and tooling changes, could you please send me the location of the repos, so that we propose PRs? |
I have no real feelings about the changes, if they matched the Azure Portal wording for these details that would be best (assuming this won't change of course) |
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 looks fine for 3.0 with a little code cleanup.
options.Audience = azureADOptions.ClientId; | ||
options.Authority = new Uri(new Uri(azureADOptions.Instance), azureADOptions.TenantId).ToString(); | ||
string audienceFormat = azureADOptions.Authority.Replace("{ClientId}", "{0}"); | ||
options.Audience = string.Format(audienceFormat, azureADOptions.ClientId); |
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 can be a single operation everywhere you do it.
options.Audience = string.Format(audienceFormat, azureADOptions.ClientId); | |
options.Audience = azureADOptions.Authority.Replace("{ClientId}", azureADOptions.ClientId); |
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.
We don't do things like this in the framework. Audience should be initialized here, not in the property, and it's also better to just use interpolated strings directly. $"api://{azureAdOptions.ClientId}"
@@ -35,9 +35,8 @@ public async Task BearerAzureAD_Challenges_UnauthorizedRequests() | |||
.AddAzureADBearer(o => | |||
{ | |||
o.Instance = "https://login.microsoftonline.com/"; | |||
o.Domain = "test.onmicrosoft.com"; | |||
o.Tenant= "test.onmicrosoft.com"; |
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.
Spacing
@phenning for tooling. |
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.
I have some comments, but it's a good starting point for a discussion. As @blowdart said this will require coordination with templates and tooling.
options.Audience = azureADOptions.ClientId; | ||
options.Authority = new Uri(new Uri(azureADOptions.Instance), azureADOptions.TenantId).ToString(); | ||
string audienceFormat = azureADOptions.Authority.Replace("{ClientId}", "{0}"); | ||
options.Audience = string.Format(audienceFormat, azureADOptions.ClientId); |
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.
We don't do things like this in the framework. Audience should be initialized here, not in the property, and it's also better to just use interpolated strings directly. $"api://{azureAdOptions.ClientId}"
@@ -29,7 +29,8 @@ public void Configure(string name, OpenIdConnectOptions options) | |||
|
|||
options.ClientId = azureADOptions.ClientId; | |||
options.ClientSecret = azureADOptions.ClientSecret; | |||
options.Authority = new Uri(new Uri(azureADOptions.Instance), azureADOptions.TenantId).ToString(); | |||
string authorityFormat = azureADOptions.Authority.Replace("{Instance}", "{0}").Replace("{Tenant}", "{1}"); |
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.
Same comment as for the audience
/// </summary> | ||
public string TenantId { get; set; } | ||
public string Tenant { get; set; } = "common"; |
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 is a breaking change. It'll have to be discussed
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.
I don't think we should default to the common tenant here as just using the common tenant without additional per-app restriction is not recommended.
/// </summary> | ||
public string Audience { get; set; } = "api://{ClientId}"; |
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.
Can the audience be completely different from the client id or is always derived from the client id though some transformation.
Proposes improvements to the AzureADOptions:
dotnet new mvc
Proposing that Web applications are now v2.0 apps by default.
Proposing improvements to the XML documentation
Note that
This PR is essentially to start the discussion. It's not mean to be final. In particular, no special effort was made for the tests yet