11

I'm using the Oauth2 Gem to connect to a service.

I can receive the authorisation code but when I use that code to retrieve the user token, I get Faraday::ConnectionFailed (end of file reached):

Most of the other problems are attributed to out of date certificates. However this error still persists when I deploy to Heroku.

client = OAuth2::Client.new(client_id, client_secret, :site => 'https://auth.mxit.com', :authorize_url => '/authorize', :token_url => '/token')

auth_code1 = client.auth_code.authorize_url(:redirect_uri => root_url+'oauth2/callback', :scope => 'message/send')

auth_code1 =params[:code]

base_code = Base64.encode64(client_id+' : '+client_secret)

token = client.auth_code.get_token(auth_code1, :redirect_uri => root_url+'oauth2', :grant_type =>'authorization_code', :headers => {'Content-Type' => 'application/x-www-form-urlencoded','Authorization' => 'Basic'+base_code })
Andrew Lynch
  • 1,297
  • 3
  • 14
  • 25

1 Answers1

0

Not sure if this works, but I read that problem could come from the Accept-Encoding request header no being set (must be set to identity). Try this :

token = client.auth_code.get_token(auth_code1,
  redirect_uri: root_url + 'oauth2',
  grant_type: 'authorization_code',
  headers: {
    'Content-Type' => 'application/x-www-form-urlencoded',
    'Authorization' => 'Basic' + base_code,
    'Accept-Encoding' => 'identity' # here
  }
)
Ghis
  • 845
  • 10
  • 16