Create Custom Log Parameters During an Auth0 Client Credentials Exchange

Overview

Passing custom parameters, such as an environment name, during a Client Credentials exchange allows that information to appear in Auth0 logs. To achieve this, create a Machine-to-Machine (M2M) Action to capture the custom parameter from the request body and log it to the console. When an application uses the same Client ID across multiple environments to request a token, adding custom key/value pairs directly to the request body does not automatically append the data to the Raw Data in the request logs without an Action.

 

Applies To
  • Machine to Machine (M2M) Actions
  • Client Credentials Exchange
  • Logging
  • Auth0
Solution

To log custom parameters during a Client Credentials exchange, include the custom parameter in the token request body and create a Machine-to-Machine Action that extracts the custom variable from the request body to output it to the console.

  1. Include the custom parameter in the token request body.
    {
    "client_id": "<client_id>",
    "client_secret": "<client_secret>",
    "audience": "<audience>",
    "grant_type": "client_credentials",
    "x_environment": "Prod-1"
    }
  2. Create a Machine-to-Machine Action using the following code to log the environment variable:
    exports.onExecuteCredentialsExchange = async (event, api) => {
    const env = event.request.body.x_environment || 'unknown-env';
    console.log(`Environment: ${env}`);
    };

Recommended content

No recommended content found...