authom icon indicating copy to clipboard operation
authom copied to clipboard

Redirect URI incorrect when used with Express

Open bradisbell opened this issue 10 years ago • 2 comments

I'm using Authom like this:

app.use('/auth/:service', authom.app);

I'm trying to authentication with Google, which uses OAuth2. The redirect_uri passed to Google contains / instead of /auth/google.

I think the problem is in oauth2.js where req.url is used:

this.code.query.redirect_uri = url.format(req.url)

If I add these two lines above this, the problem is resolved:

  req.url.pathname = req.baseUrl;
  delete req.url.href;

Similar changes still need to be made later on for onCode.

In any case, I think that originalUrl needs to come into play here because /auth/google isn't in req.url. Is this the correct fix? I would submit a pull request, but since this is an as-documented usage of Authom, I wanted to make sure I wasn't doing anything wrong to begin with. Any insight is welcomed! Thanks.

bradisbell avatar Jun 06 '15 16:06 bradisbell

I made some changes in a fork: https://github.com/bradisbell/authom/commit/894fc773bed45160cfbe2de999574c807a038bac If that change looks good, I will put in a pull request. But, please let me know if this commit doesn't make any sense.

bradisbell avatar Jun 06 '15 19:06 bradisbell

Is this going to be merged in? i'm still getting this issue

JonNode28 avatar Dec 02 '16 18:12 JonNode28