Skip to content

Commit

Permalink
fix naming
Browse files Browse the repository at this point in the history
  • Loading branch information
alvinsj committed Jun 8, 2024
1 parent 647b8f6 commit 07a5f2d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/lib/__tests__/pkce.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
toSha256,
toBase64Url,
createRandomString,
createPKCECodeVerifier,
createPKCECodeChallenge,
} from '../pkce'

describe('createRandomString', () => {
Expand Down Expand Up @@ -52,18 +52,18 @@ describe('toBase64Url', () => {
})
})

describe('createPKCECodeVerifier', () => {
describe('createPKCECodeChallenge', () => {
test('creates code challenge', async () => {
const codeVerifier = createRandomString(43)
const codeChallenge = await createPKCECodeVerifier(codeVerifier)
const codeChallenge = await createPKCECodeChallenge(codeVerifier)

expect(codeChallenge).toHaveLength(43)
})

test('creates unique code challenge', async () => {
const codeVerifier = createRandomString(43)
const codeChallenge1 = await createPKCECodeVerifier(codeVerifier)
const codeChallenge2 = await createPKCECodeVerifier(codeVerifier)
const codeChallenge1 = await createPKCECodeChallenge(codeVerifier)
const codeChallenge2 = await createPKCECodeChallenge(codeVerifier)

expect(codeChallenge1).toEqual(codeChallenge2)
})
Expand Down
8 changes: 4 additions & 4 deletions src/lib/pkce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export const createRandomString = (length: number = 34): string => {
return randomString;
}

export const createPKCECodeVerifier = async (str: string): string => {
const hashed: Uint8Array = await toSha256(str)
const codeVerifier = toBase64Url(hashed)
return codeVerifier;
export const createPKCECodeChallenge = async (codeVerifies: string): string => {
const hashed: Uint8Array = await toSha256(codeVerifies)
const codeChallenge = toBase64Url(hashed)
return codeChallenge;
}

0 comments on commit 07a5f2d

Please sign in to comment.