Some OAuth providers (like Google), limit what hosts can be used for redirect URIs. This can be problematic when using a hostname-based local development server (like Pow or Invoker). This very simple redirection server can be used to work around this restriction.
- Assuming your local hostname is
app.test
and your callback path is/auth/google/callback
, add the following URL to the credentials section of the Google Cloud Platform console under “Authorized Redirect URIs”:http://localhost:4000/app.test/auth/google/callback
- Update your app to use this as the redirect URI in your development environment.
- Start the redirect server:
You may need to use
PORT=4000 ruby oauth_redirector.rb
BUNDLE_IGNORE_CONFIG=true
depending on how Bundler is configured.
- The redirector assumes you’re using SSL for your local development server. If you aren’t, modifying the server is left as an exercise for the reader.
- The port
4000
is used in these examples, but this can be changed as long as the same port is used in the credentials configuration, the app configuration, and when running the redirect server.