Sha256: e7a0939b359daa8df4c60005e3e7f4272f2f2ff774e5519977194babbf7ec091

Contents?: true

Size: 1.15 KB

Versions: 6

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module Doorkeeper
  module OAuth
    module ClientCredentials
      class Issuer
        attr_reader :token, :validator, :error

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

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

          @token
        end

        private

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

          creator.call(
            client,
            scopes,
            use_refresh_token: false,
            expires_in: ttl,
            **attributes
          )
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
doorkeeper-5.8.1 lib/doorkeeper/oauth/client_credentials/issuer.rb
doorkeeper-5.8.0 lib/doorkeeper/oauth/client_credentials/issuer.rb
doorkeeper-5.7.1 lib/doorkeeper/oauth/client_credentials/issuer.rb
doorkeeper-5.7.0 lib/doorkeeper/oauth/client_credentials/issuer.rb
doorkeeper-5.6.9 lib/doorkeeper/oauth/client_credentials/issuer.rb
doorkeeper-5.6.8 lib/doorkeeper/oauth/client_credentials/issuer.rb