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

fix: Authentication level claim is 0 in dialog token #1654

Merged
merged 5 commits into from
Jan 9, 2025

Conversation

Fargekritt
Copy link
Contributor

@Fargekritt Fargekritt commented Jan 7, 2025

Description

Changed IdportenAuthLevelClaim constant to fix parsing of Acr field in dialog token

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)

Documentation

  • Documentation is updated (either in docs-directory, Altinnpedia or a separate linked PR in altinn-studio-docs., if applicable)

@Fargekritt Fargekritt requested a review from a team as a code owner January 7, 2025 10:50
Copy link
Contributor

coderabbitai bot commented Jan 7, 2025

📝 Walkthrough

Walkthrough

The pull request introduces changes to JWT claim handling in two authentication extension files. Specifically, it adds a new using directive for System.IdentityModel.Tokens.Jwt and sets JwtSecurityTokenHandler.DefaultMapInboundClaims to false. This modification prevents the automatic mapping of JWT claims to their longer URI representations, explicitly altering how claims are processed during authentication.

Changes

File Change Summary
src/Digdir.Domain.Dialogporten.GraphQL/Common/Authentication/AuthenticationBuilderExtensions.cs Added JWT-related using directive and set JwtSecurityTokenHandler.DefaultMapInboundClaims to false to control claim mapping behavior.
src/Digdir.Domain.Dialogporten.WebApi/Common/Authentication/AuthenticationBuilderExtensions.cs Added JWT-related using directive and set JwtSecurityTokenHandler.DefaultMapInboundClaims to false to control claim mapping behavior.

Possibly related issues

  • Authentication level claim is 0 in dialog token #1458 (Authentication level claim is 0 in dialog token): This issue discusses discrepancies in authentication level claims, which might be related to the JWT claim handling changes in this PR. The modification of claim mapping could potentially impact how authentication levels are processed.

Possibly related PRs

  • None identified with strong code-level connections.

Suggested reviewers

  • MagnusSandgren

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 37589cc and cce2e49.

📒 Files selected for processing (1)
  • src/Digdir.Domain.Dialogporten.GraphQL/Common/Authentication/AuthenticationBuilderExtensions.cs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Digdir.Domain.Dialogporten.GraphQL/Common/Authentication/AuthenticationBuilderExtensions.cs
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Dry run deploy apps / Deploy job sync-subject-resource-mappings-job to test
  • GitHub Check: build / build-and-test

Finishing Touches

  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Fargekritt Fargekritt marked this pull request as draft January 7, 2025 14:26
@Fargekritt Fargekritt changed the title fix: Changed IdportenAuthLevelClaim constant fix: Authentication level claim is 0 in dialog token Jan 8, 2025
@Fargekritt Fargekritt marked this pull request as ready for review January 8, 2025 10:10
oskogstad
oskogstad previously approved these changes Jan 8, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/Digdir.Domain.Dialogporten.GraphQL/Common/Authentication/AuthenticationBuilderExtensions.cs (1)

14-14: Remove the commented out duplicate setting.

This line duplicates the setting at line 29. Having multiple instances of the same configuration, even if commented out, can lead to confusion.

-        // JwtSecurityTokenHandler.DefaultMapInboundClaims = false;
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8588ab5 and 37589cc.

📒 Files selected for processing (2)
  • src/Digdir.Domain.Dialogporten.GraphQL/Common/Authentication/AuthenticationBuilderExtensions.cs (3 hunks)
  • src/Digdir.Domain.Dialogporten.WebApi/Common/Authentication/AuthenticationBuilderExtensions.cs (2 hunks)
🧰 Additional context used
📓 Learnings (1)
src/Digdir.Domain.Dialogporten.GraphQL/Common/Authentication/AuthenticationBuilderExtensions.cs (1)
Learnt from: oskogstad
PR: digdir/dialogporten#1124
File: src/Digdir.Domain.Dialogporten.GraphQL/Common/Authorization/DialogTokenMiddleware.cs:56-59
Timestamp: 2024-11-12T05:32:45.311Z
Learning: The `DialogTokenMiddleware` only adds claims to user identities; the `AuthorizationOptionsSetup` validates that the `dialogID` in the token matches the `dialogID` in the subscription query and returns a 401 Unauthorized if they don't match.
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Dry run deploy apps / Deploy job sync-resource-policy-information-job to test
  • GitHub Check: Dry run deploy apps / Deploy job sync-subject-resource-mappings-job to test
  • GitHub Check: build / build-and-test
🔇 Additional comments (4)
src/Digdir.Domain.Dialogporten.WebApi/Common/Authentication/AuthenticationBuilderExtensions.cs (2)

4-4: LGTM!

The added using directive is necessary for JWT token handling.


28-30: LGTM! This change fixes the authentication level claim parsing.

Disabling the default claim mapping prevents the "acr" claim from being automatically mapped to its longer URI form, which should resolve the authentication level parsing issue.

Let's verify the impact on claim mapping:

✅ Verification successful

Verification successful: Claim mapping change is consistently applied and safe

The change to disable default claim mapping is correctly synchronized across both WebApi and GraphQL authentication configurations. All claim handling code in the codebase already uses the short "acr" form, with no dependencies on the long URI form found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any other code that might rely on the mapped claim name
rg -l "http://schemas.microsoft.com/claims/authnclassreference"

# Search for code handling the "acr" claim
rg '"acr"' -A 5

Length of output: 5609

src/Digdir.Domain.Dialogporten.GraphQL/Common/Authentication/AuthenticationBuilderExtensions.cs (2)

4-4: LGTM!

The added using directive is necessary for JWT token handling.


27-29: LGTM! This change maintains consistency with WebApi implementation.

Disabling the default claim mapping here ensures consistent behavior across both WebApi and GraphQL implementations.

Let's verify the claim handling in DialogTokenMiddleware:

✅ Verification successful

Verification successful: Claim handling is consistent across implementations

The disabled claim mapping aligns perfectly with both the DialogTokenMiddleware implementation and the JWT handling in WebApi, ensuring claims remain in their original format throughout the system.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for DialogTokenMiddleware claim handling
ast-grep --pattern 'class DialogTokenMiddleware {
  $$$
  $_(ClaimsPrincipal $_) {
    $$$
  }
  $$$
}'

Length of output: 105


Script:

#!/bin/bash
# Find files containing DialogToken
rg -l "DialogToken"

# Search for claim handling patterns
ast-grep --pattern 'ClaimsPrincipal'

# Backup search for middleware implementations
rg -l "Middleware" --type cs

Length of output: 1803


Script:

#!/bin/bash
# Get content of DialogTokenMiddleware
cat src/Digdir.Domain.Dialogporten.GraphQL/Common/Authorization/DialogTokenMiddleware.cs

# Get content of both JWT selector middlewares for comparison
cat src/Digdir.Domain.Dialogporten.GraphQL/Common/Authentication/JwtSchemeSelectorMiddleware.cs
cat src/Digdir.Domain.Dialogporten.WebApi/Common/Authentication/JwtSchemeSelectorMiddleware.cs

Length of output: 5839

@Fargekritt Fargekritt merged commit 37e545a into main Jan 9, 2025
25 checks passed
@Fargekritt Fargekritt deleted the fix/auth-level-claim-0 branch January 9, 2025 12:10
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