Skip to content

Error handling with callback state #166

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

Closed
kevinsimper opened this issue May 24, 2020 · 3 comments
Closed

Error handling with callback state #166

kevinsimper opened this issue May 24, 2020 · 3 comments

Comments

@kevinsimper
Copy link

I set up grant with callback state, however error handling now goes into a redirect loop:

Here is for a undefined provider:

$ http http://localhost:9000/connect/twitch
HTTP/1.1 302 Found
Connection: keep-alive
Content-Length: 79
Content-Type: text/plain; charset=utf-8
Date: Sun, 24 May 2020 17:05:18 GMT
Location: ?error=Grant%3A%20missing%20or%20misconfigured%20provider
Vary: Accept
X-Powered-By: Express

Found. Redirecting to ?error=Grant%3A%20missing%20or%20misconfigured%20provider

$ http http://localhost:9000/connect/twitch?error=Grant%3A%20missing%20or%20misconfigured%20provider
HTTP/1.1 302 Found
Connection: keep-alive
Content-Length: 79
Content-Type: text/plain; charset=utf-8
Date: Sun, 24 May 2020 17:05:43 GMT
Location: ?error=Grant%3A%20missing%20or%20misconfigured%20provider
Vary: Accept
X-Powered-By: Express

Found. Redirecting to ?error=Grant%3A%20missing%20or%20misconfigured%20provider

and the code like this:

app.use(
  "/connect/:provider/:override?",
  express()
    .use(grant(grantConfig))
    .use((req, res) => {
    // never reaches here
  }))
@simov
Copy link
Owner

simov commented May 25, 2020

Hi @kevinsimper you found a bug! The intention was to redirect to / instead, but since all of my tests use the root / path for callback I never caught it. I'll publish the fix today.

'Missing or misconfigured provider' is considered an unrecoverable error from Grant's point of view. There is nothing you can do about it, anyone can try accessing the /connect/:whatever route, and so the catch all error message is always delivered back to the user:

http://localhost:3000/?error=Grant%3A%20missing%20or%20misconfigured%20provider

The defaults in your configuration are only being accessed when initializing a provider. If a provider cannot be initialized then none of that configuration can exist, and so the default 'querystring' transport is being used to deliver the error message in the default callback route, which is the root '/'.

@kevinsimper
Copy link
Author

That sounds really great, thanks for the help! 😄

@simov
Copy link
Owner

simov commented May 25, 2020

Published in v5.1.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants