Class: Scaled::Auth::ApiToken
- Inherits:
-
Object
- Object
- Scaled::Auth::ApiToken
- Defined in:
- lib/scaled/auth/api_token.rb
Overview
API token authentication strategy. Стратегія автентифікації через API токен.
Instance Method Summary collapse
-
#apply(headers) ⇒ Hash{String => String}
Note: mutates and returns the same hash to avoid unnecessary allocations.
-
#initialize(token) ⇒ void
constructor
Note: token is normalized with ‘strip` to reduce accidental whitespace issues.
Constructor Details
#initialize(token) ⇒ void
Note: token is normalized with ‘strip` to reduce accidental whitespace issues. Нотатка: токен нормалізується через `strip`, щоб уникнути проблем з пробілами.
12 13 14 15 16 17 |
# File 'lib/scaled/auth/api_token.rb', line 12 def initialize(token) normalized = token.to_s.strip raise ArgumentError, "api token must be provided" if normalized.empty? @token = normalized end |
Instance Method Details
#apply(headers) ⇒ Hash{String => String}
Note: mutates and returns the same hash to avoid unnecessary allocations. Нотатка: змінює і повертає той самий hash для уникнення зайвих алокацій.
23 24 25 26 |
# File 'lib/scaled/auth/api_token.rb', line 23 def apply(headers) headers["Authorization"] = "Bearer #{@token}" headers end |