Sha256: 0000e8a7773e10bbb01e597a0341e6b7a79db3e5be0c34d3c2fe0c504e7aef4c

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Doorkeeper
  module OAuth
    class ClientCredentialsRequest < BaseRequest
      class Issuer
        attr_accessor :token, :validator, :error

        def initialize(server, validator)
          @server = server
          @validator = validator
        end

        def create(client, scopes, creator = Creator.new)
          if validator.valid?
            @token = create_token(client, scopes, creator)
            @error = :server_error unless @token
          else
            @token = false
            @error = validator.error
          end
          @token
        end

        private

        def create_token(client, scopes, creator)
          context = Authorization::Token.build_context(
            client,
            Doorkeeper::OAuth::CLIENT_CREDENTIALS,
            scopes,
          )
          ttl = Authorization::Token.access_token_expires_in(@server, context)

          creator.call(
            client,
            scopes,
            use_refresh_token: false,
            expires_in: ttl,
          )
        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/issuer.rb
doorkeeper-5.3.2 lib/doorkeeper/oauth/client_credentials/issuer.rb
doorkeeper-5.3.1 lib/doorkeeper/oauth/client_credentials/issuer.rb
doorkeeper-5.3.0 lib/doorkeeper/oauth/client_credentials/issuer.rb