[英]How can I get oauth token and oauth token secret using the ruby omniauth-twitter gem?
I setup my app similar to the tutorial here - http://railscasts.com/episodes/235-devise-and-omniauth-revised . 我设置我的应用程序类似于这里的教程 - http://railscasts.com/episodes/235-devise-and-omniauth-revised 。 If you cant access it, below is my code
如果你无法访问它,下面是我的代码
Omniauth controller callback Omniauth控制器回调
def all
user = User.from_omniauth(request.env["omniauth.auth"])
if user.persisted?
flash.notice = "Signed in!"
sign_in_and_redirect user
else
session["devise.user_attributes"] = user.attributes
redirect_to new_user_registration_url
end
end
alias_method :twitter, :all
end
user model 用户模型
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.username = auth.info.nickname
user.name = auth.info.name
end
end
def self.new_with_session(params, session)
if session["devise.user_attributes"]
new(session["devise.user_attributes"], without_protection: true) do |user|
user.attributes = params
user.valid?
end
else
super
end
end
Now I am wondering how do I obtain the authenticated user's oauth token and oauth token secret? 现在我想知道如何获取经过身份验证的用户的oauth令牌和oauth令牌密钥?
Thanks 谢谢
If you want to take a look at the information returned by a certain provider, put this as the first line of your callback controller: 如果要查看某个提供程序返回的信息,请将其作为回调控制器的第一行:
raise env["omniauth.auth"].to_yaml
You'll be able to see that the information you want can be accessed in auth.credentials.token
and auth.credentials.secret
. 您将能够看到可以在
auth.credentials.token
和auth.credentials.secret
访问auth.credentials.secret
。
EDIT: Now that Rails 4 uses the better_errors gem, this method of inspecting the omniauth hash no longer works so well. 编辑:现在Rails 4使用better_errors gem,这种检查omniauth哈希的方法不再有效。 A better way now is:
现在更好的方法是:
render :text => "<pre>" + env["omniauth.auth"].to_yaml and return
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.