[英]How can I get oauth token and oauth token secret using the ruby omniauth-twitter gem?
我設置我的應用程序類似於這里的教程 - http://railscasts.com/episodes/235-devise-and-omniauth-revised 。 如果你無法訪問它,下面是我的代碼
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
用戶模型
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
現在我想知道如何獲取經過身份驗證的用戶的oauth令牌和oauth令牌密鑰?
謝謝
如果要查看某個提供程序返回的信息,請將其作為回調控制器的第一行:
raise env["omniauth.auth"].to_yaml
您將能夠看到可以在auth.credentials.token
和auth.credentials.secret
訪問auth.credentials.secret
。
編輯:現在Rails 4使用better_errors gem,這種檢查omniauth哈希的方法不再有效。 現在更好的方法是:
render :text => "<pre>" + env["omniauth.auth"].to_yaml and return
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.