Class: HaveAPI::Authentication::Token::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/haveapi/authentication/token/config.rb

Overview

Configuration for Provider

Create a subclass and use with #with_config.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, v) ⇒ Config

Returns a new instance of Config.



99
100
101
102
# File 'lib/haveapi/authentication/token/config.rb', line 99

def initialize(server, v)
  @server = server
  @version = v
end

Class Method Details

.action(name, &block) ⇒ Object

Parameters:

  • name (Symbol)


40
41
42
43
# File 'lib/haveapi/authentication/token/config.rb', line 40

def action(name, &block)
  @actions ||= {}
  @actions[name] = ActionConfig.new(block)
end

.actionsHash

Returns:

  • (Hash)


46
47
48
# File 'lib/haveapi/authentication/token/config.rb', line 46

def actions
  @actions || {}
end

.http_header(header = nil) ⇒ String

HTTP header that is searched for token

Parameters:

  • header (String, nil) (defaults to: nil)

Returns:

  • (String)


53
54
55
56
57
58
59
# 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) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# 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

.query_parameter(param = nil) ⇒ Symbol

Query parameter searched for token

Parameters:

  • param (Symbol) (defaults to: nil)

Returns:

  • (Symbol)


64
65
66
67
68
69
70
# 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) ⇒ Object

Configure token request action



9
10
11
12
13
14
15
16
17
18
19
# 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

Instance Method Details

#find_user_by_token(request, token) ⇒ Object?

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.

Parameters:

  • request (Sinatra::Request)
  • token (String)

Returns:

  • (Object, nil)


113
# File 'lib/haveapi/authentication/token/config.rb', line 113

def find_user_by_token(request, token); end