Class: Warden::Cognito::AuthenticatableStrategy

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, scope = nil) ⇒ AuthenticatableStrategy

Returns a new instance of AuthenticatableStrategy.



9
10
11
12
13
# File 'lib/warden/cognito/authenticatable_strategy.rb', line 9

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

Instance Attribute Details

#helperObject (readonly)

Returns the value of attribute helper.



7
8
9
# File 'lib/warden/cognito/authenticatable_strategy.rb', line 7

def helper
  @helper
end

#user_not_found_callbackObject (readonly)

Returns the value of attribute user_not_found_callback.



7
8
9
# File 'lib/warden/cognito/authenticatable_strategy.rb', line 7

def user_not_found_callback
  @user_not_found_callback
end

Instance Method Details

#authenticate!Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/warden/cognito/authenticatable_strategy.rb', line 19

def authenticate!
  attempt = cognito_client.initiate_auth(email, password)

  return fail(:unknow_cognito_response) unless attempt

  user = local_user || trigger_callback(attempt.authentication_result)

  fail!(:unknown_user) unless user.present?
  success!(user)
rescue Aws::CognitoIdentityProvider::Errors::NotAuthorizedException
  fail!(:invalid_login)
rescue StandardError
  fail(:unknow_cognito_response)
end

#valid?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/warden/cognito/authenticatable_strategy.rb', line 15

def valid?
  cognito_authenticable?
end