-
Notifications
You must be signed in to change notification settings - Fork 10
feat: add pkce-like session binding and remove nonce impl #525
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
zhongliang02
wants to merge
13
commits into
main
Choose a base branch
from
feat/add-pkce-like-session-binding
base: main
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.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3e1593f
feat: add pkce-like session binding and remove nonce impl
zhongliang02 0a00391
fix: clear verifier map after successful login to minimise memory use
zhongliang02 bb2198e
fix: wrong prisma error code for duplicate codeChallenge
zhongliang02 fc71afd
fix: use toBe instead of equals in tests
zhongliang02 95022fc
chore: linting/formatting
zhongliang02 0dc2c30
fix: improve auth validator error message
zhongliang02 fd5f6ff
fix: comment english
zhongliang02 7a0f6b7
chore: formatting
zhongliang02 7545659
fix: remove incorrect test
zhongliang02 d5dad87
feat: format fix
karrui 35964f3
fix(test): import from correct director
karrui c5c5882
feat: split browser and serverside pkce generators
zhongliang02 f19c1e9
Merge branch 'main' into feat/add-pkce-like-session-binding
zhongliang02 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
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 |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { pkceVerifierGenerator } from '~/lib/pkce/pkce' | ||
|
|
||
| // This file hosts functions pertaining to PKCE (Proof Key for Code Exchange) as per RFC 7636 | ||
| // If you need to understand PKCE, read https://datatracker.ietf.org/doc/html/rfc7636 | ||
| // Do not use this for actual OAuth flows, please use a tested library instead. | ||
|
|
||
| // We need to split up server and browser implementations due to using crypto APIs | ||
|
|
||
| export function browserCreatePkceVerifier(): string { | ||
| return pkceVerifierGenerator() | ||
| } | ||
|
|
||
| export async function browserCreatePkceChallenge( | ||
| codeVerifier: string, | ||
| ): Promise<string> { | ||
| const encoder = new TextEncoder() | ||
| const data = encoder.encode(codeVerifier) | ||
| const hashBuffer = await window.crypto.subtle.digest('SHA-256', data) | ||
|
|
||
| const hashArray = Array.from(new Uint8Array(hashBuffer)) | ||
| const base64 = btoa(String.fromCharCode(...hashArray)) | ||
|
|
||
| return base64.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_') | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { customAlphabet } from 'nanoid' | ||
|
|
||
| import { PKCE_LENGTH, PKCE_VERIFIER_ALPHABET } from '~/validators/auth' | ||
|
|
||
| export const pkceVerifierGenerator = customAlphabet( | ||
| PKCE_VERIFIER_ALPHABET, | ||
| PKCE_LENGTH, | ||
| ) |
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 |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { createHash } from 'crypto' | ||
|
|
||
| import { pkceVerifierGenerator } from '~/lib/pkce/pkce' | ||
|
|
||
| // This file hosts functions pertaining to PKCE (Proof Key for Code Exchange) as per RFC 7636 | ||
| // If you need to understand PKCE, read https://datatracker.ietf.org/doc/html/rfc7636 | ||
| // Do not use this for actual OAuth flows, please use a tested library instead. | ||
|
|
||
| // We need to split up server and browser implementations due to using crypto APIs | ||
|
|
||
| export function ssCreatePkceVerifier(): string { | ||
| return pkceVerifierGenerator() | ||
| } | ||
|
|
||
| export function ssCreatePkceChallenge(codeVerifier: string): string { | ||
| return createHash('sha256').update(codeVerifier).digest('base64url') | ||
| } |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.