Method: Auth0::Api::AuthenticationEndpoints#api_token

Defined in:
lib/auth0/api/authentication_endpoints.rb

#api_token(client_id: @client_id, client_secret: @client_secret, organization: @organization, audience: nil) ⇒ json

Request an API access token using a Client Credentials grant

Parameters:

  • client_id (string) (defaults to: @client_id)

    Client ID for the application

  • client_secret (string) (defaults to: @client_secret)

    Client secret for the application. Ignored if using Client Assertion

  • audience (string) (defaults to: nil)

    API audience to use

  • organization (string) (defaults to: @organization)

    Organization ID

Returns:

  • (json)

    Returns the API token

See Also:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/auth0/api/authentication_endpoints.rb', line 25

def api_token(
  client_id: @client_id,
  client_secret: @client_secret,
  organization: @organization,
  audience: nil
)
  request_params = {
    grant_type: 'client_credentials',
    client_id: client_id,
    audience: audience,
    organization: organization
  }

  populate_client_assertion_or_secret(request_params, client_id: client_id, client_secret: client_secret)

  response = request_with_retry(:post, '/oauth/token', request_params)
  ::Auth0::ApiToken.new(response['access_token'], response['scope'], response['expires_in'])
end