0

I'm using Ruby on Rails for get a token using Oauth2 for Clio app. So, I install the following gem:

gem 'oauth2'

And this is my code:

client = OAuth2::Client.new(CLIENT_KEY_CLIO, CLIENT_SECRET_CLIO, site: SITE)
token = client.auth_code.get_token(code, :redirect_uri => 'http://127.0.0.1/approval')
return token

Where the variable code is send by frontend. And is a code that the clio app send when user make a login in his clio account. But the redirect_uri URL did not exist. However, I created it and the only thing it does is get the code parameter and return it.

Still, it does not work. According to the documentation I can put the default URL that is https://app.clio.com/oauth/approval but it does not work either. I always have this error:

{
  "error": "invalid_grant",
  "error_description": "The provided access grant is invalid, expired, or revoked (e.g. invalid assertion, expired authorization token, bad end-user password credentials, or mismatching authorization code and redirection URI)."
}

I remember that this error happened before. But it was solved when the redirect_uri value was changed.

What is wrong with the redirect_uri? Could someone provide me with an example of Oauth2 requests?

Dvex
  • 921
  • 2
  • 11
  • 35

2 Answers2

0

seems like it should work readin other threads. Add port to your calback url like or what port your app is running http://127.0.0.1:3000/approval

Imre Raudsepp
  • 1,068
  • 8
  • 8
0

In redirect_uri I needed the URL that generate code variable. So, if http://127.0.0.1/approval exists and is accessible by internet but not generate the code so, it's not working. But if I put the correct url that generate code, all it's works.

client = OAuth2::Client.new(CLIENT_KEY_CLIO, CLIENT_SECRET_CLIO, site: SITE)
token = client.auth_code.get_token(code, :redirect_uri => 'http://address_generate_code_from_frontend')
return token
Dvex
  • 921
  • 2
  • 11
  • 35