OmniAuth动态回调URL验证特定对象而不是current_user [英] OmniAuth dynamic callback url to authenticate particular objects instead of current_user

查看:57
本文介绍了OmniAuth动态回调URL验证特定对象而不是current_user的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有用户和项目模型.用户和项目与HABTM相关.我的设置实际上比这要复杂一些,但是出于我的问题,我认为这可以做到.

Say I have the models User and Project. Users and projects are HABTM-associated. My setup is actually a bit more complicated than this, but I think for the purposes of my question this will do.

现在,我想使用omniauth通过Twitter,Facebook来对特定项目进行身份验证,这有什么用.我已经找到了如何定义omniauth path_prefix的方法,但是我不知道如何传递这样的变量:config.path_prefix = 'projects/:project_id/auth',更不用说创建自定义回调URL了,例如project/:project_id/auth/twitter/callback

Now, I want to use omniauth to authenticate a particular project with Twitter, Facebook, what have you. I've figured out how to define my omniauth path_prefix, but I don't know how I could pass in a variable like so: config.path_prefix = 'projects/:project_id/auth', much less make a custom callback url like project/:project_id/auth/twitter/callback.

推荐答案

为了后代的缘故,我是这样解决的:

For posterity's sake, I solved it this way:

我在项目控制器中添加了auth方法,该方法设置了会话变量session[:auth_project_id],然后重定向到auth/ + params[:provider].

I added an auth method to my projects controller, which set a session variable session[:auth_project_id] and then redirectes to auth/ + params[:provider].

在回调控制器authentications中,我使用@project = Project.find(session[:auth_project_id])获取了项目,创建了身份验证,然后使用session[:auth_project_id] = nil取消了会话变量的设置.

In my callback controller authentications, I got my project with @project = Project.find(session[:auth_project_id]), created the authentication, and then session[:auth_project_id] = nil to unset the session variable.

这篇关于OmniAuth动态回调URL验证特定对象而不是current_user的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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