Class: Devise::G5::AuthPasswordValidator

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

Overview

Validate a user’s G5 Auth credentials

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(authenticatable_model) ⇒ AuthPasswordValidator

Returns a new instance of AuthPasswordValidator.



11
12
13
# File 'lib/devise_g5_authenticatable/g5/auth_password_validator.rb', line 11

def initialize(authenticatable_model)
  @model = authenticatable_model
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



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

def model
  @model
end

Instance Method Details

#valid_password?(password) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/devise_g5_authenticatable/g5/auth_password_validator.rb', line 15

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