如何从omniauth回调响应中获取access_token? [英] How do I get the access_token from the omniauth callback response?
本文介绍了如何从omniauth回调响应中获取access_token?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在下面的控制器响应(创建动作)中检索access_token和access_token_secret.我该怎么做呢?
I need to retrieve the access_token and access_token_secret in the controller response(create action) below. How do I do this?
routes.rb
routes.rb
match "/auth/:provider/callback" => "sessions#create", via: :get
视图
<%= link_to "Sign in with LinkedIn", "/auth/linkedin" %>
会话控制器.
def create
auth = request.env["omniauth.auth"]
user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth)
session[:user_id] = user.id
redirect_to root_url
end
推荐答案
我设法解决了这个问题.答案在 auth哈希模式中.
I managed to sort this out. The answer was in the auth hash schema.
access_token = auth["credentials"]["token"]
access_secret = auth["credentials"]["secret"]
我将此插入到控制器中以检索并保存用户个人资料.巨大的成功!
I inserted this into my controller to retrieve and save the user profile. Great success!
这篇关于如何从omniauth回调响应中获取access_token?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文