Sha256: 3d88126c0e6915ca714b565cd01748b5baa5dfc56af4f1ad65086660c5a6607e

Contents?: true

Size: 1.03 KB

Versions: 22

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Doorkeeper
  module OAuth
    class Client
      Credentials = Struct.new(:uid, :secret) do
        class << self
          def from_request(request, *credentials_methods)
            credentials_methods.inject(nil) do |_, method|
              method = self.method(method) if method.is_a?(Symbol)
              credentials = Credentials.new(*method.call(request))
              break credentials unless credentials.blank?
            end
          end

          def from_params(request)
            request.parameters.values_at(:client_id, :client_secret)
          end

          def from_basic(request)
            authorization = request.authorization
            if authorization.present? && authorization =~ /^Basic (.*)/m
              Base64.decode64(Regexp.last_match(1)).split(/:/, 2)
            end
          end
        end

        # Public clients may have their secret blank, but "credentials" are
        # still present
        def blank?
          uid.blank?
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
doorkeeper-5.1.2 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.2.6 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.3.3 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.0.3 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.1.1 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.2.5 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.3.2 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.2.4 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.3.1 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.3.0 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.2.3 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.2.2 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.2.1 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.2.0 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.2.0.rc3 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.2.0.rc2 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.2.0.rc1 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.1.0 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.1.0.rc2 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.1.0.rc1 lib/doorkeeper/oauth/client/credentials.rb