Skip to content

Commit

Permalink
added fallback for jwk.json not available
Browse files Browse the repository at this point in the history
  • Loading branch information
shlok-007 committed Jun 7, 2024
1 parent b400dba commit 7f54f37
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
5 changes: 1 addition & 4 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/cronFetchOAuthJWKs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import cron from "node-cron";
import fs from 'fs';


const fetchOAuthJWKs = async () => {
export const fetchOAuthJWKs = async () => {
console.log('Fetching OAuth JWKs');
const result = await fetch(`https://accounts.google.com/.well-known/openid-configuration`, {
method: 'GET',
Expand Down
12 changes: 11 additions & 1 deletion server/verifyOAuthJWT.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import jws from "jws-jwk";
import fs from "fs";
import { fetchOAuthJWKs } from "./cronFetchOAuthJWKs.js";

const jwk = JSON.parse(fs.readFileSync("./jwk.json", "utf8"));
let jwk = {};

try{
jwk = JSON.parse(fs.readFileSync("./jwk.json", "utf8"));
}catch(e){
console.log("Error reading jwk.json");
// console.log(e);
await fetchOAuthJWKs();
jwk = JSON.parse(fs.readFileSync("./jwk.json", "utf8"));
}

const verifyOAuthJWT = async (oauthJWT) => {
const body = JSON.parse(Buffer.from(oauthJWT.split(".")[1], "base64").toString());
Expand Down

0 comments on commit 7f54f37

Please sign in to comment.