Skip to content

Commit

Permalink
chore(refactor): use base64url encode method
Browse files Browse the repository at this point in the history
  • Loading branch information
kangmingtay committed Feb 7, 2025
1 parent f1ba550 commit 0affd19
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/lib/base64url.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
stringToBase64URL,
codepointToUTF8,
stringFromBase64URL,
stringFromUTF8,
codepointToUTF8,
stringToBase64URL,
} from './base64url'

const EXAMPLES = [
Expand Down
8 changes: 2 additions & 6 deletions src/lib/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { API_VERSION_HEADER_NAME, BASE64URL_REGEX } from './constants'
import { AuthInvalidJwtError } from './errors'
import { base64UrlToUint8Array, stringFromBase64URL } from './base64url'
import { base64UrlToUint8Array, stringFromBase64URL, stringToBase64URL } from './base64url'
import { JwtHeader, JwtPayload, SupportedStorage } from './types'

export function expiresAt(expiresIn: number) {
Expand Down Expand Up @@ -276,10 +276,6 @@ async function sha256(randomString: string) {
.join('')
}

function base64urlencode(str: string) {
return btoa(str).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
}

export async function generatePKCEChallenge(verifier: string) {
const hasCryptoSupport =
typeof crypto !== 'undefined' &&
Expand All @@ -293,7 +289,7 @@ export async function generatePKCEChallenge(verifier: string) {
return verifier
}
const hashed = await sha256(verifier)
return base64urlencode(hashed)
return stringToBase64URL(hashed)
}

export async function getCodeChallengeAndMethod(
Expand Down

0 comments on commit 0affd19

Please sign in to comment.