Signet Oauth2 Basic Auth not working with Get Response api

986 Views Asked by At

I am trying to use Signet::Oauth2::Client to get an access token from getresponse.com

client = Signet::OAuth2::Client.new(
  client_id: GET_RESPONSE_CLIENT_ID,
  client_secret: GET_RESPONSE_CLIENT_SECRET,
  token_credential_uri: 'https://api.getresponse.com/v3/token',
  redirect_uri: my_callback_uri,
  grant_type: 'authorization_code',
  code: the_code_i_got_from_get_response
)
response = client.fetch_access_token!

However Get Response always returns this:

{"error"=>"invalid_client", "error_description"=>"Client credentials were not found in the headers"}

I have done this request with curl easily. It returns successfully with the tokens.

curl -v -u client_id:client_secret https://api.getresponse.com/v3/token -d "grant_type=authorization_code&code=abc123thisisthecode&redirect_uri=https://myserver.com/callback"

I have tried a million things and read the client source but I didn't see want I am doing wrong. I will continue to read the docs but in the meantime I thought I would ask the pros here at stackoverflow. Does anyone know the answer? Here is the api docs https://apidocs.getresponse.com/v3/oauth2

1

There are 1 best solutions below

0
Sumit Gautam On

Ran into similar issues. I following steps below and worked for me.

Step.1 Load your credentials obtained from google developers console.

  client_secrets = Google::APIClient::ClientSecrets.load("#{Rails.root}/zenledger_ga_secrets.json")
  auth_client = client_secrets.to_authorization

  auth_client.update!(
    :scope => 'email profile https://www.googleapis.com/auth/analytics.readonly',
    :grant_type => "authoriation_code",
    :response_type => 'code',
    :redirect_uri => 'http://localhost:3001/admin/oauth2callback',
    :additional_parameters => {
      "access_type" => "offline",         # offline access
      "include_granted_scopes" => "true",  # incremental auth
    }
  )

Step 2. Load up your Signet client to fetch the access token necessary for accessing required APIs.

    @client = Signet::OAuth2::Client.new(
    :authorization_uri => 'https://accounts.google.com/o/oauth2/auth',
    :token_credential_uri =>  'https://oauth2.googleapis.com/token',
    :client_id => ''xxxxxxxxxx',
    :client_secret => 'xxxxxxxxxx',
    :scope => 'email profile',
    :redirect_uri => 'http://localhost/admin/oauth2callback'
  )
  @client.code = auth_code
  @client.fetch_access_token!

Note auth_code is sent by Google in the redirect URL. You can obtain them as param in your oauth2callback url in your application.