Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
shlok-007 committed Jul 22, 2024
2 parents 494081a + 21e9e5e commit 348c088
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 30 deletions.
10 changes: 5 additions & 5 deletions client/package-lock.json

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

8 changes: 4 additions & 4 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
"author": "Shlok Kumar Shaw",
"private": true,
"dependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@react-oauth/google": "^0.11.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^27.5.2",
"@types/node": "^16.18.34",
"@types/react": "^18.2.7",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.2.4",
"@vercel/analytics": "^1.2.2",
"react": "^18.2.0",
"react": "^18.3.1",
"react-dom": "^18.2.0",
"react-ga4": "^2.1.0",
"react-query": "^3.39.3",
"react-router-dom": "^6.12.1",
"react-scripts": "5.0.1",
"typescript": "^4.9.5",
"universal-cookie": "^7.1.4",
"web-vitals": "^2.1.4",
"@babel/plugin-proposal-private-property-in-object": "^7.21.11"
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
Expand Down
8 changes: 7 additions & 1 deletion client/src/components/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
// }

// Toast.tsx

/// <reference types="react/canary" />

import React, { useEffect } from 'react';
import '../styles/toastStyle.css';

Expand All @@ -45,7 +48,10 @@ const Toast: React.FC<ToastProps> = ({ message, duration, onClose }) => {
}, [duration, onClose]);

return (
<div className="popup">{message}</div>
<div className="popup"
// popover="auto"

>{message}</div>
);
};

Expand Down
61 changes: 41 additions & 20 deletions server/verifyOAuthJWT.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,26 @@ import { fetchOAuthJWKs } from "./cronFetchOAuthJWKs.js";

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 readJWKFile = async () => {
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"));
}
};

await readJWKFile();

fs.watch("./jwk.json", async (eventType, filename) => {
if (eventType === "change") {
console.log("jwk.json file has been updated. Reloading...");
await readJWKFile();
}
});


const verifyOAuthJWT = async (oauthJWT) => {
const body = JSON.parse(Buffer.from(oauthJWT.split(".")[1], "base64").toString());
Expand All @@ -22,18 +34,27 @@ const verifyOAuthJWT = async (oauthJWT) => {
// console.log(jws.verify(oauthJWT, jwk));

if( body.aud === process.env.OAUTH_CLIENT_ID &&
body.iss === 'https://accounts.google.com' &&
jws.verify(oauthJWT, jwk) ){

// console.log("JWT verified");
let userData = {
email: body.email,
name: body.name,
picture: body.picture,
sub: body.sub,
given_name: body.given_name
};
return userData;
body.iss === 'https://accounts.google.com'
// && jws.verify(oauthJWT, jwk)
){
try{
jws.verify(oauthJWT, jwk);
// console.log("JWT verified");
let userData = {
email: body.email,
name: body.name,
picture: body.picture,
sub: body.sub,
given_name: body.given_name
};
return userData;
}
catch(e){
console.log("JWT verification failed");
await fetchOAuthJWKs();
return false;
}

}

return false;
Expand Down

0 comments on commit 348c088

Please sign in to comment.