我正在构建一个使用Devise gem进行身份验证的Web应用程序(还有一个API),并且还使用Doorkeeper gem进行API部分的身份验证.
问题是现在,当我转到接收Oauth2代码(和登录)的URL时,我被重定向到Web应用程序而不是客户端回调URL.
我需要做的是在正常登录时重定向到Web应用程序,并在使用Oauth时重定向到回调URL.
我该怎么做?我覆盖了Devise会话控制器,但我不知道该怎么做.
这是我的代码:
def new session[:return_to] = params[:return_to] if params[:return_to] resource = build_resource clean_up_passwords(resource) end def create resource = warden.authenticate!(auth_options) sign_in(resource_name,resource) if session[:return_to] redirect_to session[:return_to] session[:return_to] = nil else respond_with resource,:location => after_sign_in_path_for(resource) end end
问题是,Devise似乎忽略了我的重定向逻辑.
请进一步建议.
解决方法
假设你的资源是用户添加会话[:user_return_to] = request.fullpath到resource_owner_authenticator块
例:
resource_owner_authenticator do #raise "Please configure doorkeeper resource_owner_authenticator block located in #{__FILE__}" # Put your resource owner authentication logic here. # Example implementation: session[:user_return_to] = request.fullpath current_user || redirect_to(login_url) end
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。