Auth0
Auth0 lets developers implement authentication / authorisation mechanisms in their application. 8x8 SMS API offers a convenient way to leverage Auth0 over the SMS channel.
Auth0 integration
About Auth0
Auth0 is an identity management platform that let applications developers easily implement authentication and authorisation logic into their applications.
Coupled with 8x8 SMS connectivity, it allows developers to send one-time passwords via the Auth0 platform to their users all over the World.
Integrating Auth0 with 8x8 SMS API
To leverage SMS API to send OTP codes to your users, you will be using the hook feature in Auth0.
More specifically, you will be using the "Send a phone message" hook and adapt it to send requests to 8x8 SMS API.
Prerequisites:
Steps:
- In your Auth0 portal, go to the Auth pipeline > Hooks section.
- Select "Create a hook" in the top right corner.
- You can call it by any name, let's call it "8x8".
- Select type "Send phone message" and click on "Create".
- Scroll down on the Hooks page to the "Send phone message" section and click on the pencil/edit button to edit the hook you just created.
- Click on the wrench icon (settings) and select "Secrets".
- Select "Add Secret" and input for secret key:
subaccount
and for secret value, your 8x8 SMS subaccount (can be obtained in 8x8 Connect portal - API Keys section).
8.Select "Add Secret" and input for secret key:apikey
and for secret value, your 8x8 SMS apikey (can be obtained in 8x8 Connect portal - API Keys section). - Close the secrets and settings section.
- Copy and paste this code in the code section of the hook in place of the code already there:
module.exports = function (recipient, text, context, cb) {
const axios = require("axios").default,
API_KEY = context.webtask.secrets.apikey,
SUBACCOUNT = context.webtask.secrets.subaccount,
BASE_URL = "https://sms.8x8.com/api/v1/";
let instance = axios.create({
baseURL: BASE_URL,
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Accept": "application/json",
"Content-Type": "application/json"
},
});
instance({
method: "post",
url: `subaccounts/${SUBACCOUNT}/messages`,
data: {
"encoding": "AUTO",
"destination": recipient,
"text": text
}
})
.then((response) => {
cb(null, {});
})
.catch((error) => {
cb(error);
});
};
- Save the code.
- Click the play button to open the runner.
- Wait for the logs stream to load.
- Press the run button (Bottom right) .
- Check that you have no errors in the hook log stream and the response has a status code of 200.
- Check 8x8 Connect logs and verify that you Auth0 submitted an SMS to the test number with your account.
- You're all set! You can now use this hook in your Auth pipeline!
Video steps
Updated over 3 years ago