Is it possible to send custom log data in a Client Credentials token request?

I have an application that is deployed to two different environments (Prod 1 and Prod 2), but both environments use the same ClientId when requesting a token.

I’d like to be able to pass along the environment name as part of the Client Credentials grant, and have that information available in the logs.

I’ve tried passing the data on the query string, and as addition key/value pairs in my request body. I was hoping that any additional data would be added to the Raw Data in the request logs, but that doesn’t seem to be the case.

Does Auth0 have a way of creating custom log parameters during a Client Credentials exchange? Can the log parameters be written to in a custom Action?

Hi @dave.natalie

Thank you for reaching out to us!

Please allow me some time to research on this matter and I will provide an update as soon as possible.

Best regards,
Gerald

Hi @dave.natalie

Thank you for your patience, returning with some news that should work for your use case!

I recommend using a Machine to Machine Action where you can add the environment variable in the event.request.body that you can then console.log. This would show the env variable in normal logs and I believe it should work as you intend. The suggested Action could look similar to the following:

TOKEN REQUEST

{
  "client_id": "...",
  "client_secret": "...",
  "audience": "...",
  "grant_type": "client_credentials",
  "x_environment": "Prod-1" 
}

exports.onExecuteCredentials Exchange = async (event, api) => {

  const env = event.request.body.x_environment || 'unknown-env';

  console.log(`Environment: ${env}`);

};

Within the code, please do not include the space here : onExecuteCredentials Exchange in order for the call to work.
Hopefully this covers your use case and works as expected for you!

Have a great one!
Gerald

Thanks! I was hoping for a solution that wouldn’t require a custom Action, but this will work for my use-case.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.