Class: Evil::Client::Resolver::Security
- Inherits:
-
Evil::Client::Resolver
- Object
- Evil::Client::Resolver
- Evil::Client::Resolver::Security
- Defined in:
- lib/evil/client/resolver/security.rb
Overview
Resolves security definitions from operation settings and schema. Defines helpers for different methods of the authentication.
Instance Method Summary collapse
-
#basic_auth(user, password) ⇒ Hash<:headers, Hash<Symbol, String>>
DSL method to provide basic authentication schema by user name and password.
-
#key_auth(key, value, inside: :headers) ⇒ Hash<Symbol, Hash<Symbol, String>>
DSL method to provide the key-based authentication schema.
-
#token_auth(token, inside: :headers, prefix: nil) ⇒ Hash<Symbol, Hash<Symbol, String>>
DSL method to provide token-based authentication schema.
Methods inherited from Evil::Client::Resolver
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Evil::Client::Resolver
Instance Method Details
#basic_auth(user, password) ⇒ Hash<:headers, Hash<Symbol, String>>
DSL method to provide basic authentication schema by user name and password
It provides base64-encoded “user:password” token and adds it to the “Authorization” header with a “Basic” prefix.
26 27 28 29 |
# File 'lib/evil/client/resolver/security.rb', line 26 def basic_auth(user, password) token = Base64.encode64("#{user}:#{password}").delete("\n") token_auth(token, prefix: "Basic") end |
#key_auth(key, value, inside: :headers) ⇒ Hash<Symbol, Hash<Symbol, String>>
DSL method to provide the key-based authentication schema
72 73 74 |
# File 'lib/evil/client/resolver/security.rb', line 72 def key_auth(key, value, inside: :headers) { inside => { key.to_s => value.to_s } } end |
#token_auth(token, inside: :headers, prefix: nil) ⇒ Hash<Symbol, Hash<Symbol, String>>
DSL method to provide token-based authentication schema
It places the token under either standard “Authorization” header, or standard “access_token” parameter of body or query. If you need custom key use [#key_auth] schema instead.
49 50 51 52 53 54 55 56 |
# File 'lib/evil/client/resolver/security.rb', line 49 def token_auth(token, inside: :headers, prefix: nil) if inside == :headers prefixed_token = [prefix&.to_s&.capitalize, token].compact.join(" ") key_auth("Authorization", prefixed_token, inside: :headers) else key_auth("access_token", token, inside: inside) end end |