Class: MnUtilsAuth::Sso
- Inherits:
-
Object
- Object
- MnUtilsAuth::Sso
- Includes:
- Singleton
- Defined in:
- lib/mn_utils_gem/sso.rb
Constant Summary collapse
- SSO_COOKIE_NAME =
:mnsso.freeze
- SSO_COOKIE_VALUE_PREFIX =
"#{SSO_COOKIE_NAME}_".freeze
Instance Method Summary collapse
- #delete_sso(cookies) ⇒ Object
- #get_sso(cookies) ⇒ Object
- #get_sso_user_id(cookies) ⇒ Object
-
#initialize ⇒ Sso
constructor
A new instance of Sso.
- #set_sso(cookies, user_id, other_attributes = {}) ⇒ Object
Constructor Details
#initialize ⇒ Sso
Returns a new instance of Sso.
12 13 14 |
# File 'lib/mn_utils_gem/sso.rb', line 12 def initialize @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT) end |
Instance Method Details
#delete_sso(cookies) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/mn_utils_gem/sso.rb', line 53 def delete_sso() if [SSO_COOKIE_NAME] redis_server.del([SSO_COOKIE_NAME]) .delete SSO_COOKIE_NAME end if RequestStore.store[:sso] RequestStore.store[:sso] = nil end end |
#get_sso(cookies) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mn_utils_gem/sso.rb', line 25 def get_sso() return RequestStore.store[:sso] if RequestStore.store[:sso] return nil if .nil? || [SSO_COOKIE_NAME].nil? || redis_server.nil? json = redis_server.get([SSO_COOKIE_NAME].to_s) return nil if json.nil? parsed = JSON.parse(json, symbolize_names: true) return nil unless parsed.is_a?(Hash) RequestStore.store[:sso] = parsed parsed rescue Exception => e @logger.error e nil end |
#get_sso_user_id(cookies) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/mn_utils_gem/sso.rb', line 16 def get_sso_user_id() parsed = get_sso return nil if parsed.nil? parsed[:user_id] rescue Exception => e @logger.error e nil end |
#set_sso(cookies, user_id, other_attributes = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mn_utils_gem/sso.rb', line 39 def set_sso(, user_id, other_attributes = {}) @logger.debug "in set_sso 1" return if .nil? || user_id.blank? || redis_server.nil? || RequestStore.store[:sso] @logger.debug "in set_sso 2" if [SSO_COOKIE_NAME].nil? @logger.debug "in set_sso 3 #{cookies[SSO_COOKIE_NAME]}" = @logger.debug "in set_sso 4 #{cookie}" value = other_attributes.reverse_merge({ user_id: user_id }) redis_server.set(, JSON[value]) RequestStore.store[:sso] = value end end |