-
-
Notifications
You must be signed in to change notification settings - Fork 739
feat(hono/jwk): Extended with allow_anon
option & passing Context
to callbacks
#3961
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
Conversation
…_token` option One slightly breaking change: Removed function callbacks from `Jwt.verifyFromJwks` for two reasons: 1. It’s always called from functions, so `jwks_uri`/`keys` can be grabbed before calling `Jwt.verifyFromJwks` anyways 2. Jwt.verifyFromJwks cannot provide the Context to the new callbacks—only the middleware can Callbacks now also accept either a Promise or a synchronous function, not only async.
… more precise tsdoc
Hmm, I don't think that Deno error is caused by my PR as I was so sure I pulled from the upstream, but I will attempt to fix it. Edit: Turns out nope; I accidentally overridden the upstream change of that |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## next #3961 +/- ##
==========================================
+ Coverage 91.32% 91.33% +0.01%
==========================================
Files 168 168
Lines 10688 10692 +4
Branches 3070 3059 -11
==========================================
+ Hits 9761 9766 +5
+ Misses 926 925 -1
Partials 1 1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Looks very promising, thank you a lot for your prompt contribution, wise person across the world! 👌 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Sorry for being late. It looks good! I'll merge this later into the next branch for the next minor version and release it. Thanks! |
Adding two main useful features people have been asking for in the original PR + some slight changes.
New features:
allow_anon
option totrue
jwks_uri
instead of only a hard-coded stringContext
is now included in all callbacks, so you can e.g pull information fromc.env
such as auth serverExample:
Note 1: This PR allows having a single endpoint for both authenticated and non-authenticated requests through
allow_anon
. The variablec.get("jwtPayload")
can be used to differentiate authenticated requests from anonymous requests since hono requires requests to haveexp
andiat
in the payload (in theverify
stage) which means the payload would always be defined for authenticated requests and be reliably used as indicator.Note 2: Setting
allow_anon
totrue
means requests without a token present (in either header/cookie) would be allowed to pass through the middleware successfully.Tests: Added 3 extra tests + modified one test to cover
jwks_uri
being a function.This PR breaks no code at all except for
Jwt.verifyFromJwks(...)
—specifically removed callbacks support from it since they're redundant and can be called outside, and also since only the middleware can provide theContext
variable to the callbacks.