Devise和OmniAuth记住OAuth [英] Devise and OmniAuth remembering OAuth

查看:133
本文介绍了Devise和OmniAuth记住OAuth的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我刚刚使用Rails 3,Devise和OmniAuth通过 https:/ /github.com/plataformatec/devise/wiki/OmniAuth:-Overview

So, I just got setup using Rails 3, Devise and OmniAuth via https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview.

我通过Facebook成功地认证用户,但他们并不记得尽管标有:

I'm successfully authenticating users via Facebook, but they are not "rememberable" despite being marked with:

devise [...]: rememberable, :omniauthable

我尝试呼叫:

@the_user.remember_me!

...无效。没有cookie被存储/设置,这意味着用户在会话之间不会持久。

...to no avail. No cookie is being stored/set which means the user does not persist across sessions.

有没有人设法获取来自FB的用户通过cookies记住?在我看来,这应该会自动发生。

Has anybody managed to get a user sourced from FB remembered via cookies? In my mind, this should be happening automatically.

感谢你们可能有任何想法或反馈。

Thanks for any ideas or feedback you guys might have.

推荐答案

我同意你会希望Devise在请求到FB之前设置一个会话。我猜这是Devise的一个缺失的功能。

I agree that you would expect Devise to set a session before the request goes to FB. I guess this is a missing feature of Devise.

我自己在使用token_authenticatable时遇到了问题。 api客户端直接调用以下url:

I had the problem myself where I used token_authenticatable. An api client was calling the following url directly:

/users/auth/facebook?auth_token=TnMn7pjfADapMdsafOFIHKgJVgrBEbjKqrubwMXUca0n16m3Hzr7CnrP1s4z

由于我使用token_authenticatable我假设这将登录用户。不幸的是,这并不奏效。要做到这一点,您需要做的是确保用户在进入此路径之前已经登录。你可以用其他方法来做,但最简单的方法是给API客户端(在这种情况下是users / connect / facebook)提供一个不同的URL,这是我添加的路由文件,使其工作(假设你有一个用户模型,并且您没有更改默认值):

Since I was using token_authenticatable i was assuming this would sign in the user. Unfortunately this doesn't work out of the box. What you have to do to get this working is making sure that the user is logged in before it gets to this path. You can do it in other ways, but the easiest way is to give a different url to the API client (in this case "users/connect/facebook". Here is my addition to the routes file that makes it work (assuming you have a user model with devise and you didn't change defaults):

authenticate :user do
  get 'users/connect/:network', :to => redirect("/users/auth/%{network}")
end

这将确保会话正确创建,以便用户在他/她从Facebook返回时被识别。

This will make sure the session is correctly created so the user is being recognized when he/she returns from facebook.

这篇关于Devise和OmniAuth记住OAuth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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