Created
January 1, 2021 19:56
-
-
Save dcaponi/769dce87c752d06bf2b188f57dd945e8 to your computer and use it in GitHub Desktop.
Creates a legal code_verifier based on the OAuth Spec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const createCodeVerifier = ( size ) => { | |
const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~'; | |
const charsetIndexBuffer = new Uint8Array( size ); | |
for ( let i = 0; i < size; i += 1 ) { | |
charsetIndexBuffer[i] = ( Math.random() * charset.length ) | 0; | |
} | |
let randomChars = []; | |
for ( let i = 0; i < charsetIndexBuffer.byteLength; i += 1 ) { | |
let index = charsetIndexBuffer[i] % charset.length; | |
randomChars.push( charset[index] ); | |
} | |
return randomChars.join( '' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment