OAuth2 with intridea ruby gem

前端 未结 1 1397
自闭症患者
自闭症患者 2021-01-14 09:35

I have the following code:

token = client.auth_code.get_token(code, :redirect_uri => \'http://localhost:3000\')
response = token.get(\'https://api.foursqu         


        
相关标签:
1条回答
  • 2021-01-14 10:24

    There seems to be a problem how the oauth2 gem passes variabels inside the objects so mode and param_name seems to be lost on the way. A solution to the problem would be to create a new AccessToken object with the correct parameters instead of using the shorthand. This example is tested against Foursquares api and it works.

    require "oauth2"
    
    client = OAuth2::Client.new(
      "CLIENT_ID",
      "CLIENT_SECRET", 
      :authorize_url => "/oauth2/authorize", 
      :token_url => "/oauth2/access_token", 
      :site => "https://foursquare.com/"
    )
    
    puts client.auth_code.authorize_url(:redirect_uri => "http://localhost:4000")
    
    code = gets.chomp
    
    token = client.auth_code.get_token(code, :redirect_uri => "http://localhost:4000")
    
    token = OAuth2::AccessToken.new(client, token.token, {
      :mode => :query,
      :param_name => "oauth_token",
    })
    
    response = token.get('https://api.foursquare.com/v2/users/self/checkins')
    
    puts response.body
    
    0 讨论(0)
提交回复
热议问题