Proposes more flexible AzureADOptions, and defaulting to AzureAD v2.0#49
Proposes more flexible AzureADOptions, and defaulting to AzureAD v2.0#49jmprieur wants to merge 1 commit intoaspnet:masterfrom
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) |
Tratcher
left a comment
There was a problem hiding this comment.
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.
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.
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}"
| { | ||
| o.Instance = "https://login.microsoftonline.com/"; | ||
| o.Domain = "test.onmicrosoft.com"; | ||
| o.Tenant= "test.onmicrosoft.com"; |
|
@phenning for 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.
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}"
| 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.
Same comment as for the audience
| /// </list> | ||
| /// </summary> | ||
| public string TenantId { get; set; } | ||
| public string Tenant { get; set; } = "common"; |
There was a problem hiding this comment.
This is a breaking change. It'll have to be discussed
There was a problem hiding this comment.
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.
| /// Gets or sets the audience for this Web Application or Web API (This audience needs | ||
| /// to match the audience of the tokens sent to access this application) | ||
| /// </summary> | ||
| public string Audience { get; set; } = "api://{ClientId}"; |
There was a problem hiding this comment.
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 mvcProposing 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