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

January 24, 2016 5.9k views
API Applications


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?

1 Answer

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!

Have another answer? Share your knowledge.

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