Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: redirect to oauth success url #811

Merged
merged 4 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/webOAuthServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ export class WebOAuthServer extends AsyncCreatable<WebOAuthServer.Options> {
oauth2: this.oauth2,
});
await authInfo.save();
this.webServer.doRedirect(303, authInfo.getOrgFrontDoorUrl(), response);
const loginUrl = this.oauth2.loginUrl.replace(/\/+$/, '');
const oauthSuccessUrl = `${loginUrl}/services/oauth2/success`;
this.webServer.doRedirect(303, oauthSuccessUrl, response);
response.end();
resolve(authInfo);
} catch (err) {
Expand Down
7 changes: 3 additions & 4 deletions test/unit/webOauthServerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('WebOauthServer', () => {

describe('authorizeAndSave', () => {
const testData = new MockTestOrgData();
const frontDoorUrl = 'https://www.frontdoor.com';
const oauthSuccessUrl = 'https://login.salesforce.com/services/oauth2/success';
let authFields: AuthFields;
let authInfoStub: StubbedType<AuthInfo>;
let serverResponseStub: StubbedType<http.ServerResponse>;
Expand All @@ -54,7 +54,6 @@ describe('WebOauthServer', () => {
authFields = await testData.getConfig();
authInfoStub = stubInterface<AuthInfo>($$.SANDBOX, {
getFields: () => authFields,
getOrgFrontDoorUrl: () => frontDoorUrl,
});
serverResponseStub = stubInterface<http.ServerResponse>($$.SANDBOX, {});

Expand All @@ -71,12 +70,12 @@ describe('WebOauthServer', () => {
expect(authInfo.getFields()).to.deep.equal(authFields);
});

it('should redirect to front door url', async () => {
it('should redirect to oauth success url', async () => {
const oauthServer = await WebOAuthServer.create({ oauthConfig: {} });
await oauthServer.start();
await oauthServer.authorizeAndSave();
expect(redirectStub.callCount).to.equal(1);
expect(redirectStub.args).to.deep.equal([[303, frontDoorUrl, serverResponseStub]]);
expect(redirectStub.args).to.deep.equal([[303, oauthSuccessUrl, serverResponseStub]]);
});

it('should report error', async () => {
Expand Down