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

🔥 Feature: Add support for multiple keys in the KeyAuth middleware #3027

Closed

Conversation

dave-gray101
Copy link
Contributor

@dave-gray101 dave-gray101 commented Jun 8, 2024

Description

I'm working on a project that must accept api keys from multiple possible sources, such as different header names. I've implemented this by slightly modifying the existing keyauth middleware, and I'd like to contribute it upstream.

Changes introduced

This is a fairly minimal enhancement to the existing keyauth middleware. I have extracted the existing extractor assignment code into a private function, and added a new []string parameter to Config named AdditionalKeyLookups. Any values set here are interpreted just like KeyLookup, and are checked in order if there is no API key found at KeyLookup

Type of change

Please delete options that are not relevant.

  • Enhancement (improvement to existing features and functionality)

Copy link

welcome bot commented Jun 8, 2024

Thanks for opening this pull request! 🎉 Please check out our contributing guidelines. If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

Copy link
Contributor

coderabbitai bot commented Jun 8, 2024

Walkthrough

The recent updates enhance the keyauth middleware by introducing support for multiple key lookups using the pipe (|) character and adding a FallbackKeyLookups field for secondary key sources. Error handling and key extraction processes have also been improved, along with the addition of new test functions to ensure robust functionality.

Changes

File Change Summary
docs/api/middleware/keyauth.md Updated documentation to reflect support for multiple key lookups and the new FallbackKeyLookups field.
middleware/keyauth/config.go Added FallbackKeyLookups field to the Config struct and ensured it initializes with an empty slice if nil.
middleware/keyauth/keyauth.go Enhanced the New function to support multiple key lookups, added parseSingleExtractor and extractorFunc type for improved key extraction.
middleware/keyauth/keyauth_test.go Added TestMultipleKeyLookup function to verify authentication with multiple key sources including header, cookie, and query parameters.

Poem

In the land of code where keys unlock,
A rabbit hops with digital clock.
Multiple paths to find the way,
Through headers, cookies, come what may.
Fallbacks guide when primary fails,
Ensuring access, no derails.
CodeRabbit dances, changes made,
In fiber’s realm, the keys now laid.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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
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: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6c3eb80 and 2eee0dd.

Files selected for processing (3)
  • docs/api/middleware/keyauth.md (1 hunks)
  • middleware/keyauth/keyauth.go (6 hunks)
  • middleware/keyauth/keyauth_test.go (1 hunks)
Additional context used
LanguageTool
docs/api/middleware/keyauth.md

[uncategorized] ~7-~7: This expression is usually spelled with a hyphen. (BASED_HYPHEN)
Context: ...Keyauth Key auth middleware provides a key based authentication. ## Signatures ```go f...


