Authentication

The authentication service is a fully-fledged user management system ready to be integrated into your app.

It allows you to:

register users
log them into your application
built user-specific logic in your workflows
reset user password
monitor your users on the console

This service provides ready-to-use HTTP endpoints and one dedicated web page to reset users' passwords, so you don't have to redevelop it yourself.

All the following endpoints require the id of your project to be set in the URL. Replace the PROJECT_ID by the actual id of your project (eg: 87501c8c-e2ed-41e8-a895-04cf6db0503b). You can get your project id from the settings page of your project.

Register a user

To register a new user, your application can send an HTTP request to the auth/register endpoint with the following body.

Request

URL: https://api.liteflow.com/project/PROJECT_ID/auth/register

Method: POST

Body:

KeyTypeDescription
emailStringUser's email
passwordStringUser's password

Response

Success

Status code: 201

No body in the response.

Error

Body:

KeyTypeDescription
statusCodeNumberError code
messageStringMessage or type of error
errorStringoptional type of error

Example

script.js
const response = await fetch(
  `https://api.liteflow.com/project/PROJECT_ID/auth/register`,
  {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      email: "test@test.com",
      password: "test",
    }),
  }
);
// check for error
if (!response.ok) {
  // there is an error: parse it and throw it
  const error = await response.json();
  throw new Error(error.message);
}
// success: the user is now registered

Login a user

To login a user, your application can request the auth/login with the email and password of the user. If successful, the response will contain an accessToken that must be set in the authorization header of authenticated endpoints.

Request

URL: https://api.liteflow.com/project/PROJECT_ID/auth/login

Method: POST

Body:

KeyTypeDescription
usernameStringUser's username. For now it's must be the user's email
passwordStringUser's password

Response

Success

Status code: 201

Body:

KeyTypeDescription
accessTokenStringThe access token of the user. Your app must keep it so it can be used in future requests to authenticate the user.

Error

Body:

KeyTypeDescription
statusCodeNumberError code
messageStringMessage or type of error
errorStringoptional type of error

Example

script.js
const response = await fetch(
  `https://api.liteflow.com/project/PROJECT_ID/auth/login`,
  {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      username: "test@test.com",
      password: "test",
    }),
  }
);
// check for error
if (!response.ok) {
  // there is an error: parse it and throw it
  const error = await response.json();
  throw new Error(error.message);
}
// success: the user is now logged in
const data = await response.json();
const accessToken = data.accessToken;

Fetch logged in user

To know if the user is correctly logged in and to get more info about it, your application can request the auth/me endpoint.

This is an authenticated endpoint: the authorization header must be set with the accessToken of the user.

Request

URL: https://api.liteflow.com/project/PROJECT_ID/auth/me

Method: GET

Header: Authorization: Bearer ACCESS_TOKEN (replace ACCESS_TOKEN with the token obtained with the login)

Response

Success

Status code: 200

KeyTypeDescription
idStringUser's id
emailStringUser's email

Error

Body:

KeyTypeDescription
statusCodeNumberError code
messageStringMessage or type of error
errorStringoptional type of error

Example

script.js
const response = await fetch(
  `https://api.liteflow.com/project/PROJECT_ID/auth/me`,
  {
    method: "GET",
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ACCESS_TOKEN`, // replace ACCESS_TOKEN with the actual user's accessToken
    },
  }
);
// check for error
if (!response.ok) {
  // there is an error: parse it and throw it
  const error = await response.json();
  throw new Error(error.message);
}
// success
const data = await response.json();
const userId = data.id;
const email = data.email;

Forget password

If one of your users forgot its password and want to reset, your app can initiate the procedure to reset the password of a user by sending a request to the auth/password/forgot with the email of the user.

If the request is successful, an email will be sent to the user's email containing a link to a form to reset its password, hosted on https://auth.liteflow.com domain.

Request

URL: https://api.liteflow.com/project/PROJECT_ID/auth/password/forgot

Method: POST

Body:

KeyTypeDescription
emailStringUser's email

Response

Success

Status code: 201

No body in the response.

Error

Body:

KeyTypeDescription
statusCodeNumberError code
messageStringMessage or type of error
errorStringoptional type of error

Example

script.js
const response = await fetch(
  `https://api.liteflow.com/project/PROJECT_ID/auth/password/forgot`,
  {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      email: "test@test.com",
    }),
  }
);
// check for error
if (!response.ok) {
  // there is an error: parse it and throw it
  const error = await response.json();
  throw new Error(error.message);
}
// success: an email has been sent to the user's email