Sha256: 09168a719255129cabd864682f1044fc1dccef556f9612ccf5e9ae8ebc82cf2c

Contents?: true

Size: 719 Bytes

Versions: 15

Compression:

Stored size: 719 Bytes

Contents

require 'faraday'



module Saddle
  module Middleware
    module Authentication

      ## Add OAuth 2.0 authentication tokens to requests
      #
      class OAuth2 < Faraday::Middleware

        def initialize(app, key_name='access_token')
          super(app)
          @key_name = key_name
        end

        def call(env)
          if env[:request][:client_options][@key_name.to_sym]
            new_query = []
            new_query << env[:url].query if env[:url].query
            new_query << "#{@key_name}=#{CGI.escape(env[:request][:client_options][@key_name.to_sym].to_s)}"
            env[:url].query = new_query.join('&')
          end

          @app.call(env)
        end

      end

    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
saddle-0.0.53 lib/saddle/middleware/authentication/oauth2.rb
saddle-0.0.51 lib/saddle/middleware/authentication/oauth2.rb
saddle-0.0.50 lib/saddle/middleware/authentication/oauth2.rb
saddle-0.0.49 lib/saddle/middleware/authentication/oauth2.rb
saddle-0.0.48 lib/saddle/middleware/authentication/oauth2.rb
saddle-0.0.46 lib/saddle/middleware/authentication/oauth2.rb
saddle-0.0.45 lib/saddle/middleware/authentication/oauth2.rb
saddle-0.0.44 lib/saddle/middleware/authentication/oauth2.rb
saddle-0.0.43 lib/saddle/middleware/authentication/oauth2.rb
saddle-0.0.42 lib/saddle/middleware/authentication/oauth2.rb
saddle-0.0.41 lib/saddle/middleware/authentication/oauth2.rb
saddle-0.0.38 lib/saddle/middleware/authentication/oauth2.rb
saddle-0.0.37 lib/saddle/middleware/authentication/oauth2.rb
saddle-0.0.36 lib/saddle/middleware/authentication/oauth2.rb
saddle-0.0.35 lib/saddle/middleware/authentication/oauth2.rb