Sha256: e3264a8547a1761c6bfb20abd789bab432d42afdca3777255b8e2d4f73973250

Contents?: true

Size: 665 Bytes

Versions: 22

Compression:

Stored size: 665 Bytes

Contents

# frozen_string_literal: true

require 'active_support'

module LHS
  module Interceptors
    module AutoOauth
      extend ActiveSupport::Concern

      class Interceptor < LHC::Interceptor

        def before_request
          request.options[:auth] = { bearer: token }
        end

        def tokens
          @tokens ||= LHS::Interceptors::AutoOauth::ThreadRegistry.access_token
        end

        def token
          if tokens.is_a?(Hash)
            tokens.dig(
              request.options[:oauth] ||
              request.options[:record]&.auto_oauth
            )
          else
            tokens
          end
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
lhs-21.3.1 lib/lhs/interceptors/auto_oauth/interceptor.rb
lhs-21.3.0 lib/lhs/interceptors/auto_oauth/interceptor.rb