Class: HaveAPI::Authentication::Basic::Provider

Inherits:
HaveAPI::Authentication::Base show all
Defined in:
lib/haveapi/authentication/basic/provider.rb

Overview

HTTP basic authentication provider.

Example usage:

class MyBasicAuth < HaveAPI::Authentication::Basic::Provider
  protected
  def find_user(request, username, password)
    ::User.find_by(login: username, password: password)
  end
end

Finally put the provider in the authentication chain:

api = HaveAPI.new(...)
...
api.auth_chain << MyBasicAuth

Instance Attribute Summary

Attributes inherited from HaveAPI::Authentication::Base

#name, #resources

Instance Method Summary collapse

Methods inherited from HaveAPI::Authentication::Base

#describe, #initialize

Constructor Details

This class inherits a constructor from HaveAPI::Authentication::Base

Instance Method Details

#authenticate(request) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/haveapi/authentication/basic/provider.rb', line 18

def authenticate(request)
  user = nil

  auth = Rack::Auth::Basic::Request.new(request.env)
  if auth.provided? && auth.basic? && auth.credentials
    user = find_user(request, *auth.credentials)
  end

  user
end