class Warden::Cognito::TokenAuthenticatableStrategy

Constants

METHOD

Attributes

helper[R]

Public Class Methods

new(env, scope = nil) click to toggle source
Calls superclass method
# File lib/warden/cognito/token_authenticatable_strategy.rb, line 11
def initialize(env, scope = nil)
  super
  @helper = UserHelper.new
end

Public Instance Methods

authenticate!() click to toggle source
# 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?() click to toggle source
# File lib/warden/cognito/token_authenticatable_strategy.rb, line 16
def valid?
  token_decoder.validate!
rescue ::JWT::ExpiredSignature
  true
rescue StandardError
  false
end

Private Instance Methods

authorization_header() click to toggle source
# File lib/warden/cognito/token_authenticatable_strategy.rb, line 64
def authorization_header
  env['HTTP_AUTHORIZATION']
end
cognito_user() click to toggle source
# File lib/warden/cognito/token_authenticatable_strategy.rb, line 37
def cognito_user
  token_decoder.cognito_user
end
extract_token() click to toggle source
# File lib/warden/cognito/token_authenticatable_strategy.rb, line 57
def extract_token
  return nil unless authorization_header

  method, token = authorization_header.split
  method == METHOD ? token : nil
end
local_user() click to toggle source
# File lib/warden/cognito/token_authenticatable_strategy.rb, line 41
def local_user
  LocalUserMapper.find token_decoder
end
pool_identifier() click to toggle source
# File lib/warden/cognito/token_authenticatable_strategy.rb, line 49
def pool_identifier
  env['HTTP_X_AUTHORIZATION_POOL_IDENTIFIER']
end
token() click to toggle source
# File lib/warden/cognito/token_authenticatable_strategy.rb, line 53
def token
  @token ||= extract_token
end
token_decoder() click to toggle source
# File lib/warden/cognito/token_authenticatable_strategy.rb, line 45
def token_decoder
  @token_decoder ||= TokenDecoder.new(token, pool_identifier)
end