Comments (10)
Does it work if you create a key only once in the deployed app?
from djwt.
The Web Crypto API has methods for importing and exporting keys (see the mdn web docs for more info)
- Generate a key
const key = await crypto.subtle.generateKey(
{ name: "HMAC", hash: "SHA-512" },
true,
["sign", "verify"],
);
- Create a JWT
const jwt = await create({ alg: "HS512", typ: "JWT" }, { foo: "bar" }, key);
- Export the key
E.g. write this to a file which you can read later on— it's up to you how you persist this file, depending on your project.
let exportedKey = await crypto.subtle.exportKey("jwk", key)
- Reimport the key and confirm everything works
let reimportedKey = await crypto.subtle.importKey(
"jwk",
exportedKey,
{ name: "HMAC", hash: "SHA-512" }, true, ["sign", "verify"]);
// Confirm everything works as expected
console.log(await verify(jwt, reimportedKey))
// {foo: 'bar'}
from djwt.
Does it not work if you create a key only once in the whole deployed app?
Yes, I exported it in a file (jwt_key.ts):
export const jwtKey = await crypto.subtle.generateKey(
{ name: "HMAC", hash: "SHA-512" },
true,
["sign", "verify"],
);
from djwt.
The Web Crypto API has methods for importing and exporting keys (see the mdn web docs for more info)
- Generate a key
const key = await crypto.subtle.generateKey( { name: "HMAC", hash: "SHA-512" }, true, ["sign", "verify"], );
- Create a JWT
const jwt = await create({ alg: "HS512", typ: "JWT" }, { foo: "bar" }, key);
- Export the key
E.g. write this to a file which you can read later on— it's up to you how you persist this file, depending on your project.let exportedKey = await crypto.subtle.exportKey("jwk", key)
- Reimport the key and confirm everything works
let reimportedKey = await crypto.subtle.importKey( "jwk", exportedKey, { name: "HMAC", hash: "SHA-512" }, true, ["sign", "verify"]); // Confirm everything works as expected console.log(await verify(jwt, reimportedKey)) // {foo: 'bar'}
thank you for your reply! However, how should I implement this?
from djwt.
兄弟,找到解决办法没
from djwt.
兄弟,找到解决办法没
没呢
目前我的办法是 将JSON化后的JWT Key硬编码在环境变量里()
from djwt.
Please talk in English guys!
@so1ve wouldn't you agree that this a deno.com issue and not a djwt issue, if at all? Although, it might be that I have not fully understood the problem yet.
from djwt.
I'm so sorry...it's actually a deno.com issue. denoland/deploy_feedback#237
from djwt.
Oh no problem at all. I was rather curious what the problem was. Thank you!
from djwt.
I think this is caused by Deno Deploy being deployed on the edge server, which causes my program to run from scratch every time (including the part that generates the key).
from djwt.
Related Issues (20)
- How to use Cert files HOT 6
- Feature Request: Support JSON Web Key Sets (JWKS) HOT 3
- mod.ts missing on deno.land HOT 4
- Verify Web Token Crypto from a different file (middleware) HOT 1
- There's no permanent key available. HOT 13
- need some real world examples HOT 7
- Cannot find name 'HmacKeyAlgorithm' HOT 3
- Expected comma with deno bundle (GitHub Actions) HOT 3
- Argument of type '"jwk"' is not assignable to parameter of type '"raw" | "pkcs8" | "spki". in Deno v1.18.1 HOT 2
- Verify fail HOT 1
- exp/nbf leeway should be configurable HOT 4
- Node or browser version? HOT 2
- Moving to JavaScript with JSDoc? HOT 2
- The jwt's signature does not match the verification signature. HOT 4
- Cannot verify token/secret which verifies successfully using Node HOT 3
- Cannot create token Uncaught TypeError: Cannot read properties of undefined (reading 'name') HOT 1
- How to safe the CryptoKey for the djwt HOT 1
- Can you publish djwt to npmjs ? HOT 4
- can create but not validate a JWT with a non-object payload HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from djwt.