Secure Auth0 post registration action

Viewed 22

In the example auth0 provides for Storing an Auth0 user id in a remote system it posts to an unprotected endpoint. Are there headers or something I can add to the request that my endpoint can check to make sure not just anyone can post a email and create a user?

const axios = require("axios");

/**
 * @param {Event} event - Details about registration event.
 */
exports.onExecutePostUserRegistration = async (event) => {
  await axios.post("https://my-api.exampleco.com/users", { params: { email: event.user.email }});
};
1 Answers

The example uses the axios library to execute the request. axios is a mature Javascript HTTP client with a ton of features. You can easily add a header, e.g.:

await axios.post(
    "https://my-api.exampleco.com/users",
    {
        headers: { 'Authorization: supersecret' },
        params: { email: event.user.email }
    }
);

Also refer to the axios documentation: https://www.npmjs.com/package/axios.

If axios is not suitable, other npm packages can also be used.

Related