Sha256: 791a2aae8277bc153117524f9cbf2f26e6804205c4ee5cb0d7327aa4c207aa47

Contents?: true

Size: 1.07 KB

Versions: 4

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Doorkeeper
  module OAuth
    class ClientCredentialsRequest < BaseRequest
      class Creator
        def call(client, scopes, attributes = {})
          if lookup_existing_token?
            existing_token = find_existing_token_for(client, scopes)
            return existing_token if server_config.reuse_access_token && existing_token&.reusable?

            existing_token&.revoke if server_config.revoke_previous_client_credentials_token
          end

          server_config.access_token_model.find_or_create_for(
            client, nil, scopes, attributes[:expires_in],
            attributes[:use_refresh_token],
          )
        end

        private

        def lookup_existing_token?
          server_config.reuse_access_token || server_config.revoke_previous_client_credentials_token
        end

        def find_existing_token_for(client, scopes)
          server_config.access_token_model.matching_token_for(client, nil, scopes)
        end

        def server_config
          Doorkeeper.config
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
doorkeeper-5.3.3 lib/doorkeeper/oauth/client_credentials/creator.rb
doorkeeper-5.3.2 lib/doorkeeper/oauth/client_credentials/creator.rb
doorkeeper-5.3.1 lib/doorkeeper/oauth/client_credentials/creator.rb
doorkeeper-5.3.0 lib/doorkeeper/oauth/client_credentials/creator.rb