Sha256: 72fa20bceb82b54a69577eff32a4bbfe4973d3abece603d6b1329562158187ee

Contents?: true

Size: 797 Bytes

Versions: 16

Compression:

Stored size: 797 Bytes

Contents

module Doorkeeper
  module OAuth
    class ClientCredentialsRequest
      class Creator
        def call(client, scopes, attributes = {})
          existing_token = existing_token_for(client, scopes)
          if existing_token
            return existing_token if existing_token.accessible?
            existing_token.revoke
          end
          create(client, scopes, attributes)
        end

      private

        def existing_token_for(client, scopes)
          Doorkeeper::AccessToken.matching_token_for client, nil, scopes
        end

        def create(client, scopes, attributes = {})
          Doorkeeper::AccessToken.create(attributes.merge({
            :application_id => client.id,
            :scopes         => scopes.to_s
          }))
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
doorkeeper-0.7.1 lib/doorkeeper/oauth/client_credentials/creator.rb
doorkeeper-0.7.0 lib/doorkeeper/oauth/client_credentials/creator.rb
doorkeeper-0.6.7 lib/doorkeeper/oauth/client_credentials/creator.rb
doorkeeper-0.6.6 lib/doorkeeper/oauth/client_credentials/creator.rb
doorkeeper-0.6.5 lib/doorkeeper/oauth/client_credentials/creator.rb
doorkeeper-0.6.4 lib/doorkeeper/oauth/client_credentials/creator.rb
doorkeeper-0.6.3 lib/doorkeeper/oauth/client_credentials/creator.rb
doorkeeper-0.6.2 lib/doorkeeper/oauth/client_credentials/creator.rb
doorkeeper-0.6.1 lib/doorkeeper/oauth/client_credentials/creator.rb
doorkeeper-0.6.0 lib/doorkeeper/oauth/client_credentials/creator.rb
doorkeeper-0.6.0.rc1 lib/doorkeeper/oauth/client_credentials/creator.rb
doorkeeper-0.5.0 lib/doorkeeper/oauth/client_credentials/creator.rb
doorkeeper-0.5.0.rc1 lib/doorkeeper/oauth/client_credentials/creator.rb
doorkeeper-0.4.2 lib/doorkeeper/oauth/client_credentials/creator.rb
doorkeeper-0.4.1 lib/doorkeeper/oauth/client_credentials/creator.rb
doorkeeper-0.4.0 lib/doorkeeper/oauth/client_credentials/creator.rb