[uncategorized] ~77-~77: The abbreviation “e.g.” (= for example) requires two periods. (E_G)
Context: ...of keyauth and apply a filter function (eg. authFilter) like so ```go package ma...

Markdownlint
docs/api/middleware/keyauth.md

21-21: Column: 1 (MD010, no-hard-tabs)
Hard tabs


22-22: Column: 1 (MD010, no-hard-tabs)
Hard tabs


23-23: Column: 1 (MD010, no-hard-tabs)
Hard tabs


24-24: Column: 1 (MD010, no-hard-tabs)
Hard tabs


28-28: Column: 1 (MD010, no-hard-tabs)
Hard tabs


32-32: Column: 1 (MD010, no-hard-tabs)
Hard tabs


33-33: Column: 1 (MD010, no-hard-tabs)
Hard tabs


35-35: Column: 1 (MD010, no-hard-tabs)
Hard tabs


36-36: Column: 1 (MD010, no-hard-tabs)
Hard tabs


37-37: Column: 1 (MD010, no-hard-tabs)
Hard tabs


38-38: Column: 1 (MD010, no-hard-tabs)
Hard tabs


42-42: Column: 1 (MD010, no-hard-tabs)
Hard tabs


44-44: Column: 1 (MD010, no-hard-tabs)
Hard tabs


45-45: Column: 1 (MD010, no-hard-tabs)
Hard tabs


46-46: Column: 1 (MD010, no-hard-tabs)
Hard tabs


47-47: Column: 1 (MD010, no-hard-tabs)
Hard tabs


48-48: Column: 1 (MD010, no-hard-tabs)
Hard tabs


50-50: Column: 1 (MD010, no-hard-tabs)
Hard tabs


51-51: Column: 1 (MD010, no-hard-tabs)
Hard tabs


52-52: Column: 1 (MD010, no-hard-tabs)
Hard tabs


54-54: Column: 1 (MD010, no-hard-tabs)
Hard tabs


83-83: Column: 1 (MD010, no-hard-tabs)
Hard tabs


84-84: Column: 1 (MD010, no-hard-tabs)
Hard tabs


85-85: Column: 1 (MD010, no-hard-tabs)
Hard tabs


86-86: Column: 1 (MD010, no-hard-tabs)
Hard tabs


87-87: Column: 1 (MD010, no-hard-tabs)
Hard tabs


88-88: Column: 1 (MD010, no-hard-tabs)
Hard tabs


92-92: Column: 1 (MD010, no-hard-tabs)
Hard tabs


93-93: Column: 1 (MD010, no-hard-tabs)
Hard tabs


94-94: Column: 1 (MD010, no-hard-tabs)
Hard tabs


95-95: Column: 1 (MD010, no-hard-tabs)
Hard tabs


96-96: Column: 1 (MD010, no-hard-tabs)
Hard tabs


100-100: Column: 1 (MD010, no-hard-tabs)
Hard tabs


101-101: Column: 1 (MD010, no-hard-tabs)
Hard tabs


103-103: Column: 1 (MD010, no-hard-tabs)
Hard tabs


104-104: Column: 1 (MD010, no-hard-tabs)
Hard tabs


105-105: Column: 1 (MD010, no-hard-tabs)
Hard tabs


106-106: Column: 1 (MD010, no-hard-tabs)
Hard tabs


110-110: Column: 1 (MD010, no-hard-tabs)
Hard tabs


112-112: Column: 1 (MD010, no-hard-tabs)
Hard tabs


113-113: Column: 1 (MD010, no-hard-tabs)
Hard tabs


114-114: Column: 1 (MD010, no-hard-tabs)
Hard tabs


115-115: Column: 1 (MD010, no-hard-tabs)
Hard tabs


116-116: Column: 1 (MD010, no-hard-tabs)
Hard tabs


117-117: Column: 1 (MD010, no-hard-tabs)
Hard tabs


121-121: Column: 1 (MD010, no-hard-tabs)
Hard tabs


123-123: Column: 1 (MD010, no-hard-tabs)
Hard tabs


124-124: Column: 1 (MD010, no-hard-tabs)
Hard tabs


125-125: Column: 1 (MD010, no-hard-tabs)
Hard tabs


126-126: Column: 1 (MD010, no-hard-tabs)
Hard tabs


127-127: Column: 1 (MD010, no-hard-tabs)
Hard tabs


129-129: Column: 1 (MD010, no-hard-tabs)
Hard tabs


130-130: Column: 1 (MD010, no-hard-tabs)
Hard tabs


131-131: Column: 1 (MD010, no-hard-tabs)
Hard tabs


132-132: Column: 1 (MD010, no-hard-tabs)
Hard tabs


133-133: Column: 1 (MD010, no-hard-tabs)
Hard tabs


134-134: Column: 1 (MD010, no-hard-tabs)
Hard tabs


135-135: Column: 1 (MD010, no-hard-tabs)
Hard tabs


136-136: Column: 1 (MD010, no-hard-tabs)
Hard tabs


137-137: Column: 1 (MD010, no-hard-tabs)
Hard tabs


139-139: Column: 1 (MD010, no-hard-tabs)
Hard tabs


165-165: Column: 1 (MD010, no-hard-tabs)
Hard tabs


166-166: Column: 1 (MD010, no-hard-tabs)
Hard tabs


167-167: Column: 1 (MD010, no-hard-tabs)
Hard tabs


168-168: Column: 1 (MD010, no-hard-tabs)
Hard tabs


176-176: Column: 1 (MD010, no-hard-tabs)
Hard tabs


178-178: Column: 1 (MD010, no-hard-tabs)
Hard tabs


179-179: Column: 1 (MD010, no-hard-tabs)
Hard tabs


180-180: Column: 1 (MD010, no-hard-tabs)
Hard tabs


181-181: Column: 1 (MD010, no-hard-tabs)
Hard tabs


183-183: Column: 1 (MD010, no-hard-tabs)
Hard tabs


184-184: Column: 1 (MD010, no-hard-tabs)
Hard tabs


185-185: Column: 1 (MD010, no-hard-tabs)
Hard tabs


186-186: Column: 1 (MD010, no-hard-tabs)
Hard tabs


187-187: Column: 1 (MD010, no-hard-tabs)
Hard tabs


188-188: Column: 1 (MD010, no-hard-tabs)
Hard tabs


190-190: Column: 1 (MD010, no-hard-tabs)
Hard tabs


191-191: Column: 1 (MD010, no-hard-tabs)
Hard tabs


192-192: Column: 1 (MD010, no-hard-tabs)
Hard tabs


194-194: Column: 1 (MD010, no-hard-tabs)
Hard tabs


195-195: Column: 1 (MD010, no-hard-tabs)
Hard tabs


196-196: Column: 1 (MD010, no-hard-tabs)
Hard tabs


198-198: Column: 1 (MD010, no-hard-tabs)
Hard tabs


230-230: Column: 1 (MD010, no-hard-tabs)
Hard tabs


231-231: Column: 1 (MD010, no-hard-tabs)
Hard tabs


232-232: Column: 1 (MD010, no-hard-tabs)
Hard tabs


233-233: Column: 1 (MD010, no-hard-tabs)
Hard tabs


234-234: Column: 1 (MD010, no-hard-tabs)
Hard tabs


235-235: Column: 1 (MD010, no-hard-tabs)
Hard tabs


236-236: Column: 1 (MD010, no-hard-tabs)
Hard tabs


237-237: Column: 1 (MD010, no-hard-tabs)
Hard tabs


238-238: Column: 1 (MD010, no-hard-tabs)
Hard tabs


239-239: Column: 1 (MD010, no-hard-tabs)
Hard tabs


240-240: Column: 1 (MD010, no-hard-tabs)
Hard tabs


241-241: Column: 1 (MD010, no-hard-tabs)
Hard tabs


74-74: Expected: 1; Actual: 2 (MD012, no-multiple-blanks)
Multiple consecutive blank lines


221-221: Expected: 4; Actual: 5; Too many cells, extra data will be missing (MD056, table-column-count)
Table column count

Additional comments not posted (5)
middleware/keyauth/keyauth.go (3)

22-22: The new type extractorFunc standardizes the function signature for key extraction, which is a good practice for maintainability and consistency.


95-95: The keyFromHeader function correctly handles different authentication schemes. Good use of string slicing for extracting the token.


Line range hint 110-143: The key extraction functions (keyFromQuery, keyFromForm, keyFromParam, keyFromCookie) are implemented consistently and handle missing keys appropriately.

docs/api/middleware/keyauth.md (1)

221-221: The updated documentation for KeyLookup clearly explains the new functionality of supporting multiple keys separated by a pipe character. This aligns well with the code changes.

Tools
Markdownlint

221-221: Expected: 4; Actual: 5; Too many cells, extra data will be missing (MD056, table-column-count)
Table column count

middleware/keyauth/keyauth_test.go (1)

134-177: The TestMultipleKeyLookup function effectively tests the new functionality of handling multiple key sources. It covers both successful and unsuccessful scenarios, ensuring robust testing.

middleware/keyauth/keyauth.go Outdated Show resolved Hide resolved
middleware/keyauth/keyauth.go Outdated Show resolved Hide resolved
middleware/keyauth/keyauth.go Outdated Show resolved Hide resolved
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2eee0dd and 8659bd1.

Files selected for processing (4)
  • docs/api/middleware/keyauth.md (1 hunks)
  • middleware/keyauth/config.go (2 hunks)
  • middleware/keyauth/keyauth.go (7 hunks)
  • middleware/keyauth/keyauth_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • middleware/keyauth/keyauth.go
  • middleware/keyauth/keyauth_test.go
Additional context used
LanguageTool
docs/api/middleware/keyauth.md

[uncategorized] ~7-~7: This expression is usually spelled with a hyphen. (BASED_HYPHEN)
Context: ...Keyauth Key auth middleware provides a key based authentication. ## Signatures ```go f...


