Ami*_*mad 12 ruby-on-rails omniauth ruby-on-rails-4 doorkeeper
我正在使用Doorkeeper作为我的Rails应用程序,我正在尝试这样做,当用户从门卫提供商退出时,用户将自动从所有应用程序注销.
默认情况下,当用户从应用程序注销时,他仍将在门卫提供商应用程序中登录.
这是我的门卫提供商的会话控制器.
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
Run Code Online (Sandbox Code Playgroud)
这是我的一个应用程序的会话控制器:
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
Run Code Online (Sandbox Code Playgroud)
我为Doorkeeper提供商应用程序编写了自己的用户身份验证,但我使用了Devise来连接我的应用程序连接到我的Doorkepeer提供程序应用程序.
目前,当我从我的门卫应用程序退出时,我仍然在我的其他应用程序登录.那么如何让我从门卫那里退出,这也会让我从所有应用中退出?
您必须从 Doorkeeper 应用程序向每个客户端应用程序发送 API 调用,告诉它们删除特定用户的会话,或者您需要让客户端应用程序定期查询 Doorkeeper 应用程序以确保会话或访问令牌仍然存在积极的。后者可能是更好的策略,尽管它最终会进行更多的 API 调用。