Sha256: 8d0c8705db7dc41d73559d2c8ffccfcce586780874734eab7981964697440599

Contents?: true

Size: 754 Bytes

Versions: 1

Compression:

Stored size: 754 Bytes

Contents

# frozen_string_literal: true
require 'faraday'
require 'base64'

module BitBucket
  module Request
    class BasicAuth < Faraday::Middleware
      dependency 'base64'

      def call(env)
        env[:request_headers].merge!('Authorization' => "Basic #{@auth}\"")

        @app.call env
      end

      def initialize(app, *args)
        @app = app
        credentials = ''
        options = args.extract_options!
        if options.key? :login
          credentials = "#{options[:login]}:#{options[:password]}"
        elsif options.key? :basic_auth
          credentials = (options[:basic_auth]).to_s
        end
        @auth = Base64.encode64(credentials)
        @auth.gsub!("\n", '')
      end
    end # BasicAuth
  end # Request
end # BitBucket

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bitbuckets-0.2.0 lib/bitbucket_rest_api/request/basic_auth.rb