From 31af1071b540d739043016b2f4d1d2b101f94bbb Mon Sep 17 00:00:00 2001 From: Steve Gill Date: Wed, 6 May 2020 16:21:27 -0700 Subject: [PATCH 1/2] improved oauth success user experience flow --- packages/oauth/src/index.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/oauth/src/index.ts b/packages/oauth/src/index.ts index 7b13b0815..9f31ab760 100644 --- a/packages/oauth/src/index.ts +++ b/packages/oauth/src/index.ts @@ -179,7 +179,7 @@ export class InstallProvider { parsedUrl = parseUrl(req.url, true); code = parsedUrl.query.code as string; state = parsedUrl.query.state as string; - if (state === undefined || code === undefined) { + if (state === undefined || state === '' || code === undefined) { throw new MissingStateError('redirect url is missing state or code query parameters'); } } else { @@ -507,8 +507,14 @@ function callbackSuccess( // redirect back to slack // Open in native app const redirectUrl = `slack://app?team=${installation.team.id}&id=${installation.appId}`; - res.writeHead(302, { Location: redirectUrl }); - res.end(); + const htmlResponse = ` + + +

Success! Redirecting to the Slack App...

+ + `; + res.writeHead(200, { 'Content-Type': 'text/html' }); + res.end(htmlResponse); } else { // Send a generic success page // TODO: make this page pretty? From cff920ca05fc4f73991a075a16f6c3b2a9b6395e Mon Sep 17 00:00:00 2001 From: Steve Gill Date: Wed, 6 May 2020 16:54:46 -0700 Subject: [PATCH 2/2] updated custom success/failure callback examples in the README --- packages/oauth/README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/oauth/README.md b/packages/oauth/README.md index 81d54b502..631e56fa6 100644 --- a/packages/oauth/README.md +++ b/packages/oauth/README.md @@ -140,11 +140,15 @@ If you decide you need custom success or failure behaviors (ex: wanting to show const callbackOptions = { success: (installation, metadata, req, res) => { // Do custom success logic here - res.send('successful!'); + // tip: you can add javascript and css in the htmlResponse using the