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

Inherits:
Object
  • Object
show all
Includes:
Benchmarking, Logging, Meter
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 Meter

#caller_name, #metric, #timing, #track

Methods included from Logging

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

Methods included from Benchmarking

#benchmark

Constructor Details

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

Returns a new instance of AfterFetch.



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

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#passportObject (readonly)

Returns the value of attribute passport.



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

def passport
  @passport
end

#wardenObject (readonly)

Returns the value of attribute warden.



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

def warden
  @warden
end

Class Method Details

.activate(warden_options) ⇒ Object



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

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



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

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 :timeout, timeout_ms: verifier.human_readable_timeout_in_ms
  Operations.failure :server_request_timed_out

rescue => exception
  ::SSO.config.exception_handler.call exception
  Operations.failure :client_exception_caught
end