Class: Fortnox::Auth::ThreadLocal

Inherits:
Object
  • Object
show all
Defined in:
lib/fortnox/auth/thread_local.rb

Overview

Bearer-token authentication isolated between threads, so concurrent contexts (Sidekiq workers, Puma threads) can use different tokens without leaking across them.

Constant Summary collapse

THREAD_LOCAL_KEY =
:fortnox_access_token

Instance Method Summary collapse

Instance Method Details

#apply(request) ⇒ Object



11
12
13
# File 'lib/fortnox/auth/thread_local.rb', line 11

def apply(request)
  request.headers['Authorization'] = "Bearer #{token!}"
end

#on_rejected(response) ⇒ Object



15
16
17
# File 'lib/fortnox/auth/thread_local.rb', line 15

def on_rejected(response)
  raise Fortnox::RequestError, response
end