Class: SSO::Client::Warden::Hooks::AfterFetch

Inherits:
Object
  • Object
show all
Includes:
Benchmarking, Logging
Defined in:
lib/sso/client/warden/hooks/after_fetch.rb

Overview

This is a helpful ‘Warden::Manager.after_fetch` hook for Alpha and Beta. Whenever Carol is fetched out of the session, we also verify her passport.

Usage:

SSO::Client::Warden::Hooks::AfterFetch.activate scope: :vip

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Benchmarking

#benchmark

Methods included from Logging

#debug, #error, #fatal, #info, #logger, #progname, #warn

Constructor Details

#initialize(passport:, warden:, options:) ⇒ AfterFetch

Returns a new instance of AfterFetch.



26
27
28
# File 'lib/sso/client/warden/hooks/after_fetch.rb', line 26

def initialize(passport:, warden:, options:)
  @passport, @warden, @options = passport, warden, options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



16
17
18
# File 'lib/sso/client/warden/hooks/after_fetch.rb', line 16

def options
  @options
end

#passportObject (readonly)

Returns the value of attribute passport.



16
17
18
# File 'lib/sso/client/warden/hooks/after_fetch.rb', line 16

def passport
  @passport
end

#wardenObject (readonly)

Returns the value of attribute warden.



16
17
18
# File 'lib/sso/client/warden/hooks/after_fetch.rb', line 16

def warden
  @warden
end

Class Method Details

.activate(warden_options) ⇒ Object



20
21
22
23
24
# File 'lib/sso/client/warden/hooks/after_fetch.rb', line 20

def self.activate(warden_options)
  ::Warden::Manager.after_fetch(warden_options) do |passport, warden, options|
    ::SSO::Client::Warden::Hooks::AfterFetch.new(passport: passport, warden: warden, options: options).call
  end
end

Instance Method Details

#callObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sso/client/warden/hooks/after_fetch.rb', line 30

def call
  return unless passport.is_a?(::SSO::Client::Passport)
  verify

rescue Timeout::Error
  error { 'SSO Server timed out. Continuing with last known authentication/authorization...' }
  # meter status: :timeout, scope: scope, passport_id: user.passport_id, timeout_ms: human_readable_timeout_in_ms

rescue => exception
  ::SSO.config.exception_handler.call exception
end