[uncategorized] ~77-~77: The abbreviation “e.g.” (= for example) requires two periods. (E_G)
Context: ...of keyauth and apply a filter function (eg. authFilter) like so ```go package ma...


[uncategorized] ~217-~217: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ...-------|:------------------------------| | Next | `func(*fiber.Ctx) boo...


[uncategorized] ~221-~221: Possible missing article found. (AI_HYDRA_LEO_MISSING_THE)
Context: ...ource>:`" that is used to extract key from the request. | "header:Authorizati...

Markdownlint
docs/api/middleware/keyauth.md

21-21: Column: 1 (MD010, no-hard-tabs)
Hard tabs


22-22: Column: 1 (MD010, no-hard-tabs)
Hard tabs


23-23: Column: 1 (MD010, no-hard-tabs)
Hard tabs


24-24: Column: 1 (MD010, no-hard-tabs)
Hard tabs


28-28: Column: 1 (MD010, no-hard-tabs)
Hard tabs


32-32: Column: 1 (MD010, no-hard-tabs)
Hard tabs


33-33: Column: 1 (MD010, no-hard-tabs)
Hard tabs


35-35: Column: 1 (MD010, no-hard-tabs)
Hard tabs


36-36: Column: 1 (MD010, no-hard-tabs)
Hard tabs


37-37: Column: 1 (MD010, no-hard-tabs)
Hard tabs


38-38: Column: 1 (MD010, no-hard-tabs)
Hard tabs


42-42: Column: 1 (MD010, no-hard-tabs)
Hard tabs


44-44: Column: 1 (MD010, no-hard-tabs)
Hard tabs


45-45: Column: 1 (MD010, no-hard-tabs)
Hard tabs


46-46: Column: 1 (MD010, no-hard-tabs)
Hard tabs


47-47: Column: 1 (MD010, no-hard-tabs)
Hard tabs


48-48: Column: 1 (MD010, no-hard-tabs)
Hard tabs


50-50: Column: 1 (MD010, no-hard-tabs)
Hard tabs


51-51: Column: 1 (MD010, no-hard-tabs)
Hard tabs


52-52: Column: 1 (MD010, no-hard-tabs)
Hard tabs


54-54: Column: 1 (MD010, no-hard-tabs)
Hard tabs


83-83: Column: 1 (MD010, no-hard-tabs)
Hard tabs


84-84: Column: 1 (MD010, no-hard-tabs)
Hard tabs


85-85: Column: 1 (MD010, no-hard-tabs)
Hard tabs


86-86: Column: 1 (MD010, no-hard-tabs)
Hard tabs


87-87: Column: 1 (MD010, no-hard-tabs)
Hard tabs


88-88: Column: 1 (MD010, no-hard-tabs)
Hard tabs


92-92: Column: 1 (MD010, no-hard-tabs)
Hard tabs


93-93: Column: 1 (MD010, no-hard-tabs)
Hard tabs


94-94: Column: 1 (MD010, no-hard-tabs)
Hard tabs


95-95: Column: 1 (MD010, no-hard-tabs)
Hard tabs


96-96: Column: 1 (MD010, no-hard-tabs)
Hard tabs


100-100: Column: 1 (MD010, no-hard-tabs)
Hard tabs


101-101: Column: 1 (MD010, no-hard-tabs)
Hard tabs


103-103: Column: 1 (MD010, no-hard-tabs)
Hard tabs


104-104: Column: 1 (MD010, no-hard-tabs)
Hard tabs


105-105: Column: 1 (MD010, no-hard-tabs)
Hard tabs


106-106: Column: 1 (MD010, no-hard-tabs)
Hard tabs


110-110: Column: 1 (MD010, no-hard-tabs)
Hard tabs


112-112: Column: 1 (MD010, no-hard-tabs)
Hard tabs


113-113: Column: 1 (MD010, no-hard-tabs)
Hard tabs


114-114: Column: 1 (MD010, no-hard-tabs)
Hard tabs


115-115: Column: 1 (MD010, no-hard-tabs)
Hard tabs


116-116: Column: 1 (MD010, no-hard-tabs)
Hard tabs


117-117: Column: 1 (MD010, no-hard-tabs)
Hard tabs


121-121: Column: 1 (MD010, no-hard-tabs)
Hard tabs


123-123: Column: 1 (MD010, no-hard-tabs)
Hard tabs


124-124: Column: 1 (MD010, no-hard-tabs)
Hard tabs


125-125: Column: 1 (MD010, no-hard-tabs)
Hard tabs


126-126: Column: 1 (MD010, no-hard-tabs)
Hard tabs


127-127: Column: 1 (MD010, no-hard-tabs)
Hard tabs


129-129: Column: 1 (MD010, no-hard-tabs)
Hard tabs


130-130: Column: 1 (MD010, no-hard-tabs)
Hard tabs


131-131: Column: 1 (MD010, no-hard-tabs)
Hard tabs


132-132: Column: 1 (MD010, no-hard-tabs)
Hard tabs


133-133: Column: 1 (MD010, no-hard-tabs)
Hard tabs


134-134: Column: 1 (MD010, no-hard-tabs)
Hard tabs


135-135: Column: 1 (MD010, no-hard-tabs)
Hard tabs


136-136: Column: 1 (MD010, no-hard-tabs)
Hard tabs


137-137: Column: 1 (MD010, no-hard-tabs)
Hard tabs


139-139: Column: 1 (MD010, no-hard-tabs)
Hard tabs


165-165: Column: 1 (MD010, no-hard-tabs)
Hard tabs


166-166: Column: 1 (MD010, no-hard-tabs)
Hard tabs


167-167: Column: 1 (MD010, no-hard-tabs)
Hard tabs


168-168: Column: 1 (MD010, no-hard-tabs)
Hard tabs


176-176: Column: 1 (MD010, no-hard-tabs)
Hard tabs


178-178: Column: 1 (MD010, no-hard-tabs)
Hard tabs


179-179: Column: 1 (MD010, no-hard-tabs)
Hard tabs


180-180: Column: 1 (MD010, no-hard-tabs)
Hard tabs


181-181: Column: 1 (MD010, no-hard-tabs)
Hard tabs


183-183: Column: 1 (MD010, no-hard-tabs)
Hard tabs


184-184: Column: 1 (MD010, no-hard-tabs)
Hard tabs


185-185: Column: 1 (MD010, no-hard-tabs)
Hard tabs


186-186: Column: 1 (MD010, no-hard-tabs)
Hard tabs


187-187: Column: 1 (MD010, no-hard-tabs)
Hard tabs


188-188: Column: 1 (MD010, no-hard-tabs)
Hard tabs


190-190: Column: 1 (MD010, no-hard-tabs)
Hard tabs


191-191: Column: 1 (MD010, no-hard-tabs)
Hard tabs


192-192: Column: 1 (MD010, no-hard-tabs)
Hard tabs


194-194: Column: 1 (MD010, no-hard-tabs)
Hard tabs


195-195: Column: 1 (MD010, no-hard-tabs)
Hard tabs


196-196: Column: 1 (MD010, no-hard-tabs)
Hard tabs


198-198: Column: 1 (MD010, no-hard-tabs)
Hard tabs


231-231: Column: 1 (MD010, no-hard-tabs)
Hard tabs


232-232: Column: 1 (MD010, no-hard-tabs)
Hard tabs


233-233: Column: 1 (MD010, no-hard-tabs)
Hard tabs


234-234: Column: 1 (MD010, no-hard-tabs)
Hard tabs


235-235: Column: 1 (MD010, no-hard-tabs)
Hard tabs


236-236: Column: 1 (MD010, no-hard-tabs)
Hard tabs


237-237: Column: 1 (MD010, no-hard-tabs)
Hard tabs


238-238: Column: 1 (MD010, no-hard-tabs)
Hard tabs


239-239: Column: 1 (MD010, no-hard-tabs)
Hard tabs


240-240: Column: 1 (MD010, no-hard-tabs)
Hard tabs


241-241: Column: 1 (MD010, no-hard-tabs)
Hard tabs


242-242: Column: 1 (MD010, no-hard-tabs)
Hard tabs


74-74: Expected: 1; Actual: 2 (MD012, no-multiple-blanks)
Multiple consecutive blank lines

Additional comments not posted (3)
middleware/keyauth/config.go (2)

35-38: The addition of AdditionalKeyLookups enhances the flexibility of key source specification. Good implementation and documentation.


91-93: Initializing AdditionalKeyLookups to an empty slice by default is a prudent defensive programming practice.

docs/api/middleware/keyauth.md (1)

222-222: The documentation update for AdditionalKeyLookups is clear and informative, correctly reflecting the new functionality.

Signed-off-by: Dave Lee <[email protected]>
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8659bd1 and 3e51245.

Files selected for processing (1)
  • middleware/keyauth/keyauth.go (7 hunks)
Files skipped from review as they are similar to previous changes (1)
  • middleware/keyauth/keyauth.go

Copy link
Member

@gaby gaby left a comment

Choose a reason for hiding this comment

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

Looks good, just two minor comments

docs/api/middleware/keyauth.md Outdated Show resolved Hide resolved
docs/api/middleware/keyauth.md Show resolved Hide resolved
Signed-off-by: Dave Lee <[email protected]>
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: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3e51245 and 468bd1e.

Files selected for processing (4)
  • docs/api/middleware/keyauth.md (2 hunks)
  • middleware/keyauth/config.go (2 hunks)
  • middleware/keyauth/keyauth.go (7 hunks)
  • middleware/keyauth/keyauth_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • middleware/keyauth/config.go
  • middleware/keyauth/keyauth.go
  • middleware/keyauth/keyauth_test.go
Additional context used
LanguageTool
docs/api/middleware/keyauth.md

[uncategorized] ~7-~7: This expression is usually spelled with a hyphen. (BASED_HYPHEN)
Context: ...Keyauth Key auth middleware provides a key based authentication. ## Signatures ```go f...


