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 17e5736
Showing 1 changed file with 2 additions and 6 deletions.
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 17e5736

Please sign in to comment.