Skip to content
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

Jennyf/null ref #139

Closed
wants to merge 2 commits into from
Closed

Jennyf/null ref #139

wants to merge 2 commits into from

Conversation

jennyf19
Copy link
Collaborator

…ither null or white space in the configuration settings.
- clean up authority helpers
- add unit tests
- add string.format()
@jennyf19
Copy link
Collaborator Author

jennyf19 commented Apr 30, 2020

@bgavrilMS this is related to the MSAL null ref we discussed this morning.

Here's a PR for MSAL .NET
and the related issue with more info.

Copy link
Collaborator

@jmprieur jmprieur left a comment

Choose a reason for hiding this comment

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

LGTM. @jennyf19
Thanks for making the configuration more reliable

for the future, I just discovered that we could implement a IValidateOptions. See for instance https://github.com/dotnet/aspnetcore/blob/master/src/Azure/AzureAD/Authentication.AzureAD.UI/src/AzureADOptionsValidation.cs

It's then registered like this: https://github.com/dotnet/aspnetcore/blob/49b4f418d5e7351b192023515e33e06c84d25e0e/src/Azure/AzureAD/Authentication.AzureAD.UI/src/AzureADAuthenticationBuilderExtensions.cs#L63

Maybe we'd want to raise a new issue to use this pattern (which separates concerns even better)?

var userFlow = options.DefaultUserFlow;
return new Uri(baseUri, new PathString($"{pathBase}/{domain}/{userFlow}/v2.0")).ToString();
}
else
else // Create an AAD authority
Copy link
Member

Choose a reason for hiding this comment

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

If it's not B2C, it can be ADFS.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@bgavrilMS : do you think that Microsoft.Identity.Web should support ADFS?

Copy link
Member

Choose a reason for hiding this comment

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

I think you should at least throw a "not supported" exception or smth.

throw;
}
}

internal void CheckApplicationOptionsContainClientSecret(ConfidentialClientApplicationOptions applicationOptions)
Copy link
Member

Choose a reason for hiding this comment

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

I think that this fix is not necessary in Identity.Web, and that it should be only in MSAL. But I can understand having a tactical fix in Identity.Web if you cannot wait for the next MSAL release (or you can hotfix MSAL).

Copy link
Collaborator

Choose a reason for hiding this comment

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

We want to check the other parameters anyway.

@@ -349,6 +353,8 @@ private async Task<IConfidentialClientApplication> BuildConfidentialClientApplic

try
{
CheckApplicationOptionsContainClientSecret(_applicationOptions);
Copy link
Member

Choose a reason for hiding this comment

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

TLDR: What about certificates?

There are 4 ways of specifying the secure contract between the server and AAD in a confidential client:

  • client secret (should not really be used in production)
  • cert (recommended)
  • client assertion (which is essentially a string with cert details - we use this when MSAL can't handle wierd certs)
  • cert + extra claims

ConfidentialClientApplicationOptions only allows users to pass in a secret. But you must provide mechanism for user to configure certificates.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@bgavrilMS : yes, and we have an enhancements issue for this: (#12).

For the moment, proposing an incremental approach

if (string.IsNullOrEmpty(applicationOptions.ClientSecret))
{
string msg = string.Format(CultureInfo.InvariantCulture, "Client secret cannot be null or whitespace, " +
"and must be included in the configuration of the web app when calling a web API. " +
Copy link
Member

Choose a reason for hiding this comment

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

A certificate can be used instead of a secret.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@bgavrilMS : yes, and we have an enhancements issue for this: (#12).

For the moment, proposing an incremental approach

}
else
{
if (string.IsNullOrEmpty(microsoftIdentityOptions.TenantId))
Copy link
Member

Choose a reason for hiding this comment

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

What about ADFS?

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's a good question @bgavrilMS
For the moment, I did not even considered that Microsoft.Identity.Web coud support ADFS, but maybe it should.

Copy link
Member

@bgavrilMS bgavrilMS left a comment

Choose a reason for hiding this comment

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

ADFS and certs options need to be revisited

Copy link
Member

@bgavrilMS bgavrilMS left a comment

Choose a reason for hiding this comment

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

JM responded to my comments, I think it is ok once you decide what to do about adfs

@jennyf19
Copy link
Collaborator Author

LGTM. @jennyf19
Thanks for making the configuration more reliable

for the future, I just discovered that we could implement a IValidateOptions. See for instance https://github.com/dotnet/aspnetcore/blob/master/src/Azure/AzureAD/Authentication.AzureAD.UI/src/AzureADOptionsValidation.cs

It's then registered like this: https://github.com/dotnet/aspnetcore/blob/49b4f418d5e7351b192023515e33e06c84d25e0e/src/Azure/AzureAD/Authentication.AzureAD.UI/src/AzureADAuthenticationBuilderExtensions.cs#L63

Maybe we'd want to raise a new issue to use this pattern (which separates concerns even better)?

that's much easier. i just did it on a separate branch and it's easier to check web api options now. thx. will add some tests adn push that branhc.

@jennyf19 jennyf19 closed this Apr 30, 2020
@jennyf19 jennyf19 deleted the jennyf/nullRef branch April 30, 2020 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants