Getting " invalid_grant" error when trying to use oauth with DigitalOcean gem in my rails app


I’m using Rails 4.2.3. I’m trying to enable external authentication via DigitalOcean, using the tutorial but I”m running into some problems. I have registered my application with DigitalOcean (using the callback http://localhost:3000/users/auth/digitalocean/callback) and gotten my client ID and secret, which I have added into config/initializers/devise.rb

    config.omniauth :digitalocean, “myid”, “mysecret”
    config.omniauth :google, “Myid”, “MySecret”

and I have added the callback to app/controllers/callbacks_controller.rb

def digitalocean
    @user = User.from_omniauth(request.env["omniauth.auth"])
    logger.debug "user: @user"
    sign_in_and_redirect @user

However, when I link to DigitalOcean from my application home page and then click on the “Authorize Application” from this page on DigitalOcaen’s site — , I am getting this error in my log

E, [2016-01-24T14:56:26.493450 #36584] ERROR -- omniauth: (digitalocean) Authentication failure! invalid_credentials: OAuth2::Error, invalid_grant: The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.

What do I need to configure where to allow things to work properly?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

What version of the omniauth-oauth2 gem do you have installed? It seems there was a change introduced that broke a number of omniauth providers. While we put a workaround in place directly in omniauth-digitalocean, pinning the version of omniauth-oauth2 to 1.3.1 should resolve the problem. In your Gemfile, use:

gem 'omniauth-oauth2', '~> 1.3.1'

Let us know if that resolves the problem for you!