-
-
Notifications
You must be signed in to change notification settings - Fork 579
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(jwt): jwt middleware #169
Conversation
Hi @metrue, thank you for PR. I have two suggestions:
|
Hi @yusukebe
We may not be able to use utils/crypto.ts directly, since JWT encodes the header and payload with base64url which is a bit difference with base64.
I think we could do that, although I haven't thought of a use case now. |
I see. First, as much as possible, I want you to use base64 in Second,
Methods in import { encodeBase64, decodeBase64 } from 'hono/utils/crypto' Or we can use methods for Cloudflare Workers. import { getContentFromKVAsset } from 'hono/utils/cloudflare' So, if methods for JWT are placed under the app.post('/login', (c) => {
const username = c.req.parsedBody.username
const password = c.req.parsedBody.password
if (isOK(username, password)) {
const token = JWT.sign({ username: username }, secret)
res.json({
token: token,
})
}else {
//...
}
}) These are my thoughts. What do you think? |
Good points, @yusukebe . Hono's not only designed for Cloudflare Worker, but also for Fastly Compute@Edge, it's important to make the codes compatible for both of them as much as possible. I will refactor the codes. |
Great! Thank you! |
@yusukebe The fact that Hono provides a sign method should be documented somewhere! Saved me from installing a package like |
Hi @julianpoma Are you referring to the But, most APIs within the utils are stable, so it might not be a bad idea to consider exporting methods from |
Exactly @yusukebe. I am doing an API server and I need to issue JWTokens, not just verify them. Understood that this methods could change without notice, I can live with that :) I think it's worth considering exposing a small set of helpers to handle JWTs - |
This is a awesome idea! Could you create the issue for the helpers as a feature request? Thanks! |
This MR is to add JWT middleware to hono.
Close #168