I want to work in my localhost and my live domain, there is any way to insert more then one callback to github oauth settings? How we solve this problem?
4 Answers
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:
My official OAuth application for production
- Client ID:
ABC - Client Secret:
123 - Authorization callback URL:
https://example.com/api/v1/security/oauth/github/callback
- Client ID:
My private OAuth application for development
- Client ID:
XYZ - Client Secret:
456 - Authorization callback URL:
https://localhost/api/v1/security/oauth/github/callback
- Client ID:
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).
1 Comment
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:
- domain.com/auth/github/callback/sub-callback-1
- domain.com/auth/github/callback/sub-callback-2
- 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.
4 Comments
https://localhost/auth/github/callback and one to be used in production https://example.net/auth/github/callback. Can this be achieved with what you describe above?https://example.net/auth/github/callback-localhost and then let your server redirect it to localhost to archive that.https://example.net/auth/github/callback it means I have to change the configuration of my web server in production to redirect to https://localhost/auth/github/callback. Right? I have proposed another solution below. What do you think?127.0.0.1 or ::1 instead of localhostAccording their doc, you don't need to register localhost redirect URLs, but it just accepts URLs even if it doesn't match the registered one as long as its host part is localhost.
Comments
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.