class E3DB::TokenHelper
Faraday middleware to automatically refresh authentication tokens and pass them to API requests.
Public Class Methods
new(app, client)
click to toggle source
Calls superclass method
# File lib/e3db/client.rb, line 20 def initialize(app, client) super(app) @client = client @token = nil end
Public Instance Methods
call(env)
click to toggle source
# File lib/e3db/client.rb, line 26 def call(env) if @token.nil? or @token.expired? @token = @client.client_credentials.get_token end env[:request_headers]['Authorization'] ||= %(Bearer #{@token.token}) @app.call env end