max-mapper / max-mapper/github-oauth

pathname in baseURL is ignored for redirectURI

Open
#18 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
71
Forks
20
PR merge metrics
No merged PRs in 30d

Description

{
  baseUrl: 'https://example.com/basename', 
  callbackURI: '/github/callback',
}

With that config, I get the redirect URI https://example.com/github/callback, even though it should contain the /basename. I explicitly don't want to specify /basename/github/callback as the callbackURI, because that would mount the route to that pathname, which would be available at https://example.com/basename/basename/github/callback (notice the double "basename").

I think the problem lies in the usage of url.resolve:

urlObj.pathname = url.resolve(urlObj.pathname, opts.callbackURI)

url.resolve is meant to resolve relative paths, but the callbackURI starts with a slash, so the pathname is ignored. Joining them with a / (and stripping unnecessary slashes) would be preferable in that case. Since all route mountpoints are supposed to start with a slash, we can probably just always change the behaviour and drop url.resolve entirely.

I provide a PR #19 with the suggested fix.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the urlObj.pathname assignment using url.resolve and compare it with PR #19. Done means a baseUrl pathname such as /basename is preserved in the redirect URI without requiring it in callbackURI or duplicating it in the mounted route.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
authentication
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.