simple-pkce-browser
v1.0.3
Published
PKCE HMAC or hash SHA256 challenge & verifier generator for any browser (using fast-sha256)
Downloads
35
Readme
simple-pkce-browser
PKCE HMAC or hash SHA256 base64 challenge & verifier generator for any browser (using fast-sha256)
Installation
npm i simple-pkce-browser
Usage
Library exports single function - createPKCEHelper(isHMAC = true)
This function returns object with two methods on it:
getChallenge(verifier: string) => string
- for getting challenge from verifiergenerateChallenge(verifierLength: number) => PKCEChallenge
- generates verifier of given length and returnsPKCEChallenge
:
interface PKCEChallenge {
verifier: string;
challenge: string;
}
Examples
if you need SHA256 base64 HMAC challenge:
import { createPKCEHelper, PKCEChallenge, PKCEHelperLegacyBrowser } from 'simple-pkce-browser'
const VERIFIER_LENGTH = 64
const { generateChallenge, getChallenge }: PKCEHelperLegacyBrowser = createPKCEHelper()
const { verifier, challenge }: PKCEChallenge = generateChallenge(VERIFIER_LENGTH)
if you need SHA256 base64 hash you do exactly the same, but need to pass false
as the first parameter to createPKCEHelper()
:
import { createPKCEHelper, PKCEChallenge, PKCEHelperLegacyBrowser } from 'simple-pkce-browser'
const VERIFIER_LENGTH = 64
const { generateChallenge, getChallenge }: PKCEHelperLegacyBrowser = createPKCEHelper(false)
const { verifier, challenge }: PKCEChallenge = generateChallenge(VERIFIER_LENGTH)