Skip to content

Commit

Permalink
idplogin for public client
Browse files Browse the repository at this point in the history
  • Loading branch information
yunakim714 committed Sep 11, 2024
1 parent be716eb commit bbfc077
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
18 changes: 16 additions & 2 deletions src/static/helpers/slasHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,22 @@ describe('Registered B2C user flow', () => {
});

describe('Social login user flow', () => {

})
test('loginIDPUser does not stop when authorizeCustomer returns 303', async () => {
// slasClient is copied and tries to make an actual API call
const mockSlasClient = createMockSlasClient();
const {shortCode, organizationId} = mockSlasClient.clientConfig.parameters;

// Mock authorizeCustomer
nock(`https://${shortCode}.api.commercecloud.salesforce.com`)
.get(`/shopper/auth/v1/organizations/${organizationId}/oauth2/authorize`)
.query(true)
.reply(303, {message: 'Oh yes!'});

await expect(
slasHelper.loginIDPUser(mockSlasClient, parameters)
).resolves.not.toThrow(ResponseError);
});
});

describe('Refresh Token', () => {
test('refreshes the token with slas public client', () => {
Expand Down
19 changes: 1 addition & 18 deletions src/static/helpers/slasHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,6 @@ export async function loginIDPUser(
clientId: string;
siteId: string;
}>,
credentials: {
clientSecret?: string;
},
parameters: {
redirectURI: string;
hint: string;
Expand All @@ -408,21 +405,7 @@ export async function loginIDPUser(
...(parameters.dnt !== undefined && {dnt: parameters.dnt.toString()}),
};

// using slas private client
if (credentials.clientSecret) {
const authHeaderIdSecret = `Basic ${stringToBase64(
`${slasClient.clientConfig.parameters.clientId}:${credentials.clientSecret}`
)}`;

const optionsToken = {
headers: {
Authorization: authHeaderIdSecret,
},
body: tokenBody,
};
return slasClient.getAccessToken(optionsToken);
}
return slasClient.getAccessToken({body: tokenBody})
return slasClient.getAccessToken({body: tokenBody});
}

/**
Expand Down

0 comments on commit bbfc077

Please sign in to comment.