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 all commits
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
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ jobs:
- https://github.com/salesforcecli/plugin-schema
- https://github.com/salesforcecli/plugin-env
- https://github.com/salesforcecli/plugin-org
- https://github.com/salesforcecli/plugin-login
with:
packageName: '@salesforce/core'
externalProjectGitUrl: ${{ matrix.externalProjectGitUrl }}
Expand Down
10 changes: 9 additions & 1 deletion messages/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,16 @@ The device authorization request timed out. After executing force:auth:device:lo

# serverErrorHTMLResponse

<h1>%s</h1><br />This is most likely <b>not</b> an error with the Salesforce CLI. Please ensure all information is accurate and try again.
<html><head><style>body {background-color:#F4F6F9; font-family: Arial, sans-serif; font-size: 0.8125rem; line-height: 1.5rem; color: #16325c;} #center {margin: auto; width: 370px; padding: 100px 0px 20px;} #logo-container {margin-left: auto; margin-right: auto; text-align: center;} #logo {max-width: 180px; max-height: 113px; margin-bottom: 2rem; border: 0;} #header {font-size: 1.5rem; text-align: center; margin-bottom: 1rem;} #message {background-color: #FFFFFF; margin: 0px auto; padding: 1.25rem; border-radius: 0.25rem; border: 1px solid #D8DDE6;} #footer {height: 24px; width: 370px; text-align: center; font-size: .75rem; position: absolute; bottom: 10;}</style></head><body><div id="center"><div id="logo-container"><img id="logo" aria-hidden="true" name="logo" alt="Salesforce" src="data:image/svg+xml;base64,%s"></div><div id="header">%s</div><div id="message">%s<br/><br/>This is most likely <b>not</b> an error with the Salesforce CLI. Please ensure all information is accurate and try again.</div><div id="footer">&copy; %s Salesforce, Inc. All rights reserved.</div></div></body></html>

# missingAuthCode

No authentication code found on login response.

# serverSuccessHTMLResponse

<html><head><style>body {background-color:#F4F6F9; font-family: Arial, sans-serif; font-size: 0.8125rem; line-height: 1.5rem; color: #16325c;} #center {margin: auto; width: 300px; padding: 100px 0px 20px;} #logo-container {margin-left: auto; margin-right: auto; text-align: center;} #logo {max-width: 180px; max-height: 113px; margin-bottom: 2rem; border: 0;} #header {font-size: 1.5rem; text-align: center; margin-bottom: 1rem;} #message {background-color: #FFFFFF; margin: 0px auto; padding: 1.25rem; border-radius: 0.25rem; border: 1px solid #D8DDE6;} #footer {height: 24px; width: 300px; text-align: center; font-size: .75rem; position: absolute; bottom: 10;}</style></head><body><div id="center"><div id="logo-container"><img id="logo" aria-hidden="true" name="logo" alt="Salesforce" src="data:image/svg+xml;base64,%s"></div><div id="header">Authentication Successful</div><div id="message">You've successfully logged in. You can now close this browser tab or window.</div><div id="footer">&copy; %s Salesforce, Inc. All rights reserved.</div></div></body></html>

# serverSfdcImage

PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDIxLjEuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IgoJIHZpZXdCb3g9IjAgMCAyNjIgMTg0IiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCAyNjIgMTg0OyIgeG1s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LjUsMC40LTAuNSwwLjRoLTVMMTQzLjYsOThjLTAuNCwyLTAuOCwzLjctMS4zLDUuMWMtMC41LDEuNC0xLjEsMi40LTIsMy40CgkJCQkJYy0wLjgsMC45LTEuNywxLjYtMi44LDEuOWMtMSwwLjQtMi4zLDAuNi0zLjcsMC42Yy0wLjcsMC0xLjQsMC0yLjItMC4yYy0wLjYtMC4xLTAuOS0wLjItMS40LTAuNGMtMC4yLTAuMS0wLjMtMC4zLTAuMi0wLjYKCQkJCQljMC4xLTAuMywxLTIuNywxLjEtMy4xYzAuMi0wLjQsMC41LTAuMiwwLjUtMC4yYzAuMywwLjEsMC41LDAuMiwwLjgsMC4zYzAuNCwwLjEsMC44LDAuMSwxLjIsMC4xYzAuNywwLDEuMy0wLjEsMS44LTAuMwoJCQkJCWMwLjYtMC4yLDEtMC42LDEuNC0xLjFjMC40LTAuNSwwLjctMS4yLDEuMS0yLjFjMC4zLTAuOSwwLjYtMi4yLDAuOS0zLjdsMy40LTE4LjloLTMuM2MtMC40LDAtMC41LTAuMi0wLjUtMC41bDAuNi0zLjEKCQkJCQljMC4xLTAuNSwwLjUtMC40LDAuNS0wLjRoMy40bDAuMi0xYzAuNS0zLDEuNS01LjMsMy02LjhjMS41LTEuNSwzLjctMi4zLDYuNC0yLjNjMC44LDAsMS41LDAuMSwyLjEsMC4yCgkJCQkJQzE1NSw2NC44LDE1NS41LDY0LjksMTU2LDY1LjF6IE04OC42LDk3LjZjMCwwLjMtMC4yLDAuNS0wLjQsMC41aC00Yy0wLjMsMC0wLjQtMC4yLTAuNC0wLjVWNjUuNWMwLTAuMiwwLjItMC41LDAuNC0wLjVoNAoJCQkJCWMwLjMsMCwwLjQsMC4yLDAuNCwwLjVWOTcuNnoiLz4KCQkJPC9nPgoJCTwvZz4KCTwvZz4KPC9nPgo8L3N2Zz4K
2 changes: 1 addition & 1 deletion src/org/authInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ export class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
this.throwUserGetException(response);
} else {
const userInfoJson = parseJsonMap(response.body) as UserInfoResult;
const url = `${baseUrl.toString()}/services/data/${apiVersion}/sobjects/User/${userInfoJson.user_id}`;
const url = `${baseUrl.toString()}services/data/${apiVersion}/sobjects/User/${userInfoJson.user_id}`;
shetzel marked this conversation as resolved.
Show resolved Hide resolved
this.logger.info(`Sending request for User SObject after successful auth code exchange to URL: ${url}`);
response = await new Transport().httpRequest({ url, method: 'GET', headers });
if (response.statusCode >= 400) {
Expand Down
73 changes: 62 additions & 11 deletions src/webOAuthServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { AuthInfo, DEFAULT_CONNECTED_APP_INFO } from './org';
import { SfError } from './sfError';
import { Messages } from './messages';
import { SfProjectJson } from './sfProject';
import { EventEmitter } from 'events';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'auth');
Expand Down Expand Up @@ -46,6 +47,7 @@ export class WebOAuthServer extends AsyncCreatable<WebOAuthServer.Options> {
private webServer!: WebServer;
private oauth2!: OAuth2;
private oauthConfig: JwtOAuth2Config;
private oauthError = new Error('Oauth Error');

public constructor(options: WebOAuthServer.Options) {
super(options);
Expand Down Expand Up @@ -94,11 +96,12 @@ export class WebOAuthServer extends AsyncCreatable<WebOAuthServer.Options> {
oauth2: this.oauth2,
});
await authInfo.save();
this.webServer.doRedirect(303, authInfo.getOrgFrontDoorUrl(), response);
await this.webServer.handleSuccess(response);
response.end();
resolve(authInfo);
} catch (err) {
this.webServer.reportError(err as Error, response);
this.oauthError = err as Error;
await this.webServer.handleError(response);
reject(err);
}
})
Expand Down Expand Up @@ -158,9 +161,12 @@ export class WebOAuthServer extends AsyncCreatable<WebOAuthServer.Options> {
request.query = parseQueryString(url.query as string);
if (request.query.error) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const err = new SfError(request.query.error_description ?? request.query.error, request.query.error);
this.webServer.reportError(err, response);
return reject(err);
this.oauthError = new SfError(
request.query.error_description ?? request.query.error,
request.query.error
);
await this.webServer.handleError(response);
return reject(this.oauthError);
}
this.logger.debug(`request.query.state: ${request.query.state as string}`);
try {
Expand All @@ -170,6 +176,10 @@ export class WebOAuthServer extends AsyncCreatable<WebOAuthServer.Options> {
} catch (err) {
reject(err);
}
} else if (url.pathname === '/OauthSuccess') {
this.webServer.reportSuccess(response);
} else if (url.pathname === '/OauthError') {
this.webServer.reportError(this.oauthError, response);
} else {
this.webServer.sendError(404, 'Resource not found', response);
const errName = 'invalidRequestUri';
Expand Down Expand Up @@ -262,6 +272,7 @@ export class WebServer extends AsyncCreatable<WebServer.Options> {
public host = 'localhost';
private logger!: Logger;
private sockets: Socket[] = [];
private redirectStatus = new EventEmitter();

public constructor(options: WebServer.Options) {
super(options);
Expand Down Expand Up @@ -312,7 +323,7 @@ export class WebServer extends AsyncCreatable<WebServer.Options> {
/**
* sends a response error.
*
* @param statusCode he statusCode for the response.
* @param status the statusCode for the response.
* @param message the message for the http body.
* @param response the response to write the error to.
*/
Expand All @@ -325,11 +336,12 @@ export class WebServer extends AsyncCreatable<WebServer.Options> {
/**
* sends a response redirect.
*
* @param statusCode the statusCode for the response.
* @param status the statusCode for the response.
* @param url the url to redirect to.
* @param response the response to write the redirect to.
*/
public doRedirect(status: number, url: string, response: http.ServerResponse): void {
this.logger.debug(`Redirecting to ${url}`);
response.setHeader('Content-Type', 'text/plain');
const body = `${status} - Redirecting to ${url}`;
response.setHeader('Content-Length', Buffer.byteLength(body));
Expand All @@ -340,20 +352,59 @@ export class WebServer extends AsyncCreatable<WebServer.Options> {
/**
* sends a response to the browser reporting an error.
*
* @param error the error
* @param response the response to write the redirect to.
* @param error the oauth error
* @param response the HTTP response.
*/
public reportError(error: Error, response: http.ServerResponse): void {
response.setHeader('Content-Type', 'text/html');
const body = messages.getMessage('serverErrorHTMLResponse', [error.message]);
response.setHeader('Content-Length', Buffer.byteLength(body));
const currentYear = new Date().getFullYear();
const encodedImg = messages.getMessage('serverSfdcImage');
const body = messages.getMessage('serverErrorHTMLResponse', [encodedImg, error.name, error.message, currentYear]);
response.setHeader('Content-Length', Buffer.byteLength(body, 'utf8'));
response.end(body);
if (error.stack) {
this.logger.debug(error.stack);
}
this.redirectStatus.emit('complete');
}

/**
* sends a response to the browser reporting the success.
*
* @param response the HTTP response.
*/
public reportSuccess(response: http.ServerResponse): void {
response.setHeader('Content-Type', 'text/html');
const currentYear = new Date().getFullYear();
const encodedImg = messages.getMessage('serverSfdcImage');
const body = messages.getMessage('serverSuccessHTMLResponse', [encodedImg, currentYear]);
response.setHeader('Content-Length', Buffer.byteLength(body, 'utf8'));
response.end(body);
this.redirectStatus.emit('complete');
}

public async handleSuccess(response: http.ServerResponse): Promise<void> {
return this.handleRedirect(response, '/OauthSuccess');
}

public async handleError(response: http.ServerResponse): Promise<void> {
return this.handleRedirect(response, '/OauthError');
}

protected async init(): Promise<void> {
this.logger = await Logger.child(this.constructor.name);
}

private async handleRedirect(response: http.ServerResponse, url: '/OauthSuccess' | '/OauthError'): Promise<void> {
return new Promise((resolve) => {
this.redirectStatus.on('complete', () => {
this.logger.debug(`Redirect complete`);
resolve();
});
this.doRedirect(303, url, response);
});
}

/**
* Make sure we can't open a socket on the localhost/host port. It's important because we don't want to send
* auth tokens to a random strange port listener. We want to make sure we can startup our server first.
Expand Down
Loading