Class: Zaikio::Client::Helpers::AuthorizationMiddleware

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/zaikio/client/helpers/authorization_middleware.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.reset_tokenObject



15
16
17
# File 'lib/zaikio/client/helpers/authorization_middleware.rb', line 15

def self.reset_token
  Thread.current[:zaikio_client_access_token] = nil
end

.tokenObject



7
8
9
# File 'lib/zaikio/client/helpers/authorization_middleware.rb', line 7

def self.token
  Thread.current[:zaikio_client_access_token]
end

.token=(value) ⇒ Object



11
12
13
# File 'lib/zaikio/client/helpers/authorization_middleware.rb', line 11

def self.token=(value)
  Thread.current[:zaikio_client_access_token] = value
end

Instance Method Details

#call(request_env) ⇒ Object



19
20
21
22
23
# File 'lib/zaikio/client/helpers/authorization_middleware.rb', line 19

def call(request_env)
  request_env[:request_headers]["Authorization"] = "Bearer #{self.class.token}" if self.class.token

  @app.call(request_env)
end