Sha256: 2c9fed85d49c1eae55fb6a451372741966d6e75f2bd47f301ef4d5fc95aa6ffa

Contents?: true

Size: 665 Bytes

Versions: 12

Compression:

Stored size: 665 Bytes

Contents

# frozen_string_literal: true

require 'active_support'

module DHS
  module Interceptors
    module AutoOauth
      extend ActiveSupport::Concern

      class Interceptor < DHC::Interceptor

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

        def tokens
          @tokens ||= DHS::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

12 entries across 12 versions & 1 rubygems

Version Path
dhs-1.6.0 lib/dhs/interceptors/auto_oauth/interceptor.rb
dhs-1.5.0 lib/dhs/interceptors/auto_oauth/interceptor.rb
dhs-1.4.2 lib/dhs/interceptors/auto_oauth/interceptor.rb
dhs-1.4.1 lib/dhs/interceptors/auto_oauth/interceptor.rb
dhs-1.4.0 lib/dhs/interceptors/auto_oauth/interceptor.rb
dhs-1.3.0 lib/dhs/interceptors/auto_oauth/interceptor.rb
dhs-1.2.0 lib/dhs/interceptors/auto_oauth/interceptor.rb
dhs-1.1.0 lib/dhs/interceptors/auto_oauth/interceptor.rb
dhs-1.0.3 lib/dhs/interceptors/auto_oauth/interceptor.rb
dhs-1.0.2 lib/dhs/interceptors/auto_oauth/interceptor.rb
dhs-1.0.1 lib/dhs/interceptors/auto_oauth/interceptor.rb
dhs-1.0.0 lib/dhs/interceptors/auto_oauth/interceptor.rb