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

updates to id web to support authentication handlers than JwtBearer #1493

Closed
wants to merge 3 commits into from

Conversation

jennyf19
Copy link
Collaborator

@jennyf19 jennyf19 commented Oct 18, 2021

Have tested with release build, in addition to the migration samples from @jmprieur

  • WebApp-OIDC
    • MyOrg
    • B2C
  • WebApp-graph
    • Call-MSGraph
  • WebApp-your-API
    • MyOrg
    • B2C

* initial commit to move aadIssuerValidator

* avoid breaking changes

* add xml

* update tests

* fix test warning

* PR feedback
* add auth builder for token acqusition

* update XML

* update comment

* take JM's PR #1483 (#1492)

* PR feedback
@jennyf19 jennyf19 requested a review from jmprieur October 18, 2021 20:59
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
Thanks for this roll-up PR. This is very useful
Do we want to merge it to master? Or provide a release build to test things out?

@jennyf19
Copy link
Collaborator Author

jennyf19 commented Oct 18, 2021

I did a release build last night which we've already been testing with, so not sure if another one is needed at this point.

and yes, i would like to merge to master if this is the direction we want to go.


In reply to: 782580128

@jennyf19 jennyf19 marked this pull request as ready for review October 18, 2021 21:26
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 9 Code Smells

34.6% 34.6% Coverage
0.0% 0.0% Duplication

</ItemGroup>

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1; net462; net472; net5.0; netstandard2.0</TargetFrameworks>
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I guess net45 is out of the picture because of the System.Text.Json dependency.

Copy link
Collaborator

@jmprieur jmprieur Oct 20, 2021

Choose a reason for hiding this comment

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

@GeoK: Do we need to support net45? would we want to leverage Microsoft.IdentityModel.Json for net45 ? or even for all the target framework?

Copy link
Member

Choose a reason for hiding this comment

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

Depending on the assembly that will host this model. Microsoft.IdentityModel.Json is internal and would have to grant internals to IdWeb which is less than ideal.

using System.Runtime.CompilerServices;

// Allow this assembly to be serviced when run on desktop CLR
[assembly: InternalsVisibleTo("Microsoft.Identity.Web.IssuerValidator.Test, PublicKey=00240000048000009400000006020000002400005253413100040000010001002D96616729B54F6D013D71559A017F50AA4861487226C523959D1579B93F3FDF71C08B980FD3130062B03D3DE115C4B84E7AC46AEF5E192A40E7457D5F3A08F66CEAB71143807F2C3CB0DA5E23B38F0559769978406F6E5D30CEADD7985FC73A5A609A8B74A1DF0A29399074A003A226C943D480FEC96DBEC7106A87896539AD")]
Copy link
Member

Choose a reason for hiding this comment

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

nit: spacing

actualIssuer));
}

private string CreateV1Authority()
{
if (AadAuthority.Contains(Constants.Organizations, StringComparison.OrdinalIgnoreCase))
#if DOTNET_STANDARD_20 || DOTNET_462 || DOTNET_472
if (AadAuthority.Contains(IssuerValidatorConstants.Organizations))
Copy link
Member

Choose a reason for hiding this comment

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

Would it be fair to say that if AadAuthority is not 'common'/'organizations', extracting a tenantId and creating & comparing URIs is not necessary? Thinking if we could cut these cycles as issuer validation is on the hot-path.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense, great point.

@@ -132,36 +129,46 @@ public class AadIssuerValidator
throw new SecurityTokenInvalidIssuerException(
string.Format(
CultureInfo.InvariantCulture,
IDWebErrorMessage.IssuerDoesNotMatchValidIssuers,
IssuerValidatorErrorMessage.IssuerDoesNotMatchValidIssuers,
Copy link
Member

Choose a reason for hiding this comment

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

Would be good to throw in the catch segment above and capture more information on what caused a potential issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good idea. will update.

AadAuthority = aadAuthority.TrimEnd('/');
}

private IOptions<AadIssuerValidatorOptions> AadIssuerValidatorOptions { get; }
private IHttpClientFactory HttpClientFactory { get; }
private HttpClient? HttpClient { get; }
Copy link
Member

Choose a reason for hiding this comment

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

If TVP.ValidIssuer(s) is empty, AadIssuerV1/2 will be populated only once (no refresh). Is this an issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

are you suggesting a refresh after a certain amount of time to check if the metadata has changed?

Copy link
Member

Choose a reason for hiding this comment

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

Yes. Not sure if the lack of refresh could be the issue (not expecting issuer to change). Code might be broken if the issuer on the metadata changes so that it doesn't contain {tenantId}, and refresh wouldn't help there.

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