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 = {})
  if Doorkeeper.config.reuse_access_token
    reusable_token = find_reusable_token_for(client, scopes, attributes)
    return reusable_token if reusable_token
  end

  existing_token = find_revocable_token_for(client, scopes, attributes)

  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