Skip to content

User authentication

The main route to create or login a user is used to get a authToken for a specific user.

When you wish to use the clingWidget you can call this route to later on be able to login as a specific user. The body that you provide in the request is used to match existing and update, or to create a new user in Cling.

POST /partner/authCompanyUser Match existing or create a new user, and receive a authToken in return.

Example

The body in your request need to be on the format:

json
{
  "company": {
    "id": "yourUniqueCompanyId",
    "name": "CompanyName AB"
  },
  "companyUser": {
    "id": "yourUniqueCompanyUserId",
    "email": "userEmail@cling.se"
  }
}

The companyUser in the request also have the optional but recommended properties firstname and lastname.

The return value from the route is on the format:

json
{
  "authToken": "abc"
}

General flow

The general flow you should know about is:

  1. Does the unique id match an existing company and user? If yes, update the properties if needed and return authToken for the existing user.
  2. No, does the id for the company match an existing company? If yes, create a new user on that company and return authToken for the new user.
  3. If no, lets create a new company and user and return authToken for the new user.

The authToken that is returned can later be used to exchange for JWT in the context of that specific companyUser, similar to if the user would authenticated themself.