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

Allow handlerInstallPath to work without stateStore #1507

Merged
merged 1 commit into from
Jul 7, 2022
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
45 changes: 24 additions & 21 deletions packages/oauth/src/install-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,6 @@ export class InstallProvider {
const _printableOptions = JSON.stringify(_installOptions);
this.logger.debug(`Running handleInstallPath() with ${_printableOptions}`);

if (this.stateStore === undefined) {
throw new GenerateInstallUrlError('StateStore is not properly configured');
}

try {
let shouldProceed = true;
if (options?.beforeRedirection !== undefined) {
Expand All @@ -350,24 +346,31 @@ export class InstallProvider {
this.logger.debug('Skipped to proceed with the built-in redirection as beforeRedirection returned false');
return;
}
const state = await this.stateStore.generateStateParam(_installOptions, new Date());
const stateCookie: string = this.buildSetCookieHeaderForNewState(state);
if (res.getHeader('Set-Cookie')) {
// If the cookies already exist
const existingCookies = res.getHeader('Set-Cookie') || [];
const allCookies: string[] = [];
if (Array.isArray(existingCookies)) {
allCookies.push(...existingCookies);
} else if (typeof existingCookies === 'string') {
allCookies.push(existingCookies);
} else {
allCookies.push(existingCookies.toString());
let state: string | undefined;
if (this.stateVerification) {
if (this.stateStore) {
state = await this.stateStore.generateStateParam(_installOptions, new Date());
const stateCookie: string = this.buildSetCookieHeaderForNewState(state);
if (res.getHeader('Set-Cookie')) {
// If the cookies already exist
const existingCookies = res.getHeader('Set-Cookie') || [];
const allCookies: string[] = [];
if (Array.isArray(existingCookies)) {
allCookies.push(...existingCookies);
} else if (typeof existingCookies === 'string') {
allCookies.push(existingCookies);
} else {
allCookies.push(existingCookies.toString());
}
// Append the state cookie
allCookies.push(stateCookie);
res.setHeader('Set-Cookie', allCookies);
} else {
res.setHeader('Set-Cookie', stateCookie);
}
} else if (this.stateStore === undefined) {
throw new GenerateInstallUrlError('StateStore is not properly configured');
}
// Append the state cookie
allCookies.push(stateCookie);
res.setHeader('Set-Cookie', allCookies);
} else {
res.setHeader('Set-Cookie', stateCookie);
}
const url = await this.generateInstallUrl(_installOptions, this.stateVerification, state);
this.logger.debug(`Generated authorize URL: ${url}`);
Expand Down
2 changes: 1 addition & 1 deletion packages/webhook/src/IncomingWebhook.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const url = 'https://hooks.slack.com/services/FAKEWEBHOOK';
describe('IncomingWebhook', function () {

describe('constructor()', function () {
it('should build a default wehbook given a URL', function () {
it('should build a default webhook given a URL', function () {
const webhook = new IncomingWebhook(url);
assert.instanceOf(webhook, IncomingWebhook);
});
Expand Down