带有Intridea红宝石宝石的OAuth2 [英] OAuth2 with intridea ruby gem

查看:66
本文介绍了带有Intridea红宝石宝石的OAuth2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

token = client.auth_code.get_token(code, :redirect_uri => 'http://localhost:3000')
response = token.get('https://api.foursquare.com/v2/users/self/checkins', {:mode => :query})

问题是,无论我指定什么:mode,我总是在Authorization标头中获得Bearer令牌.有问题的代码是一个私有的set_token,它始终取决于默认的:mode,始终为:header.

The problem is that no matter what :mode I specify I always get a Bearer token in Authorization header. The code in question is a private set_token which always depends on the default :mode which is always :header.

我用错了吗?

谢谢!

推荐答案

oauth2 gem如何在对象内部传递变量,似乎存在问题,因此mode和param_name似乎丢失了.解决该问题的方法是使用正确的参数创建一个新的AccessToken对象,而不是使用简写形式.此示例已经针对Foursquares api进行了测试,并且可以正常工作.

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

这篇关于带有Intridea红宝石宝石的OAuth2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