ruby-on-rails – 从Doorkeeper提供商的多个应用程序单点登出

我正在使用Doorkeeper作为我的Rails应用程序,而且我试图让用户从门卫提供商登出后,用户自动退出所有应用程序.

认情况下,当用户从应用程序中注销时,他仍然会在doorkeeper提供商应用程序中登录.

这是我的Doorkeeper提供商的会话控制器.

class SessionsController < ApplicationController
  def new
    redirect_to root_path if current_user
    session[:return_to] = params[:return_to] if params[:return_to]
  end

  def create
    user = User.find_by_email(params[:email])
    if user && user.authenticate(params[:password])
      session[:user_id] = user.id
      if session[:return_to]
        redirect_to session[:return_to]
        session[:return_to] = nil
      else
        redirect_to root_path

      end
    else
      flash.Now.alert = "Email or password is invalid"
      render "new"
    end
  end

  def destroy
    session[:user_id] = nil
    flash[:alert] = "Sign Out successfully"
    redirect_to new_session_path
  end
end

这是我的一个应用程序的会话控制器:

class SessionsController < ApplicationController
  def create
    auth = request.env["omniauth.auth"]
    user = User.find_by_provider_and_uid(auth["provider"],auth["uid"]) || User.create_with_omniauth(auth)
    session[:user_id] = user.id
    session[:access_token] = auth["credentials"]["token"]
    redirect_to root_url
  end

  def destroy
    session[:user_id] = nil
    session[:access_token] = nil
    redirect_to root_url
  end
end

我为Doorkeeper提供程序应用程序编写了自己的用户身份验证,但是我使用Devise为自己的应用程序连接到我的Doorkepeer提供程序应用程序.

目前,当我从我的Doorkeeper应用程序登出时,我仍然在我的其他应用程序登录.那么我该如何做,以便我从Doorkeeper登出,这将使我从所有的应用程序登出?

解决方法

您必须从Doorkeeper应用程序发送API呼叫给每个客户端应用程序,告诉他们删除特定用户的会话,或者您需要定期让您的客户端应用程序查询doorkeeper应用程序,以确保会话或访问令牌仍然活性.后者可能是更好的策略,尽管它最终会产生更多的API调用.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...