-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
experimental
- Loading branch information
Showing
16 changed files
with
535 additions
and
509 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1 @@ | ||
export * as base64url from "https://deno.land/[email protected]/encoding/base64url.ts"; | ||
export { | ||
decodeString as convertHexToUint8Array, | ||
encodeToString as convertUint8ArrayToHex, | ||
} from "https://deno.land/[email protected]/encoding/hex.ts"; | ||
export { HmacSha256 } from "https://deno.land/[email protected]/hash/sha256.ts"; | ||
export { HmacSha512 } from "https://deno.land/[email protected]/hash/sha512.ts"; | ||
export { RSA } from "https://deno.land/x/[email protected]/rsa.ts"; | ||
export * as base64url from "https://deno.land/[email protected]/encoding/base64url.ts"; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1 @@ | ||
export { serve } from "https://deno.land/[email protected]/http/server.ts"; | ||
export { decode, encode } from "https://deno.land/[email protected]/encoding/utf8.ts"; | ||
export { dirname, fromFileUrl } from "https://deno.land/[email protected]/path/mod.ts"; | ||
export { serve } from "https://deno.land/[email protected]/http/server.ts"; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,41 @@ | ||
import { create, verify } from "../mod.ts"; | ||
import { dirname, fromFileUrl, serve } from "./example_deps.ts"; | ||
import { serve } from "./example_deps.ts"; | ||
|
||
import type { Header, Payload } from "../mod.ts"; | ||
|
||
const moduleDir = dirname(fromFileUrl(import.meta.url)); | ||
const publicKey = await Deno.readTextFile(moduleDir + "/certs/public.pem"); | ||
const privateKey = await Deno.readTextFile(moduleDir + "/certs/private.pem"); | ||
const key = await window.crypto.subtle.generateKey( | ||
{ | ||
name: "RSASSA-PKCS1-v1_5", | ||
modulusLength: 4096, | ||
publicExponent: new Uint8Array([1, 0, 1]), | ||
hash: "SHA-384", | ||
}, | ||
true, | ||
["verify", "sign"], | ||
); | ||
|
||
const payload: Payload = { | ||
sub: "1234567890", | ||
name: "John Doe", | ||
admin: true, | ||
iat: 1516239022, | ||
}; | ||
const header: Header = { | ||
alg: "RS256", | ||
alg: "RS384", | ||
typ: "JWT", | ||
}; | ||
|
||
console.log("server is listening at 0.0.0.0:8000"); | ||
for await (const req of serve("0.0.0.0:8000")) { | ||
if (req.method === "GET") { | ||
req.respond({ body: (await create(header, payload, privateKey)) + "\n" }); | ||
req.respond({ | ||
body: (await create(header, payload, key.privateKey)) + "\n", | ||
}); | ||
} else { | ||
const jwt = new TextDecoder().decode(await Deno.readAll(req.body)); | ||
await verify(jwt, publicKey, "RS256").then(() => | ||
await verify(jwt, key.publicKey).then(() => | ||
req.respond({ body: "Valid JWT\n" }) | ||
).catch(() => req.respond({ body: "Invalid JWT\n", status: 401 })); | ||
) | ||
.catch(() => req.respond({ body: "Invalid JWT\n", status: 401 })); | ||
} | ||
} |
Oops, something went wrong.