我可以将Facebook ID +令牌传递给Rails Devise服务以验证用户身份吗?

| 我有一个运行Devise + OmniAuth的Rails Web服务。我有用户在移动设备上针对Facebook Connect进行身份验证。然后,我希望移动设备与我们的Web服务建立会话。我需要从移动客户端传递到设备的哪些内容才能建立此会话?在Rails方面是否有代码示例,说明如何处理从facebook->移动-> Web服务传递的id + token?     
已邀请:
        我还没有找到这样做的好方法。我也没有使用
:omniauthable
,而是分别使用OmniAuth和Devise,这在Railscast情节中可见,那里有两个表
users
authentications
。这有点hacky,仅适用于Facebook。 基本上,通过SSL或类似方式将您的access_token从iPhone发送到服务器。您必须先与OmniAuth进行检查,如果您被授予访问权限,则可以通过以下操作手动使用OmniAuth创建会话: 通过这样做,我确实获得了一些工作:
FB = OmniAuth::Strategies::Facebook.new(\"nothing\") 

client = ::OAuth2::Client.new(\"nothing\", \"nothing\", FB.client_options) 

cached_token = \"app_id_part|session_id_part|token_part\" # or maybe you sent it from the iPhone
access_token = ::OAuth2::AccessToken.new(client, cached_token)  

FB.instance_variable_set(\"@access_token\", access_token) 

FB.auth_hash 
# You will either get a hash or get this error:
# OAuth2::AccessDenied: Received HTTP 401 during request.
之后,您需要通过Authentications表查找用户信息,以查找用户:
@user = Authentication.where(:uid => FB.auth_hash[\"uid\"], :provider => \"facebook\").first.user
现在我们创建一个会话:
sign_in_and_redirect(:user, @user)

# or, perhaps

sign_in(@user, :bypass => true)
    
        我在这方面遇到了困难,因此我将在这里向其他人发布我的答案。这是受到以上Dex \'s答案的启发。
FB = OmniAuth::Strategies::Facebook.new(\"APP_ID\", \"APP_SECRET\") 
client = OAuth2::Client.new(\"APP_ID\", \"APP_SECRET\", FB.options.client_options) 
token = OAuth2::AccessToken.new(client,\'ACCESS_TOKEN\', FB.options.access_token_options)
FB.access_token = token
FB.auth_hash
任何建议,以改善这一点将不胜感激。 上面的代码段允许我通过使用access_token查询facebook来获取auth_hash 我正在使用这个gem:github.com/mkdynamic/omniauth-facebook     

要回复问题请先登录注册