class HaveAPI::Authentication::Token::Config

Configuration for {HaveAPI::Authentication::Token::Provider}

Create a subclass and use with {HaveAPI::Authentication::Token#with_config}.

Public Class Methods

action(name, &block) click to toggle source

@param name [Symbol]

# File lib/haveapi/authentication/token/config.rb, line 40
def action(name, &block)
  @actions ||= {}
  @actions[name] = ActionConfig.new(block)
end
actions() click to toggle source

@return [Hash]

# File lib/haveapi/authentication/token/config.rb, line 46
def actions
  @actions || {}
end
http_header(header = nil) click to toggle source

HTTP header that is searched for token @param header [String, nil] @return [String]

# File lib/haveapi/authentication/token/config.rb, line 53
def http_header(header = nil)
  if header
    @http_header = header
  else
    @http_header || 'X-HaveAPI-Auth-Token'
  end
end
inherited(subclass) click to toggle source
Calls superclass method
# File lib/haveapi/authentication/token/config.rb, line 72
def inherited(subclass)
  super

  # Default request
  subclass.request do
    input do
      string :user, label: 'User', required: true
      password :password, label: 'Password', required: true
      string :scope, label: 'Scope', default: 'all', fill: true
    end

    handle do
      raise NotImplementedError
    end
  end

  # Default renew and revoke
  %i[renew revoke].each do |name|
    subclass.send(name) do
      handle do
        raise NotImplementedError
      end
    end
  end
end
new(server, v) click to toggle source
# File lib/haveapi/authentication/token/config.rb, line 99
def initialize(server, v)
  @server = server
  @version = v
end
query_parameter(param = nil) click to toggle source

Query parameter searched for token @param param [Symbol] @return [Symbol]

# File lib/haveapi/authentication/token/config.rb, line 64
def query_parameter(param = nil)
  if param
    @query_param = param
  else
    @query_param || :_auth_token
  end
end
request(&block) click to toggle source

Configure token request action

# File lib/haveapi/authentication/token/config.rb, line 9
def request(&block)
  if block
    if @request
      @request.update(block)
    else
      @request = ActionConfig.new(block)
    end
  else
    @request
  end
end

Public Instance Methods

find_user_by_token(request, token) click to toggle source

Authenticate request by ‘token`

Return user object or nil. If the token was created as auto-renewable, this method is responsible for its renewal. Must be implemented. @param request [Sinatra::Request] @param token [String] @return [Object, nil]

# File lib/haveapi/authentication/token/config.rb, line 113
def find_user_by_token(request, token); end