class HaveAPI::Authentication::Base

Base class for authentication providers.

Attributes

name[R]

@return [Symbol]

Public Class Methods

auth_method(v = nil) click to toggle source

Get or set auth method name @param v [Symbol, nil] @return [Symbol]

# File lib/haveapi/authentication/base.rb, line 8
def self.auth_method(v = nil)
  if v
    @auth_method = v
  else
    @auth_method || name.split('::').last.underscore.to_sym
  end
end
inherited(subclass) click to toggle source
Calls superclass method
# File lib/haveapi/authentication/base.rb, line 16
def self.inherited(subclass)
  super
  subclass.send(:instance_variable_set, '@auth_method', @auth_method)
end
new(server, v) click to toggle source
# File lib/haveapi/authentication/base.rb, line 24
def initialize(server, v)
  @name = self.class.auth_method
  @server = server
  @version = v
  setup
end

Public Instance Methods

authenticate(request) click to toggle source

Reimplement this method in your authentication provider. ‘request` is passed directly from Sinatra.

# File lib/haveapi/authentication/base.rb, line 43
def authenticate(request); end
describe() click to toggle source

Reimplement to describe provider.

# File lib/haveapi/authentication/base.rb, line 46
def describe
  {}
end
register_routes(sinatra, prefix) click to toggle source

Register custom path handlers in sinatra @param sinatra [Sinatra::Base] @param prefix [String]

# File lib/haveapi/authentication/base.rb, line 34
def register_routes(sinatra, prefix); end
resource_module() click to toggle source

@return [Module, nil]

# File lib/haveapi/authentication/base.rb, line 37
def resource_module
  nil
end

Protected Instance Methods

deny() click to toggle source

Immediately return from authentication chain. User is not allowed to authenticate.

# File lib/haveapi/authentication/base.rb, line 57
def deny
  throw(:return)
end
setup() click to toggle source

Called during API mount.

# File lib/haveapi/authentication/base.rb, line 53
def setup; end