Github oauth multiple authorization callback URL

Instead of using localhost, you can modify your hosts file and point your domain to use 127.0.0.1. On a Mac, open the hosts file located under:

Computer > Macintosh HD > etc

Add the entry for your domain. For example if your domain is mycoolapp.com

127.0.0.1 mycoolapp.com

Just make sure to comment out this line when you want to test using your production server:

#127.0.0.1 mycoolapp.com

Using this solution, you don't need to maintain two separate configurations.


I solved this issue by creating a dedicated OAuth application on Github for my local development environment. So I have the following 2 OAuth applications:

  1. My official OAuth application for production

    • Client ID: ABC
    • Client Secret: 123
    • Authorization callback URL: https://example.com/api/v1/security/oauth/github/callback
  2. My private OAuth application for development

    • Client ID: XYZ
    • Client Secret: 456
    • Authorization callback URL: https://localhost/api/v1/security/oauth/github/callback

When I configure my API in local, I use the ID and secret of the development application (2). And in production I use the ID and secret of my official application (1).


The bad news is we can't insert more than one callback to GitHub OAuth setting.

Good news is that we can use multiple callback sub-url under our callback url, then you can redirect(proxy) it to any callback url that you want.

for example, if your callback url is: domain.com/auth/github/callback, then the following callback url are all valid:

  1. domain.com/auth/github/callback/sub-callback-1
  2. domain.com/auth/github/callback/sub-callback-2
  3. domain.com/auth/github/callback/sub-callback-3

etc.

After redirect to sub-callback-N with all parameters, then we could jump to any other callback url as you expected.