Skip to content

Commit

Permalink
only generate code challenge for public client
Browse files Browse the repository at this point in the history
  • Loading branch information
yunakim714 committed Sep 30, 2024
1 parent 8df5137 commit ac79df7
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/static/helpers/slasHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,13 @@ export async function authorize(
},
privateClient = false
): Promise<{code: string; url: string; usid: string}> {
const codeChallenge = await generateCodeChallenge(codeVerifier);
interface ClientOptions {
codeChallenge?: string;
}
const clientOptions: ClientOptions = {};
if (!privateClient) {
clientOptions.codeChallenge = await generateCodeChallenge(codeVerifier);
}

// Create a copy to override specific fetchOptions
const slasClientCopy = new ShopperLogin(slasClient.clientConfig);
Expand All @@ -136,7 +142,9 @@ export async function authorize(
parameters: {
client_id: slasClient.clientConfig.parameters.clientId,
channel_id: slasClient.clientConfig.parameters.siteId,
...(!privateClient && {code_challenge: codeChallenge}),
...(clientOptions.codeChallenge && {
code_challenge: clientOptions.codeChallenge,
}),
...(parameters.hint && {hint: parameters.hint}),
organizationId: slasClient.clientConfig.parameters.organizationId,
redirect_uri: parameters.redirectURI,
Expand Down Expand Up @@ -190,18 +198,27 @@ export async function authorizeIDP(
}
): Promise<{url: string; codeVerifier: string}> {
const codeVerifier = createCodeVerifier();
const codeChallenge = await generateCodeChallenge(codeVerifier);

// Create a copy to override specific fetchOptions
const slasClientCopy = new ShopperLogin(slasClient.clientConfig);

const privateClient = !!credentials.clientSecret;

interface ClientOptions {
codeChallenge?: string;
}
const clientOptions: ClientOptions = {};
if (!privateClient) {
clientOptions.codeChallenge = await generateCodeChallenge(codeVerifier);
}

const options = {
parameters: {
client_id: slasClient.clientConfig.parameters.clientId,
channel_id: slasClient.clientConfig.parameters.siteId,
...(!privateClient && {code_challenge: codeChallenge}),
...(clientOptions.codeChallenge && {
code_challenge: clientOptions.codeChallenge,
}),
hint: parameters.hint,
organizationId: slasClient.clientConfig.parameters.organizationId,
redirect_uri: parameters.redirectURI,
Expand Down

0 comments on commit ac79df7

Please sign in to comment.