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

[OIDC 1] Add basic Entra ID token validation #10251

Merged
merged 1 commit into from
Nov 11, 2024
Merged

Conversation

joelverhagen
Copy link
Member

@joelverhagen joelverhagen commented Nov 7, 2024

Progress on #10212.

This adds an IEntraIdTokenValidator interface which accepts a parsed JWT (JSON web token) and performs basic Entra ID validation. This will be used by higher level code in a future PR.

The goal of this class is to assert that a given JWT is issued by Entra ID and is valid. The following checks are performed:

  1. The JWT signature is valid per Entra ID's signing keys, fetched via JWKS. This is done inside ConfigurationManager<OpenIdConnectConfiguration>.
  2. The issuer is an expected Entra ID value (iss claim and issuer property on the key). This is done via AadIssuerValidator.GetAadIssuerValidator and EnableAadSigningKeyIssuerValidation.
  3. The token is not expired (nbf and exp claims). This is done inside JsonWebTokenHandler.ValidateTokenAsync.
  4. The token has a valid audience (aud claim). A valid aud claim is our configured app client ID. This is done inside JsonWebTokenHandler.ValidateTokenAsync.

Other validations like replay protection, matching tenant ID/object ID, etc will be done elsewhere.

This minimal set of validations mimic the OWIN integration in Microsoft.Identity.Web:
https://github.com/AzureAD/microsoft-identity-web/blob/011bd155ce3ddedeb43daa7348e09584cfa20552/src/Microsoft.Identity.Web.OWIN/AppBuilderExtension.cs#L62-L73

This handles issuer, audience, expiration, and signature validation
@joelverhagen joelverhagen requested a review from a team as a code owner November 7, 2024 15:36

public class EntraIdTokenValidator : IEntraIdTokenValidator
{
private static string EntraIdAuthority { get; } = "https://login.microsoftonline.com/common/v2.0";
Copy link
Member Author

@joelverhagen joelverhagen Nov 7, 2024

Choose a reason for hiding this comment

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

From NuGetGallery's perspective, any tenant is allowed, thus the common endpoint. The tenant ID per accepted service principal will be validated elsewhere.

@joelverhagen joelverhagen changed the title Add basic Entra ID token validation [OIDC 1] Add basic Entra ID token validation Nov 7, 2024
@joelverhagen joelverhagen merged commit 088e9da into dev Nov 11, 2024
3 checks passed
@joelverhagen joelverhagen deleted the jver-oidc-ship branch November 11, 2024 22:22
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.

2 participants