Skip to content

Instantly share code, notes, and snippets.

@dcaponi
Created January 1, 2021 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcaponi/b9919931dbddfa8ee0eb8cb8083bdad2 to your computer and use it in GitHub Desktop.
Save dcaponi/b9919931dbddfa8ee0eb8cb8083bdad2 to your computer and use it in GitHub Desktop.
Builts the auth url to an IdP using PKCE flow
const PKCEAuthCodeFirstStep = () => {
let oidcURL = `${process.env.OIDC_IDP_URL}/auth`;
let queryParams = [`client_id=${process.env.OIDC_CLIENT_ID}`];
let codeVerifier = createCodeVerifier( 50 );
localStorage.setItem( 'code_verifier', codeVerifier );
return createCodeChallenge( codeVerifier ).then( codeChallenge => {
queryParams.push(`code_challenge=${codeChallenge}`);
queryParams.push(`redirect_uri=http://localhost/login_oidc`);
queryParams.push(`code_challenge_method=S256`);
queryParams.push(`response_type=code`);
queryParams.push(`scope=openid`);
return `${oidcURL}?${queryParams.join("&")}`;
} );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment