OmniAuth 的起源 - /auth/facebook 是从哪里调用的

发布于 2025-01-04 07:37:28 字数 388 浏览 3 评论 0原文

我使用 OmniAuth 作为让用户将其社交网络链接到系统的一种方式。因此,我的路线中有常见的匹配 '/auth/:provider/callback', to: 'authentications#create'

这很好,我将特定用户的信息存储在表中。但是,我有另一种使用 OmniAuth 的方法,该方法不应与此方法重叠。用户可以使用对 /auth/facebook 的调用来登录系统,因此我不仅应该将该信息存储到身份验证表中,还应该将用户登录到系统中。

另一方面,已登录的用户可能只想链接他/她的 Facebook 帐户而不登录,但调用将针对相同的 /auth/facebook 进行。所以我的问题是:我如何才能发现对 auth/facebook 的调用是从哪里完成的?

I'm using OmniAuth as a way to let users link their social networks into a system. So I have the common match '/auth/:provider/callback', to: 'authentications#create' in my routes.

This is fine, and I store that info for a particular user in a table. However, I have another way of using OmniAuth that should not overlap this one. The users can use a call to /auth/facebook to log into the system and therefore I should not just store that information into the authentications table, but also log the user into the system.

On the other hand, a user that is logged in might just want to link his/her Facebook account without logging in but the call will be done to the same /auth/facebook. So my question is: How can I discover where that call to auth/facebook was done from?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧话新听 2025-01-11 07:37:28

一个想法是在您的身份验证控制器中添加一个 before_filter,它只是检查用户是否已经登录。 #sign_in? 可能看起来像这样:

def sign_in?
 if @oauth.provider == 'facebook'
   if current_user?
     # then lets associate this facebook credentials with the logged-in user.
   else
     # user isn't logged in, so let's do that
     sign_in(@authentication.account)
   end
 end
end

An idea would be to have a before_filter in your authentications controller, which simply checks if the user is already signed-in. #sign_in? might look something like this:

def sign_in?
 if @oauth.provider == 'facebook'
   if current_user?
     # then lets associate this facebook credentials with the logged-in user.
   else
     # user isn't logged in, so let's do that
     sign_in(@authentication.account)
   end
 end
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文