Skip to content

Commit

Permalink
fix: audience for loginUrls without my in the domain
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Jan 15, 2021
1 parent 0d6d3ea commit 2bca84c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/authInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ function getJwtAudienceUrl(options: OAuth2Options & { createdOrgInstance?: strin
createdOrgInstance.startsWith('cs') ||
createdOrgInstance.endsWith('s') ||
options.loginUrl?.includes('sandbox.my.salesforce.com') || // enhanced domains >= 230
options.loginUrl?.match(/([Cc][Ss][0-9]+.my.salesforce.com)/g) ||
options.loginUrl?.match(/([Cc][Ss][0-9]+.my.salesforce.com)/g) || // my domains
options.loginUrl?.match(/([Cc][Ss][0-9]+.salesforce.com)/g) || // instance without my domain
(options.loginUrl && urlParse(options.loginUrl).hostname === 'test.salesforce.com')
) {
return SfdcUrl.SANDBOX;
Expand Down
16 changes: 16 additions & 0 deletions test/unit/authInfoTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1672,6 +1672,22 @@ describe('AuthInfo', () => {
await runTest({ loginUrl: 'https://customdomain.my.salesforce.com' }, 'https://login.salesforce.com');
});

it('should use the correct audience URL for scratch orgs with domains', async () => {
await runTest({ loginUrl: 'https://cs17.my.salesforce.com' }, 'https://test.salesforce.com');
});

it('should use the correct audience URL for scratch orgs with domains (capitalized)', async () => {
await runTest({ loginUrl: 'https://CS17.my.salesforce.com' }, 'https://test.salesforce.com');
});

it('should use the correct audience URL for scratch orgs without domains', async () => {
await runTest({ loginUrl: 'https://cs17.salesforce.com' }, 'https://test.salesforce.com');
});

it('should use the correct audience URL for scratch orgs without domains (capitalized)', async () => {
await runTest({ loginUrl: 'https://CS17.salesforce.com' }, 'https://test.salesforce.com');
});

it('should use the correct audience URL for sandbox enhanced domains', async () => {
await runTest(
{ loginUrl: 'https://customdomain--sandboxname.sandbox.my.salesforce.com' },
Expand Down

0 comments on commit 2bca84c

Please sign in to comment.