-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
178 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as jose from 'jose' | ||
|
||
const alg = 'ES256' | ||
// const options = { | ||
// issuer: "urn:example:issuer", | ||
// audience: "urn:example:audience", | ||
// }; | ||
const keys = await jose.generateKeyPair(alg, { extractable: true }) | ||
const keys2 = await jose.generateKeyPair(alg, { extractable: true }) | ||
// const keys3 = await jose.generateKeyPair(alg, { extractable: true }); | ||
|
||
const jwk1 = await jose.exportJWK(keys.publicKey).then((jwk) => { | ||
jwk.kid = 'key1' | ||
|
||
return jwk | ||
}) | ||
|
||
const jwk2 = await jose.exportJWK(keys2.publicKey).then((jwk) => { | ||
jwk.kid = 'key2' | ||
|
||
return jwk | ||
}) | ||
|
||
// const jwk3 = await jose.exportJWK(keys3.publicKey).then((jwk) => { | ||
// jwk.kid = "key3"; | ||
// return jwk; | ||
// }); | ||
|
||
export const jwks = jose.createLocalJWKSet({ keys: [jwk1, jwk2] }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as jose from 'jose' | ||
|
||
export const alg = 'ES256' | ||
|
||
export const serverKeys = await jose.generateKeyPair(alg, { extractable: true }) | ||
export const userKeys1 = await jose.generateKeyPair(alg, { extractable: true }) | ||
export const userKeys3 = await jose.generateKeyPair(alg, { extractable: true }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as jose from 'jose' | ||
|
||
const alg = 'ES256' | ||
|
||
const keys = await jose.generateKeyPair(alg, { extractable: true }) | ||
const keys2 = await jose.generateKeyPair(alg, { extractable: true }) | ||
|
||
console.log('keys\n', await jose.exportPKCS8(keys.privateKey)) | ||
console.log('keys2\n', await jose.exportPKCS8(keys2.privateKey)) | ||
|
||
const jwt = await new jose.GeneralSign( | ||
new TextEncoder().encode('Hello, World!'), | ||
) | ||
.addSignature(keys.privateKey) | ||
.setProtectedHeader({ alg, b64: true }) | ||
.addSignature(keys2.privateKey) | ||
.setProtectedHeader({ alg, b64: true }) | ||
.sign() | ||
|
||
console.log('jwt', jwt) | ||
|
||
const { payload, protectedHeader } = await jose.generalVerify( | ||
jwt, | ||
keys2.publicKey, | ||
) | ||
|
||
console.log(protectedHeader) | ||
console.log(new TextDecoder().decode(payload)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import * as jose from 'jose' | ||
|
||
const alg = 'ES256' | ||
const options = { | ||
issuer: 'urn:example:issuer', | ||
audience: 'urn:example:audience', | ||
} | ||
|
||
const keys = await jose.generateKeyPair(alg, { extractable: true }) | ||
const keys2 = await jose.generateKeyPair(alg, { extractable: true }) | ||
// const keys3 = await jose.generateKeyPair(alg, { extractable: true }); | ||
|
||
const jwk1 = await jose.exportJWK(keys.publicKey).then((jwk) => { | ||
jwk.kid = 'key1' | ||
|
||
return jwk | ||
}) | ||
|
||
const jwk2 = await jose.exportJWK(keys2.publicKey).then((jwk) => { | ||
jwk.kid = 'key2' | ||
|
||
return jwk | ||
}) | ||
|
||
// const jwk3 = await jose.exportJWK(keys3.publicKey).then((jwk) => { | ||
// jwk.kid = "key3"; | ||
// return jwk; | ||
// }); | ||
|
||
const jwks = jose.createLocalJWKSet({ keys: [jwk1, jwk2] }) | ||
|
||
console.log('keys\n', await jose.exportPKCS8(keys.privateKey)) | ||
console.log('keys2\n', await jose.exportPKCS8(keys2.privateKey)) | ||
|
||
const jwt = await new jose.SignJWT({ | ||
foo: 'bar', | ||
}) | ||
.setIssuer(options.issuer) | ||
.setAudience(options.audience) | ||
.setProtectedHeader({ alg, kid: 'key1' }) | ||
.setExpirationTime('10m') | ||
.setIssuedAt() | ||
.sign(keys.privateKey) | ||
|
||
console.log('jwt', jwt) | ||
|
||
const { payload, protectedHeader } = await jose | ||
.jwtVerify(jwt, jwks, options) | ||
|
||
console.log(protectedHeader) | ||
console.log(payload) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters