Class: Devise::G5::AuthPasswordValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/devise_g5_authenticatable/g5/auth_password_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(authenticatable_model) ⇒ AuthPasswordValidator

Returns a new instance of AuthPasswordValidator.



8
9
10
# File 'lib/devise_g5_authenticatable/g5/auth_password_validator.rb', line 8

def initialize(authenticatable_model)
  @model = authenticatable_model
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



6
7
8
# File 'lib/devise_g5_authenticatable/g5/auth_password_validator.rb', line 6

def model
  @model
end

Instance Method Details

#valid_password?(password) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
# File 'lib/devise_g5_authenticatable/g5/auth_password_validator.rb', line 12

def valid_password?(password)
  begin
    auth_user = auth_client(password).me
  rescue OAuth2::Error => error
    raise unless error.code == 'invalid_resource_owner'
  rescue RuntimeError => error
    raise unless error.message =~ /Insufficient credentials/
  end

  !auth_user.nil?
end