-
Notifications
You must be signed in to change notification settings - Fork 39
Chore/Upgrade packages #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
IDisposable
wants to merge
1
commit into
jetkvm:dev
Choose a base branch
from
IDisposable:chore/packages
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,293
−1,706
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,37 +1,50 @@ | ||
| import { type NextFunction, type Request, type Response } from "express"; | ||
| import * as jose from "jose"; | ||
| import { UnauthorizedError } from "./errors"; | ||
|
|
||
| import { BadRequestError, UnauthorizedError } from "./errors"; | ||
|
|
||
| const JWKS_URL = new URL("https://www.googleapis.com/oauth2/v3/certs") | ||
| const JWKS = jose.createRemoteJWKSet(JWKS_URL); | ||
| const verificationOptions = { | ||
| //algorithms: ['RS256'], | ||
| issuer: "https://accounts.google.com", | ||
| audience: process.env.GOOGLE_CLIENT_ID, | ||
| }; | ||
|
|
||
| export const verifyToken = async (idToken: string) => { | ||
| const JWKS = jose.createRemoteJWKSet( | ||
| new URL("https://www.googleapis.com/oauth2/v3/certs"), | ||
| ); | ||
|
|
||
| try { | ||
| const { payload } = await jose.jwtVerify(idToken, JWKS, { | ||
| issuer: "https://accounts.google.com", | ||
| audience: process.env.GOOGLE_CLIENT_ID, | ||
| }); | ||
|
|
||
| const { payload } = await jose.jwtVerify(idToken, JWKS, verificationOptions); | ||
| console.log('JWT Payload:', payload); | ||
| return payload; | ||
| } catch (e) { | ||
| console.error(e); | ||
| } catch (error: any) { | ||
| console.error('JWT Verification Failed:', error.message); | ||
| return null; | ||
| } | ||
| }; | ||
|
|
||
| export const authenticated = async (req: Request, res: Response, next: NextFunction) => { | ||
| const idToken = req.session?.id_token; | ||
| if (!idToken) throw new UnauthorizedError(); | ||
| const session = req.session; | ||
| if (!session) throw new UnauthorizedError("No session found"); | ||
|
|
||
| const idToken = session.id_token; | ||
| if (!idToken) throw new UnauthorizedError("No ID token found in session"); | ||
|
|
||
| const payload = await verifyToken(idToken); | ||
| if (!payload) throw new UnauthorizedError(); | ||
| if (!payload.exp) throw new UnauthorizedError(); | ||
| if (!payload) throw new UnauthorizedError("Invalid ID token"); | ||
|
|
||
| if (new Date(payload.exp * 1000) < new Date()) { | ||
| throw new UnauthorizedError(); | ||
| const { sub, iss, exp } = payload; | ||
| if (!sub) throw new UnauthorizedError("Missing sub (subject) in token"); | ||
| if (!iss) throw new UnauthorizedError("Missing iss (issuer) in token"); | ||
| if (!exp) throw new UnauthorizedError("Missing exp (expiration) in token"); | ||
|
|
||
| if (new Date(payload.exp! * 1000) < new Date()) { | ||
| throw new UnauthorizedError("ID token has expired"); | ||
| } | ||
|
|
||
| const isGoogle = iss === "https://accounts.google.com"; | ||
| if (!isGoogle) throw new BadRequestError("Token is not from Google"); | ||
|
|
||
| req.subject = sub; | ||
| req.issuer = iss; | ||
|
|
||
| next(); | ||
| }; | ||
| }; | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example shows S256 but really should be RS256... until I can test I can't be sure which is right.