class Devise::G5::AuthPasswordValidator

Validate a user's G5 Auth credentials

Attributes

model[R]

Public Class Methods

new(authenticatable_model) click to toggle source
# File lib/devise_g5_authenticatable/g5/auth_password_validator.rb, line 11
def initialize(authenticatable_model)
  @model = authenticatable_model
end

Public Instance Methods

valid_password?(password) click to toggle source
# 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

Private Instance Methods

auth_client(password) click to toggle source
# File lib/devise_g5_authenticatable/g5/auth_password_validator.rb, line 29
def auth_client(password)
  G5AuthenticationClient::Client.new(username: model.email,
                                     password: password)
end