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

improved oauth success user experience flow #1011

Merged
merged 2 commits into from
May 7, 2020
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
8 changes: 6 additions & 2 deletions packages/oauth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <script> and <style> tags
const htmlResponse = `<html><body>Success!</body></html>`
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(htmlResponse);
},
failure: (error, installOptions , req, res) => {
// Do custom failure logic here
res.send('failure');
res.writeHead(500, { 'Content-Type': 'text/html' });
res.end('<html><body><h1>Oops, Something Went Wrong! Please Try Again or Contact the App Owner</h1></body></html>');
}
}
app.get('/slack/oauth_redirect', (req, res) => {
Expand Down
12 changes: 9 additions & 3 deletions packages/oauth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 = `<html>
<meta http-equiv="refresh" content="0; URL=${redirectUrl}">
<body>
<h1>Success! Redirecting to the Slack App...</h1>
<button onClick="window.location = '${redirectUrl}'">Click here to redirect</button>
</body></html>`;
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(htmlResponse);
} else {
// Send a generic success page
// TODO: make this page pretty?
Expand Down