Class: HaveAPI::Authentication::Token::Config
- Inherits:
-
Object
- Object
- HaveAPI::Authentication::Token::Config
- Defined in:
- lib/haveapi/authentication/token/config.rb
Overview
Configuration for Provider
Create a subclass and use with #with_config.
Class Method Summary collapse
- .action(name, &block) ⇒ Object
- .actions ⇒ Hash
-
.http_header(header = nil) ⇒ String
HTTP header that is searched for token.
- .inherited(subclass) ⇒ Object
-
.query_parameter(param = nil) ⇒ Symbol
Query parameter searched for token.
-
.request(&block) ⇒ Object
Configure token request action.
Instance Method Summary collapse
-
#find_user_by_token(request, token) ⇒ Object?
Authenticate request by
token. -
#initialize(server, v) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(server, v) ⇒ Config
Returns a new instance of Config.
106 107 108 109 |
# File 'lib/haveapi/authentication/token/config.rb', line 106 def initialize(server, v) @server = server @version = v end |
Class Method Details
.action(name, &block) ⇒ Object
40 41 42 43 |
# File 'lib/haveapi/authentication/token/config.rb', line 40 def action(name, &block) @actions ||= {} @actions[name] = ActionConfig.new(block) end |
.actions ⇒ 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
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 97 98 99 100 101 102 103 |
# File 'lib/haveapi/authentication/token/config.rb', line 72 def inherited(subclass) super # Default request subclass.request do input do string :user, label: HaveAPI.('haveapi.parameters.authentication.token.user.label'), required: true password :password, label: HaveAPI.('haveapi.parameters.authentication.token.password.label'), required: true string :scope, label: HaveAPI.('haveapi.parameters.authentication.token.scope.label'), 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
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.
120 |
# File 'lib/haveapi/authentication/token/config.rb', line 120 def find_user_by_token(request, token); end |