oauth-pkce
Version:
OAUTH PKCE code_verifier and code_challenge generator
1 lines • 727 B
JavaScript
;function b64Uri(n){return btoa(n).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function getPkce(n,r){n=n||43;for(var e="undefined"!=typeof window&&window.msCrypto||crypto,t=b64Uri(Array.prototype.map.call(e.getRandomValues(new Uint8Array(n)),function(n){return String.fromCharCode(n)}).join("")).substring(0,n),o=new Uint8Array(t.length),a=0;a<t.length;a++)o[a]=t.charCodeAt(a);var i=e.subtle.digest("SHA-256",o);"undefined"!=typeof window&&window.CryptoOperation?(i.onerror=r,i.oncomplete=function(n){runCallback(r,t,n.target.result)}):i.then(function(n){runCallback(r,t,n)}).catch(r)}function runCallback(n,r,e){n(null,{verifier:r,challenge:b64Uri(String.fromCharCode.apply(null,new Uint8Array(e)))})}