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

feat(protocol): credential mediation #361

Merged
merged 1 commit into from
Jan 3, 2025
Merged

Conversation

james-d-elliott
Copy link
Member

@james-d-elliott james-d-elliott commented Dec 24, 2024

This adds support for credential mediation.

Closes #347

This adds support for credential mediation.
@james-d-elliott james-d-elliott requested a review from a team as a code owner December 24, 2024 12:25
Copy link

coderabbitai bot commented Dec 24, 2024

Walkthrough

This pull request introduces a comprehensive enhancement to the WebAuthn library's credential management by adding a CredentialMediationRequirement type and associated functionality. The changes span multiple files in the protocol and webauthn packages, introducing new methods and fields that allow more granular control over user authentication and registration processes. The implementation provides developers with the ability to specify different levels of user mediation during credential operations, aligning with WebAuthn and Credential Management API standards.

Changes

File Changes
protocol/authenticator.go - Added new type CredentialMediationRequirement
- Added constants: MediationSilent, MediationOptional, MediationConditional, MediationRequired
protocol/options.go - Added Mediation field to CredentialCreation and CredentialAssertion structs
webauthn/login.go - Added BeginDiscoverableLogin method
- Added BeginDiscoverableMediatedLogin method
- Updated BeginMediatedLogin and beginLogin method signatures to include mediation parameter
webauthn/registration.go - Added BeginMediatedRegistration method
- Modified BeginRegistration to use new mediated registration method

Sequence Diagram

sequenceDiagram
    participant Client
    participant WebAuthn
    participant AuthenticatorService
    
    Client->>WebAuthn: BeginMediatedLogin(user, mediation)
    WebAuthn->>AuthenticatorService: Request Credential Assertion
    AuthenticatorService-->>WebAuthn: Return Credential Options
    WebAuthn-->>Client: Return Credential Assertion with Mediation
Loading

Possibly related issues

  • Support for Mediation #347: Directly addresses the issue's request for support of mediation requirements in WebAuthn, providing implementation for credential presentation management and privacy protection.

Possibly related PRs

Poem

🐰 Hop, hop, through the auth domain,
Mediation's dance, no longer plain!
Silent, optional, or required with grace,
Passkeys now dance at their own pace!
WebAuthn's magic, a rabbit's delight! 🔐


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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

Copy link

@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 (4)
webauthn/login.go (3)

34-35: Consider providing a default mediation type.

Currently, passing an empty string ("") for the mediation requirement relies on the zero value. Using a meaningful default, such as protocol.MediationOptional, may improve clarity and prevent confusion.

func (webauthn *WebAuthn) BeginLogin(user User, opts ...LoginOption) (*protocol.CredentialAssertion, *SessionData, error) {
-	return webauthn.BeginMediatedLogin(user, "", opts...)
+	return webauthn.BeginMediatedLogin(user, protocol.MediationOptional, opts...)
}

37-39: Likewise, consider specifying an explicit mediation requirement for discoverable login.

Similar to the comment above, passing an empty string as the mediation requirement leaves it ambiguous. Specifying a default like protocol.MediationOptional may be clearer.


76-76: Mediation field assignment is correct.

Ensure the calling code or documentation clarifies expectations when mediation is empty or a non-standard value.

webauthn/registration.go (1)

24-25: Suggest clarifying the default mediation type in BeginRegistration.

Similarly to the login flow, passing an empty string may cause confusion about which mediation policy is in effect.

func (webauthn *WebAuthn) BeginRegistration(user User, opts ...RegistrationOption) (creation *protocol.CredentialCreation, session *SessionData, err error) {
-	return webauthn.BeginMediatedRegistration(user, "", opts...)
+	return webauthn.BeginMediatedRegistration(user, protocol.MediationOptional, opts...)
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7e1caf7 and 677f7ac.

📒 Files selected for processing (4)
  • protocol/authenticator.go (1 hunks)
  • protocol/options.go (1 hunks)
  • webauthn/login.go (3 hunks)
  • webauthn/registration.go (2 hunks)
🔇 Additional comments (13)
webauthn/login.go (4)

42-43: New function introducing mediation parameter looks good.

The docstring aligns with the new mediation feature, and the function signature is well-structured.


56-56: Straightforward propagation of the mediation parameter.

This call neatly forwards all relevant parameters to beginLogin.


59-62: Consistent approach for discoverable mediated login.

The additional method is consistent with the other login flows, providing a mediation parameter for discoverable credentials.


65-65: Updated function signature for beginLogin.

Including the mediation parameter maintains consistency and extends configurability.

webauthn/registration.go (2)

27-28: New mediated registration function is well-integrated.

It mirrors the approach in the login flow and appears functionally sound.


72-72: Mediation field addition is consistent.

The usage aligns with the broader mediation pattern introduced in the codebase.

protocol/options.go (2)

8-9: Added Mediation field for CredentialCreation.

This field adheres to the new design for specifying mediation requirements.


13-14: Added Mediation field for CredentialAssertion.

Similarly extends mediation functionality to assertions. The approach is consistent with the creation flow.

protocol/authenticator.go (5)

60-66: Definition of CredentialMediationRequirement is well-documented.

The references to the W3C Credential Management spec provide clarity on usage.


67-72: MediationSilent constant implementation looks good.

The descriptive comment helps clarify expected behavior.


73-76: MediationOptional constant is properly introduced.

Documentation is succinct and accurate to the spec.


77-84: MediationConditional constant is well-defined.

The thorough explanation of non-modal dialog behavior is beneficial for implementers.


85-88: MediationRequired constant is clearly described.

Nicely captures the requirement to always involve user mediation.

@james-d-elliott james-d-elliott merged commit b9a233f into master Jan 3, 2025
6 checks passed
@james-d-elliott james-d-elliott deleted the feat-mediation branch January 3, 2025 00:38
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.

Support for Mediation
1 participant