Skip to content

Conversation

@mikyll
Copy link
Contributor

@mikyll mikyll commented May 23, 2024

Description

New feature:

  • Added a new configuration parameter to the schema: key_claim_name (default = "key"), so for example one could use "iss" to check the validity of the JWT;

(similar behaviour to Kong JWT plugin)

Fixes #11276

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

Features:
- config param "key_claim_name" (default = "key"), so for example one could use "iss" to check the validity of the JWT;

Style:
- 2 blank lines between functions;
- 1 blank like before "else" and "elseif";
- jwt -> JWT;
- Capitalized logs and response messages;
- Added description for each schema configuration parameter;
@mikyll mikyll changed the title Fix #11276 + Little style refactor feat(jwt-auth): Fix #11276 + Little style refactor May 23, 2024
@mikyll mikyll marked this pull request as ready for review May 23, 2024 14:50
Copy link
Contributor

@shreemaan-abhishek shreemaan-abhishek left a comment

Choose a reason for hiding this comment

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

Please remove the style changes and add test cases to support your fix. Thanks.

@mikyll
Copy link
Contributor Author

mikyll commented May 29, 2024

@shreemaan-abhishek thank you for the feedback. I understand the importance of keeping PRs focused, but I made the style changes to align with the code_style guide. Could you please clarify if:

  • the style changes should be reverted entirely, despite the guidelines?
  • generally speaking, you prefer these style changes to be submitted as a separate PR, or not be carried out at all?

Anyways, I'll be happy to add the necessary test cases, as soon as possible :-)

flearc and others added 7 commits May 30, 2024 10:00
Co-authored-by: Navendu Pottekkat <[email protected]>
Co-authored-by: Abhishek Choudhary <[email protected]>
I added a new test case for feature #11276

Since the default value of the new config parameter "key_claim_name" is "key", "default behaviour" is already validated by other tests.
@mikyll mikyll changed the title feat(jwt-auth): Fix #11276 + Little style refactor feat(jwt-auth): Fix #11276 Jun 4, 2024
+ Removed external httpbin upstream in favor of local endpoint (/hello);
+ Cleaned code;
@mikyll
Copy link
Contributor Author

mikyll commented Jun 4, 2024

@shreemaan-abhishek
I did the following:

@github-actions
Copy link

This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 4 weeks if no further activity occurs. If you think that's incorrect or this pull request should instead be reviewed, please simply write any comment. Even if closed, you can still revive the PR at any time or discuss it on the [email protected] list. Thank you for your contributions.

@github-actions github-actions bot added the stale label Aug 16, 2024
@mikyll
Copy link
Contributor Author

mikyll commented Sep 13, 2024

Hello, any news on this PR?

@github-actions github-actions bot removed the stale label Sep 14, 2024
local function get_real_payload(key, auth_conf, payload, key_claim_name)
local real_payload = {
key = key,
[key_claim_name] = key,
Copy link
Contributor

Choose a reason for hiding this comment

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

although the key_claim_name has changed, the value of key_claim_name will always be key. That doesn't fit into the scene. For example, if the key_claim_name is exp then the value should be the expiry time, not the key. Right?

Copy link
Contributor Author

@mikyll mikyll Sep 22, 2024

Choose a reason for hiding this comment

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

@shreemaan-abhishek I'm not sure if I understood your comment correctly, in case I didn't please correct me :)


The purpose of key_claim_name parameter is just to tell in which claim the key is stored, so that the plugin can use this for the validation. For example, the company where I work uses JWTs which do not include the key claim, but do include iss instead.

The reason why I also made changes to get_real_payload() and the like, was to provide a way to generate a signed token with a custom key claim name, through the public API (otherwise I would have needed to make a test case with a hardcoded token, see line 182 of commit 2af7e156aa07ca29cf19f4934daa605eb0571902 for reference).

Addressing your comment, if key_claim_name was "exp", then no, the value shouldn't be the expiry time, but still the key. However, that would cause some problem:

  • even though according to JWT standard, RFC 7519, the exp claim is optional, the jwt-auth plugin requires it to validate the token, and returns 401 if it's not present (at this line):
    [warn] 64#64: *16957 [lua] jwt-auth.lua:442: phase_func(): failed to verify jwt: Missing one of claims - [ nbf, exp ].,
  • setting key_claim_name to "exp" is not feasible, since that would generate a token with duplicated exp claim.

At most, we could handle this case by preventing the usage of "exp" and "nbf" as key_claim_name, what do you think?

@shreemaan-abhishek
Copy link
Contributor

@mikyll, please rebase with master there have been some changes in the CI.

@shreemaan-abhishek shreemaan-abhishek changed the title feat(jwt-auth): Fix #11276 feat(jwt-auth): support configuring key_claim_name Sep 20, 2024
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Sep 20, 2024
Features:
- config param "key_claim_name" (default = "key"), so for example one could use "iss" to check the validity of the JWT;

Style:
- 2 blank lines between functions;
- 1 blank like before "else" and "elseif";
- jwt -> JWT;
- Capitalized logs and response messages;
- Added description for each schema configuration parameter;
I added a new test case for feature #11276

Since the default value of the new config parameter "key_claim_name" is "key", "default behaviour" is already validated by other tests.
+ Removed external httpbin upstream in favor of local endpoint (/hello);
+ Cleaned code;
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Sep 22, 2024
@mikyll
Copy link
Contributor Author

mikyll commented Sep 22, 2024

@shreemaan-abhishek I've done the rebase with master, and I also left a reply to your comment.

Possible enhancements for that get_real_payload() concern, that come to my mind are:

  • (simplest one) reverting the changes to the public API and make a test case for the key_claim_name scenario that just uses a hardcoded token, without generating it with the public API;
  • preventing the usage of exp and nbf claims as values for the key_claim_name query parameter in the public API (e.g. calls to apisix_host:9180/apisix/plugin/jwt/sign?key=custom-user-key&key_claim_name=exp would return an error, such as "400: cannot use 'exp' or 'nbf' as key_claim_name");

@github-actions
Copy link

This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 4 weeks if no further activity occurs. If you think that's incorrect or this pull request should instead be reviewed, please simply write any comment. Even if closed, you can still revive the PR at any time or discuss it on the [email protected] list. Thank you for your contributions.

@github-actions github-actions bot added the stale label Nov 22, 2024
@mikyll
Copy link
Contributor Author

mikyll commented Nov 22, 2024

Closing this since it's outdated and is being implemented in #11772 👀

@mikyll mikyll closed this Nov 22, 2024
@mikyll mikyll deleted the jwt_key_claim_name branch March 6, 2025 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files. stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: As a user, I want to use "iss" JWT claim, so that I can verify my Apisix Consumers with a claim different than "key"