Skip to content

Commit

Permalink
Explicitly catch an error querystring with value access_denied; this …
Browse files Browse the repository at this point in the history
…signifies user canceled out of the installation flow. This fixes #1186
  • Loading branch information
filmaj committed Sep 13, 2021
1 parent 3163e35 commit 8566da4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/oauth/src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,8 @@ describe('OAuth', async () => {
assert.isTrue(sent);
});

it('should call the failure callback due to missing code query parameter on the URL', async () => {
const req = { url: 'http://example.com' };
it('should call the failure callback if an access_denied error query parameter was returned on the URL', async () => {
const req = { url: 'http://example.com?error=access_denied' };
let sent = false;
const res = { send: () => { sent = true; } };
const callbackOptions = {
Expand All @@ -427,7 +427,7 @@ describe('OAuth', async () => {
assert.fail('should have failed');
},
failure: async (error, installOptions, req, res) => {
assert.equal(error.code, ErrorCode.MissingStateError)
assert.equal(error.code, ErrorCode.AuthorizationError)
res.send('failure');
},
}
Expand Down
5 changes: 5 additions & 0 deletions packages/oauth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,17 @@ export class InstallProvider {
): Promise<void> {
let parsedUrl;
let code: string;
let flowError: string;
let state: string;
let installOptions: InstallURLOptions;

try {
if (req.url !== undefined) {
parsedUrl = new URL(req.url);
flowError = parsedUrl.searchParams.get('error') as string;
if (flowError === 'access_denied') {
throw new AuthorizationError('User cancelled the OAuth installation flow!');
}
code = parsedUrl.searchParams.get('code') as string;
state = parsedUrl.searchParams.get('state') as string;
if (!state || !code) {
Expand Down

0 comments on commit 8566da4

Please sign in to comment.