Sha256: 2c410bc0700dfaf76b68699a933116d8cfe0d70226047297aea9534966d90596

Contents?: true

Size: 1.01 KB

Versions: 25

Compression:

Stored size: 1.01 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 if credentials.present?
            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
        delegate :blank?, to: :uid
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
doorkeeper-5.8.0 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.7.1 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.7.0 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.6.9 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.6.8 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.6.7 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.6.6 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.6.5 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.6.4 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.6.3 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.6.2 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.6.1 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.6.0 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.6.0.rc2 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.6.0.rc1 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.5.4 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.5.3 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.5.2 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.5.1 lib/doorkeeper/oauth/client/credentials.rb
doorkeeper-5.5.0 lib/doorkeeper/oauth/client/credentials.rb