class HaveAPI::Authentication::Basic::Provider
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
Public Instance Methods
Source
# File lib/haveapi/authentication/basic/provider.rb, line 22 def authenticate(request) user = nil auth = Rack::Auth::Basic::Request.new(request.env) if auth.provided? && auth.basic? && auth.credentials begin user = find_user(request, *auth.credentials) rescue HaveAPI::AuthenticationError user = nil end end user end
Source
# File lib/haveapi/authentication/basic/provider.rb, line 37 def describe { description: 'Authentication using HTTP basic. Username and password is passed ' \ 'via HTTP header. Its use is forbidden from web browsers.' } end
Protected Instance Methods
Source
# File lib/haveapi/authentication/basic/provider.rb, line 48 def find_user(request, username, password); end
Reimplement this method. It has to return an authenticated user or nil.