Using Outseta with Auth0

Hi All—I believe this is the right place to post this question as I think an action would be required, or a hook. We use Outseta for account management and Auth0 for authentication. We need to pass Auth0 user credentials (email) to Outseta via a POST request whenever a user logs in so that their Outseta user profile (billing/account info) will surface on their dashboard viewing page once logged in. The required format of the POST request is below, username = email:

curl --location -g --request POST '{{url}}/tokens' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: {{authorizationtoken}}' \
--data-urlencode 'username={{username}}' \
--data-urlencode 'password=' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'client_id=outseta_auth_widget'

How can I trigger this POST request from Auth0 when a user logs in and send their email address as well?

Sincerely appreciative of any help! Thanks!

Hi @tessat,

Thanks for reaching out to the Auth0 Community!

I understand that you’d like to send the authenticated user’s email to Outseta with the custom POST request you shared with me.

The best way to accomplish this is with Auth0 Actions. You can use a Post-Login Action to send your request after the user successfully authenticates.

You’ll want to use the event.user.email property and pass in your request. See here for more Event object properties: https://auth0.com/docs/actions/triggers/post-login/event-object

Please let me know if you need any help with your Action. I’d be happy to assist.

Thank you.

Thanks @rueben.tiow — I think I’ll need a bit more help with my Action, not sure how to send, I can see that I can make the post-login trigger and add it to the Action flow, but not sure where I can call the Outseta POST call and pass in the user email. Maybe I’m in the wrong place?

Hi @tessat,

Thank you for your response.

After creating your Action, you will be redirected to an internal code editor where you can implement your Outseta POST call in Javascript.

Then on the code editor, implement something like this to make a POST request:

exports.onExecutePostLogin = async (event, api) => {
  var axios = require("axios").default;

  var options = {
    method: 'POST',
    url: '{{ YOUR_URL }}',
    headers: {'content-type': 'application/x-www-form-urlencoded',
              'Authorization': event.secrets.token},
    data: {
      username: event.user.email
      //(your other data here)
    }
  };

  axios.request(options).then(function (response) {
    console.log(response.data);
  }).catch(function (error) {
    console.error(error);
  });
};

In this script, you will notice that the event.user.email property is set as the username in the request. And the authorization token is saved as a Secret in your Action by calling event.secrets.token.

Any sensitive information should be stored as a Secret, which you can add by pressing the key icon on the left column and clicking on the Add Secret button. See below:

Once you have completed the implementation for your Action, you can test the Action by pressing the Test play icon directly above the Secrets key icon.

Please let me know how this works for you.

Thank you.