Class: Warden::Cognito::AuthenticatableStrategy
- Inherits:
-
Strategies::Base
- Object
- Strategies::Base
- Warden::Cognito::AuthenticatableStrategy
- Defined in:
- lib/warden/cognito/authenticatable_strategy.rb
Instance Attribute Summary collapse
-
#helper ⇒ Object
readonly
Returns the value of attribute helper.
-
#user_not_found_callback ⇒ Object
readonly
Returns the value of attribute user_not_found_callback.
Instance Method Summary collapse
- #authenticate! ⇒ Object
-
#initialize(env, scope = nil) ⇒ AuthenticatableStrategy
constructor
A new instance of AuthenticatableStrategy.
- #valid? ⇒ Boolean
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
#helper ⇒ Object (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_callback ⇒ Object (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
15 16 17 |
# File 'lib/warden/cognito/authenticatable_strategy.rb', line 15 def valid? cognito_authenticable? end |