Class: Warden::Cognito::TokenAuthenticatableStrategy

Inherits:
Strategies::Base
  • Object
show all
Defined in:
lib/warden/cognito/token_authenticatable_strategy.rb

Constant Summary collapse

METHOD =
'Bearer'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, scope = nil) ⇒ TokenAuthenticatableStrategy

Returns a new instance of TokenAuthenticatableStrategy.



11
12
13
14
# File 'lib/warden/cognito/token_authenticatable_strategy.rb', line 11

def initialize(env, scope = nil)
  super
  @helper = UserHelper.new
end

Instance Attribute Details

#helperObject (readonly)

Returns the value of attribute helper.



9
10
11
# File 'lib/warden/cognito/token_authenticatable_strategy.rb', line 9

def helper
  @helper
end

Instance Method Details

#authenticate!Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/warden/cognito/token_authenticatable_strategy.rb', line 24

def authenticate!
  user = local_user || UserNotFoundCallback.call(cognito_user, token_decoder.pool_identifier)

  fail!(:unknown_user) unless user.present?
  success!(user)
rescue ::JWT::ExpiredSignature
  fail!(:token_expired)
rescue StandardError
  fail(:unknown_error)
end

#valid?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
# File 'lib/warden/cognito/token_authenticatable_strategy.rb', line 16

def valid?
  token_decoder.validate!
rescue ::JWT::ExpiredSignature
  true
rescue StandardError
  false
end