From 059cddf9bbfed265479607b378d80d97b9c7ae0c Mon Sep 17 00:00:00 2001 From: Bohung Date: Thu, 28 Oct 2021 09:06:52 +0800 Subject: [PATCH] Add logout url. --- app/controllers/sso_login_box_controller.rb | 11 +++++++++++ lib/sso_login_box.rb | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/app/controllers/sso_login_box_controller.rb b/app/controllers/sso_login_box_controller.rb index 8774cfa..53e2a0f 100644 --- a/app/controllers/sso_login_box_controller.rb +++ b/app/controllers/sso_login_box_controller.rb @@ -1,6 +1,16 @@ class SsoLoginBoxController < SessionsController require 'openssl' OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE + def self.logout #Token Revocation + session = OrbitHelper.request.session + if session[:sso_token] + token_connection = Faraday.new 'https://cas.ccu.edu.tw/oauth2.0/revoke' + token_response = token_connection.post do |request| + request.params['token'] = session[:sso_token] + request.params['token_type_hint'] = 'access_token' + end + end + end def oauth2_auth_page session[:referer_url] = params[:referer_url] redirect_to "https://cas.ccu.edu.tw/oauth2.0/authorize?response_type=#{ENV['RESPONSE_TYPE']}&client_id=#{ENV['APP_ID']}&redirect_uri=#{ENV['REDIRECT_URI']}" @@ -29,6 +39,7 @@ class SsoLoginBoxController < SessionsController user_name = JSON.parse(account_response.body)['id'] user = User.find_by(user_name: user_name) rescue nil if !user.nil? + session[:sso_token] = token session[:user_id] = user.id session[:login_referer] = nil if session[:referer_url].present? diff --git a/lib/sso_login_box.rb b/lib/sso_login_box.rb index 37b7c4e..58cc2ff 100644 --- a/lib/sso_login_box.rb +++ b/lib/sso_login_box.rb @@ -1,4 +1,10 @@ require "sso_login_box/engine" module SsoLoginBox + # def self.controller_name #if defined, call controller's logout method + # "SsoLoginBoxController" + # end + def self.logout_url + "https://cas.ccu.edu.tw/logout" + end end