To begin using the AuthAlert API, first create a project and note down your unique project ID. This project ID is necessary for identifying your project in API calls. The API endpoint format is:
https://api.authalert.io/api/{projectId}
Replace {projectId} with your actual project ID in every API request.
There are two ways to authenticate your API calls:
When making an API request, the input data should be in JSON format. Here’s an example:
{
"email": "user@mysite.com",
"device_id": "12kjfsui346",
"user_id": "uirewe324ryuf",
"first_name": "Josh",
"last_name": "Smith"
}
Below is an example of how to call the API using cURL with token authentication:
curl -X POST <https://api.authalert.io/api/{projectId}> \\\\
-H "Authorization: Bearer your_token_here" \\\\
-H "Content-Type: application/json" \\\\
-d '{
"email": "user@mysite.com",
"device_id": "12kjfsui346",
"user_id": "uirewe324ryuf",
"first_name": "Josh",
"last_name": "Smith"
}'
For web applications built with JavaScript frameworks like React, Angular, or Vue, we recommend using the AuthAlert npm package to simplify integration. Please note that the npm package supports domain authentication only.
To install the npm package, run the following command:
npm install authalert
The npm package supports both async functions and promise chains. Here’s an example using async/await:
import AuthAlertAPI from 'authalert';
const projectId = "your_project_ID";
const result = await AuthAlertAPI(projectId, {
user_id: user.id,
email: user.email,
first_name: user.first_name,
last_name: user.last_name
});
console.log(result);
Alternatively, you can use a promise chain:
import AuthAlertAPI from 'authalert';
const projectId = "your_project_ID";
AuthAlertAPI(projectId, {
user_id: user.id,
email: user.email,
first_name: user.first_name,
last_name: user.last_name
})
.then(res => {
console.log(res);
})
.catch(err => {
console.error(err);
});
The AuthAlertAPI function accepts the following input parameters:
Upon a successful API call, the response will be a JSON object containing two boolean properties: new_user and new_device.
If new_device is true, it is recommended that the frontend application triggers Multi-Factor Authentication (MFA) to enhance security by authorizing the new device. This approach improves security without requiring MFA on every authentication attempt, effectively implementing an "authorize this device" feature.
Learn more about how to boost your application security in software development