Class: Doorkeeper::OAuth::ClientCredentials::Creator

Inherits:
Object
  • Object
show all
Defined in:
lib/doorkeeper/oauth/client_credentials/creator.rb

Instance Method Summary collapse

Instance Method Details

#call(client, scopes, attributes = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/doorkeeper/oauth/client_credentials/creator.rb', line 7

def call(client, scopes, attributes = {})
  existing_token = nil

  if lookup_existing_token?
    existing_token = find_active_existing_token_for(client, scopes, attributes)
    return existing_token if Doorkeeper.config.reuse_access_token && existing_token&.reusable?
  end

  with_revocation(existing_token: existing_token) do
    application = client.is_a?(Doorkeeper.config.application_model) ? client : client&.application
    Doorkeeper.config.access_token_model.create_for(
      application: application,
      resource_owner: nil,
      scopes: scopes,
      **attributes,
    )
  end
end