Skip to content
This repository was archived by the owner on Dec 20, 2018. It is now read-only.

Proposes more flexible AzureADOptions, and defaulting to AzureAD v2.0 #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jmprieur
Copy link

Proposes improvements to the AzureADOptions:

  • 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 to 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 "meta-tenants" (common, organizations and consumers)

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

- 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.
@dnfclas
Copy link

dnfclas commented Oct 31, 2018

CLA assistant check
All CLA requirements met.

@jmprieur
Copy link
Author

@Tratcher @brentschmaltz FYI

@Tratcher
Copy link
Member

@blowdart @BillHiebert This would need to be accompanied with template and tooling changes to get the right fields populated in config.

@blowdart
Copy link
Member

Without tooling changes this can't be merged, the VS UI would get everything wrong. So it's not as simple as this PR :)

@jmprieur
Copy link
Author

jmprieur commented Oct 31, 2018

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:

  • are we happy with renaming TenantId to Tenant? or not. Note that we could do with keeping TenantId (which would be one less breaking change) and use it for tenant information in general: not necessarily a guid. That's the case today, even if the meaning is not very clear
  • are we happy to remove Domain (which is not used anywhere btw)

Then as far as template and tooling changes, could you please send me the location of the repos, so that we propose PRs?

@blowdart
Copy link
Member

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 Tratcher requested a review from javiercn October 31, 2018 15:55
Copy link
Member

@Tratcher Tratcher left a 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);
Copy link
Member

@Tratcher Tratcher Oct 31, 2018

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.

Suggested change
options.Audience = string.Format(audienceFormat, azureADOptions.ClientId);
options.Audience = azureADOptions.Authority.Replace("{ClientId}", azureADOptions.ClientId);

Copy link
Member

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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing

@Tratcher
Copy link
Member

@phenning for tooling.

@Tratcher
Copy link
Member

#50

Copy link
Member

@javiercn javiercn left a 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);
Copy link
Member

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}");
Copy link
Member

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";
Copy link
Member

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

Copy link
Member

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}";
Copy link
Member

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants