Skip to content

Commit 895152d

Browse files
committed
chore(refactor): use base64url encode method
1 parent 324d017 commit 895152d

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/lib/helpers.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { API_VERSION_HEADER_NAME, BASE64URL_REGEX } from './constants'
22
import { AuthInvalidJwtError } from './errors'
3-
import { base64UrlToUint8Array, stringFromBase64URL } from './base64url'
3+
import { base64UrlToUint8Array, stringFromBase64URL, stringToBase64URL } from './base64url'
44
import { JwtHeader, JwtPayload, SupportedStorage } from './types'
55

66
export function expiresAt(expiresIn: number) {
@@ -276,10 +276,6 @@ async function sha256(randomString: string) {
276276
.join('')
277277
}
278278

279-
function base64urlencode(str: string) {
280-
return btoa(str).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
281-
}
282-
283279
export async function generatePKCEChallenge(verifier: string) {
284280
const hasCryptoSupport =
285281
typeof crypto !== 'undefined' &&
@@ -293,7 +289,7 @@ export async function generatePKCEChallenge(verifier: string) {
293289
return verifier
294290
}
295291
const hashed = await sha256(verifier)
296-
return base64urlencode(hashed)
292+
return stringToBase64URL(hashed)
297293
}
298294

299295
export async function getCodeChallengeAndMethod(

0 commit comments

Comments
 (0)