[uncategorized] ~77-~77: The abbreviation “e.g.” (= for example) requires two periods. (E_G)
Context: ...of keyauth and apply a filter function (eg. authFilter) like so ```go package ma...


[uncategorized] ~217-~217: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ...-------|:------------------------------| | Next | `func(*fiber.Ctx) boo...


[uncategorized] ~221-~221: Possible missing article found. (AI_HYDRA_LEO_MISSING_THE)
Context: ...ource>:`" that is used to extract key from the request. | "header:Authorizati...

Markdownlint
docs/api/middleware/keyauth.md

21-21: Column: 1 (MD010, no-hard-tabs)
Hard tabs


22-22: Column: 1 (MD010, no-hard-tabs)
Hard tabs


23-23: Column: 1 (MD010, no-hard-tabs)
Hard tabs


24-24: Column: 1 (MD010, no-hard-tabs)
Hard tabs


28-28: Column: 1 (MD010, no-hard-tabs)
Hard tabs


32-32: Column: 1 (MD010, no-hard-tabs)
Hard tabs


33-33: Column: 1 (MD010, no-hard-tabs)
Hard tabs


35-35: Column: 1 (MD010, no-hard-tabs)
Hard tabs


36-36: Column: 1 (MD010, no-hard-tabs)
Hard tabs


37-37: Column: 1 (MD010, no-hard-tabs)
Hard tabs


38-38: Column: 1 (MD010, no-hard-tabs)
Hard tabs


42-42: Column: 1 (MD010, no-hard-tabs)
Hard tabs


44-44: Column: 1 (MD010, no-hard-tabs)
Hard tabs


45-45: Column: 1 (MD010, no-hard-tabs)
Hard tabs


46-46: Column: 1 (MD010, no-hard-tabs)
Hard tabs


47-47: Column: 1 (MD010, no-hard-tabs)
Hard tabs


48-48: Column: 1 (MD010, no-hard-tabs)
Hard tabs


50-50: Column: 1 (MD010, no-hard-tabs)
Hard tabs


51-51: Column: 1 (MD010, no-hard-tabs)
Hard tabs


52-52: Column: 1 (MD010, no-hard-tabs)
Hard tabs


54-54: Column: 1 (MD010, no-hard-tabs)
Hard tabs


83-83: Column: 1 (MD010, no-hard-tabs)
Hard tabs


84-84: Column: 1 (MD010, no-hard-tabs)
Hard tabs


85-85: Column: 1 (MD010, no-hard-tabs)
Hard tabs


86-86: Column: 1 (MD010, no-hard-tabs)
Hard tabs


87-87: Column: 1 (MD010, no-hard-tabs)
Hard tabs


88-88: Column: 1 (MD010, no-hard-tabs)
Hard tabs


92-92: Column: 1 (MD010, no-hard-tabs)
Hard tabs


93-93: Column: 1 (MD010, no-hard-tabs)
Hard tabs


94-94: Column: 1 (MD010, no-hard-tabs)
Hard tabs


95-95: Column: 1 (MD010, no-hard-tabs)
Hard tabs


96-96: Column: 1 (MD010, no-hard-tabs)
Hard tabs


100-100: Column: 1 (MD010, no-hard-tabs)
Hard tabs


101-101: Column: 1 (MD010, no-hard-tabs)
Hard tabs


103-103: Column: 1 (MD010, no-hard-tabs)
Hard tabs


104-104: Column: 1 (MD010, no-hard-tabs)
Hard tabs


105-105: Column: 1 (MD010, no-hard-tabs)
Hard tabs


106-106: Column: 1 (MD010, no-hard-tabs)
Hard tabs


110-110: Column: 1 (MD010, no-hard-tabs)
Hard tabs


112-112: Column: 1 (MD010, no-hard-tabs)
Hard tabs


113-113: Column: 1 (MD010, no-hard-tabs)
Hard tabs


114-114: Column: 1 (MD010, no-hard-tabs)
Hard tabs


115-115: Column: 1 (MD010, no-hard-tabs)
Hard tabs


116-116: Column: 1 (MD010, no-hard-tabs)
Hard tabs


117-117: Column: 1 (MD010, no-hard-tabs)
Hard tabs


121-121: Column: 1 (MD010, no-hard-tabs)
Hard tabs


123-123: Column: 1 (MD010, no-hard-tabs)
Hard tabs


124-124: Column: 1 (MD010, no-hard-tabs)
Hard tabs


125-125: Column: 1 (MD010, no-hard-tabs)
Hard tabs


126-126: Column: 1 (MD010, no-hard-tabs)
Hard tabs


127-127: Column: 1 (MD010, no-hard-tabs)
Hard tabs


129-129: Column: 1 (MD010, no-hard-tabs)
Hard tabs


130-130: Column: 1 (MD010, no-hard-tabs)
Hard tabs


131-131: Column: 1 (MD010, no-hard-tabs)
Hard tabs


132-132: Column: 1 (MD010, no-hard-tabs)
Hard tabs


133-133: Column: 1 (MD010, no-hard-tabs)
Hard tabs


134-134: Column: 1 (MD010, no-hard-tabs)
Hard tabs


135-135: Column: 1 (MD010, no-hard-tabs)
Hard tabs


136-136: Column: 1 (MD010, no-hard-tabs)
Hard tabs


137-137: Column: 1 (MD010, no-hard-tabs)
Hard tabs


139-139: Column: 1 (MD010, no-hard-tabs)
Hard tabs


165-165: Column: 1 (MD010, no-hard-tabs)
Hard tabs


166-166: Column: 1 (MD010, no-hard-tabs)
Hard tabs


167-167: Column: 1 (MD010, no-hard-tabs)
Hard tabs


168-168: Column: 1 (MD010, no-hard-tabs)
Hard tabs


176-176: Column: 1 (MD010, no-hard-tabs)
Hard tabs


178-178: Column: 1 (MD010, no-hard-tabs)
Hard tabs


179-179: Column: 1 (MD010, no-hard-tabs)
Hard tabs


180-180: Column: 1 (MD010, no-hard-tabs)
Hard tabs


181-181: Column: 1 (MD010, no-hard-tabs)
Hard tabs


183-183: Column: 1 (MD010, no-hard-tabs)
Hard tabs


184-184: Column: 1 (MD010, no-hard-tabs)
Hard tabs


185-185: Column: 1 (MD010, no-hard-tabs)
Hard tabs


186-186: Column: 1 (MD010, no-hard-tabs)
Hard tabs


187-187: Column: 1 (MD010, no-hard-tabs)
Hard tabs


188-188: Column: 1 (MD010, no-hard-tabs)
Hard tabs


190-190: Column: 1 (MD010, no-hard-tabs)
Hard tabs


191-191: Column: 1 (MD010, no-hard-tabs)
Hard tabs


192-192: Column: 1 (MD010, no-hard-tabs)
Hard tabs


194-194: Column: 1 (MD010, no-hard-tabs)
Hard tabs


195-195: Column: 1 (MD010, no-hard-tabs)
Hard tabs


196-196: Column: 1 (MD010, no-hard-tabs)
Hard tabs


198-198: Column: 1 (MD010, no-hard-tabs)
Hard tabs


231-231: Column: 1 (MD010, no-hard-tabs)
Hard tabs


232-232: Column: 1 (MD010, no-hard-tabs)
Hard tabs


233-233: Column: 1 (MD010, no-hard-tabs)
Hard tabs


234-234: Column: 1 (MD010, no-hard-tabs)
Hard tabs


235-235: Column: 1 (MD010, no-hard-tabs)
Hard tabs


236-236: Column: 1 (MD010, no-hard-tabs)
Hard tabs


237-237: Column: 1 (MD010, no-hard-tabs)
Hard tabs


238-238: Column: 1 (MD010, no-hard-tabs)
Hard tabs


239-239: Column: 1 (MD010, no-hard-tabs)
Hard tabs


240-240: Column: 1 (MD010, no-hard-tabs)
Hard tabs


241-241: Column: 1 (MD010, no-hard-tabs)
Hard tabs


242-242: Column: 1 (MD010, no-hard-tabs)
Hard tabs


243-243: Column: 1 (MD010, no-hard-tabs)
Hard tabs


74-74: Expected: 1; Actual: 2 (MD012, no-multiple-blanks)
Multiple consecutive blank lines

docs/api/middleware/keyauth.md Show resolved Hide resolved
docs/api/middleware/keyauth.md Show resolved Hide resolved
@gaby
Copy link
Member

gaby commented Jun 9, 2024

@coderabbitai full review

Copy link
Contributor

coderabbitai bot commented Jun 9, 2024

Actions performed

Full review triggered.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6c3eb80 and 468bd1e.

Files selected for processing (4)
  • docs/api/middleware/keyauth.md (2 hunks)
  • middleware/keyauth/config.go (2 hunks)
  • middleware/keyauth/keyauth.go (7 hunks)
  • middleware/keyauth/keyauth_test.go (1 hunks)
Additional context used
LanguageTool
docs/api/middleware/keyauth.md

[uncategorized] ~7-~7: This expression is usually spelled with a hyphen. (BASED_HYPHEN)
Context: ...Keyauth Key auth middleware provides a key based authentication. ## Signatures ```go f...


[uncategorized] ~77-~77: The abbreviation “e.g.” (= for example) requires two periods. (E_G)
Context: ...of keyauth and apply a filter function (eg. authFilter) like so ```go package ma...

Markdownlint
docs/api/middleware/keyauth.md

21-21: Column: 1 (MD010, no-hard-tabs)
Hard tabs


22-22: Column: 1 (MD010, no-hard-tabs)
Hard tabs


23-23: Column: 1 (MD010, no-hard-tabs)
Hard tabs


24-24: Column: 1 (MD010, no-hard-tabs)
Hard tabs


28-28: Column: 1 (MD010, no-hard-tabs)
Hard tabs


32-32: Column: 1 (MD010, no-hard-tabs)
Hard tabs


33-33: Column: 1 (MD010, no-hard-tabs)
Hard tabs


35-35: Column: 1 (MD010, no-hard-tabs)
Hard tabs


36-36: Column: 1 (MD010, no-hard-tabs)
Hard tabs


37-37: Column: 1 (MD010, no-hard-tabs)
Hard tabs


38-38: Column: 1 (MD010, no-hard-tabs)
Hard tabs


42-42: Column: 1 (MD010, no-hard-tabs)
Hard tabs


44-44: Column: 1 (MD010, no-hard-tabs)
Hard tabs


45-45: Column: 1 (MD010, no-hard-tabs)
Hard tabs


46-46: Column: 1 (MD010, no-hard-tabs)
Hard tabs


47-47: Column: 1 (MD010, no-hard-tabs)
Hard tabs


48-48: Column: 1 (MD010, no-hard-tabs)
Hard tabs


50-50: Column: 1 (MD010, no-hard-tabs)
Hard tabs


51-51: Column: 1 (MD010, no-hard-tabs)
Hard tabs


52-52: Column: 1 (MD010, no-hard-tabs)
Hard tabs


54-54: Column: 1 (MD010, no-hard-tabs)
Hard tabs


83-83: Column: 1 (MD010, no-hard-tabs)
Hard tabs


84-84: Column: 1 (MD010, no-hard-tabs)
Hard tabs


85-85: Column: 1 (MD010, no-hard-tabs)
Hard tabs


86-86: Column: 1 (MD010, no-hard-tabs)
Hard tabs


87-87: Column: 1 (MD010, no-hard-tabs)
Hard tabs


88-88: Column: 1 (MD010, no-hard-tabs)
Hard tabs


92-92: Column: 1 (MD010, no-hard-tabs)
Hard tabs


93-93: Column: 1 (MD010, no-hard-tabs)
Hard tabs


94-94: Column: 1 (MD010, no-hard-tabs)
Hard tabs


95-95: Column: 1 (MD010, no-hard-tabs)
Hard tabs


96-96: Column: 1 (MD010, no-hard-tabs)
Hard tabs


100-100: Column: 1 (MD010, no-hard-tabs)
Hard tabs


101-101: Column: 1 (MD010, no-hard-tabs)
Hard tabs


103-103: Column: 1 (MD010, no-hard-tabs)
Hard tabs


104-104: Column: 1 (MD010, no-hard-tabs)
Hard tabs


105-105: Column: 1 (MD010, no-hard-tabs)
Hard tabs


106-106: Column: 1 (MD010, no-hard-tabs)
Hard tabs


110-110: Column: 1 (MD010, no-hard-tabs)
Hard tabs


112-112: Column: 1 (MD010, no-hard-tabs)
Hard tabs


113-113: Column: 1 (MD010, no-hard-tabs)
Hard tabs


114-114: Column: 1 (MD010, no-hard-tabs)
Hard tabs


115-115: Column: 1 (MD010, no-hard-tabs)
Hard tabs


116-116: Column: 1 (MD010, no-hard-tabs)
Hard tabs


117-117: Column: 1 (MD010, no-hard-tabs)
Hard tabs


121-121: Column: 1 (MD010, no-hard-tabs)
Hard tabs


123-123: Column: 1 (MD010, no-hard-tabs)
Hard tabs


124-124: Column: 1 (MD010, no-hard-tabs)
Hard tabs


125-125: Column: 1 (MD010, no-hard-tabs)
Hard tabs


126-126: Column: 1 (MD010, no-hard-tabs)
Hard tabs


127-127: Column: 1 (MD010, no-hard-tabs)
Hard tabs


129-129: Column: 1 (MD010, no-hard-tabs)
Hard tabs


130-130: Column: 1 (MD010, no-hard-tabs)
Hard tabs


131-131: Column: 1 (MD010, no-hard-tabs)
Hard tabs


132-132: Column: 1 (MD010, no-hard-tabs)
Hard tabs


133-133: Column: 1 (MD010, no-hard-tabs)
Hard tabs


134-134: Column: 1 (MD010, no-hard-tabs)
Hard tabs


135-135: Column: 1 (MD010, no-hard-tabs)
Hard tabs


136-136: Column: 1 (MD010, no-hard-tabs)
Hard tabs


137-137: Column: 1 (MD010, no-hard-tabs)
Hard tabs


139-139: Column: 1 (MD010, no-hard-tabs)
Hard tabs


165-165: Column: 1 (MD010, no-hard-tabs)
Hard tabs


166-166: Column: 1 (MD010, no-hard-tabs)
Hard tabs


167-167: Column: 1 (MD010, no-hard-tabs)
Hard tabs


168-168: Column: 1 (MD010, no-hard-tabs)
Hard tabs


176-176: Column: 1 (MD010, no-hard-tabs)
Hard tabs


178-178: Column: 1 (MD010, no-hard-tabs)
Hard tabs


179-179: Column: 1 (MD010, no-hard-tabs)
Hard tabs


180-180: Column: 1 (MD010, no-hard-tabs)
Hard tabs


181-181: Column: 1 (MD010, no-hard-tabs)
Hard tabs


183-183: Column: 1 (MD010, no-hard-tabs)
Hard tabs


184-184: Column: 1 (MD010, no-hard-tabs)
Hard tabs


185-185: Column: 1 (MD010, no-hard-tabs)
Hard tabs


186-186: Column: 1 (MD010, no-hard-tabs)
Hard tabs


187-187: Column: 1 (MD010, no-hard-tabs)
Hard tabs


188-188: Column: 1 (MD010, no-hard-tabs)
Hard tabs


190-190: Column: 1 (MD010, no-hard-tabs)
Hard tabs


191-191: Column: 1 (MD010, no-hard-tabs)
Hard tabs


192-192: Column: 1 (MD010, no-hard-tabs)
Hard tabs


194-194: Column: 1 (MD010, no-hard-tabs)
Hard tabs


195-195: Column: 1 (MD010, no-hard-tabs)
Hard tabs


196-196: Column: 1 (MD010, no-hard-tabs)
Hard tabs


198-198: Column: 1 (MD010, no-hard-tabs)
Hard tabs


231-231: Column: 1 (MD010, no-hard-tabs)
Hard tabs


232-232: Column: 1 (MD010, no-hard-tabs)
Hard tabs


233-233: Column: 1 (MD010, no-hard-tabs)
Hard tabs


234-234: Column: 1 (MD010, no-hard-tabs)
Hard tabs


235-235: Column: 1 (MD010, no-hard-tabs)
Hard tabs


236-236: Column: 1 (MD010, no-hard-tabs)
Hard tabs


237-237: Column: 1 (MD010, no-hard-tabs)
Hard tabs


238-238: Column: 1 (MD010, no-hard-tabs)
Hard tabs


239-239: Column: 1 (MD010, no-hard-tabs)
Hard tabs


240-240: Column: 1 (MD010, no-hard-tabs)
Hard tabs


241-241: Column: 1 (MD010, no-hard-tabs)
Hard tabs


242-242: Column: 1 (MD010, no-hard-tabs)
Hard tabs


243-243: Column: 1 (MD010, no-hard-tabs)
Hard tabs


74-74: Expected: 1; Actual: 2 (MD012, no-multiple-blanks)
Multiple consecutive blank lines

Additional comments not posted (7)
middleware/keyauth/config.go (2)

35-37: Added FallbackKeyLookups to handle multiple key sources.

This addition aligns with the PR's objective to enhance key extraction flexibility. Ensure that the documentation and usage examples are updated accordingly to reflect this new capability.


91-93: Ensure default value for FallbackKeyLookups is an empty slice.

This default setting prevents any unintended behavior when this field is not explicitly configured by the user.

middleware/keyauth/keyauth.go (3)

23-23: Introduced extractorFunc type for key extraction functions.

This type definition helps in maintaining a clean and understandable code structure by abstracting the function signature.


32-56: Enhanced New function to handle multiple key sources.

The implementation correctly initializes and manages multiple extractors based on the configuration. The use of a map and a loop to handle fallbacks is efficient and clear.


82-99: Refactored key extraction into parseSingleExtractor.

This function simplifies the process of setting up key extractors based on the KeyLookup configuration. The error handling and switch-case structure are appropriately used.

docs/api/middleware/keyauth.md (1)

222-222: Updated documentation to include FallbackKeyLookups.

The documentation correctly describes the new configuration option, enhancing the understanding of the middleware's capabilities.

middleware/keyauth/keyauth_test.go (1)

134-178: Added TestMultipleKeyLookup to verify multiple key lookup functionality.

This test effectively checks the functionality of extracting keys from multiple sources, ensuring that the middleware behaves as expected under different configurations.

@gaby gaby changed the title 🔥 Feature: enhance keyauth middleware to handle multiple keyExtractors in a simple way 🔥 Feature: KeyAuth Middleware add support for multiple keys Jun 9, 2024
@gaby
Copy link
Member

gaby commented Jun 9, 2024

@dave-gray101 I just realized this is on the v2 branch, we are not adding any new features for v2. The target branch would have to be changed to v3

@gaby gaby changed the title 🔥 Feature: KeyAuth Middleware add support for multiple keys 🔥 Feature: Add support for multiple keys in the KeyAuth middleware Jun 9, 2024
@dave-gray101
Copy link
Contributor Author

dave-gray101 commented Jun 9, 2024

@dave-gray101 I just realized this is on the v2 branch, we are not adding any new features for v2. The target branch would have to be changed to v3

Ah, that's unfortunate. I had dropped a question in the discord a few days ago regarding that, and didn't get a reply and figured I'd just create it rather than wait :D

I based this branch off of v2, mostly as a guess. I'll try changing the target here, but it may be cleaner to re-apply off v3.

Edit: It's a huge mess due to the age of the source branch. I'll create a new one based on main and link it below.

@dave-gray101 dave-gray101 changed the base branch from v2 to v3-alpha June 9, 2024 20:35
@dave-gray101 dave-gray101 changed the base branch from v3-alpha to v2 June 9, 2024 20:35
@dave-gray101 dave-gray101 changed the base branch from v2 to main June 9, 2024 21:08
@dave-gray101 dave-gray101 requested a review from a team as a code owner June 9, 2024 21:08
@dave-gray101 dave-gray101 requested review from sixcolors and ReneWerner87 and removed request for a team June 9, 2024 21:08
@dave-gray101 dave-gray101 requested a review from efectn June 9, 2024 21:08
@dave-gray101 dave-gray101 changed the base branch from main to v2 June 9, 2024 21:08
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