Authentication

The Identities API makes it easy to integrate user registration and logins into your app.

Each user account is represented by an identity. An identity has a name and password, and identities can be arranged into groups.

Groups

Groups allow you to organise identities into separate categories. Identity names must be unique, but only within the same group.

This can be useful if you're building multiple jsonpad.io-powered apps, each with their own set of users. In this case, you could separate the identities for each app into their own groups, and you won't need to worry about identity name conflicts between the apps.

Item ownership

The main benefit of using identities is that when you create an item while authenticated as an identity, the item will be owned by that identity.

Then, you can set up token permissions to only allow items to be viewed, modified, or deleted by their respective owners.

Registering and authenticating

To register a new identity, make a POST request to the /identities/register endpoint with the identity's group, name, and password. The password will be encrypted.

cURL
12345678curl https://api.jsonpad.io/identities/register \
  -H "Content-Type: application/json" \
  -H "x-api-token: <YOUR TOKEN>" \
  -d '{
        "group": "sample-group",
        "name": "Sample User",
        "password": "secret"
      }'

Then, we can login using the identity we just created by making a POST request to the /identities/login endpoint with the identity's group, name, and password.

cURL
12345678curl https://api.jsonpad.io/identities/login \
  -H "Content-Type: application/json" \
  -H "x-api-token: <YOUR TOKEN>" \
  -d '{
        "group": "sample-group",
        "name": "Sample User",
        "password": "secret"
      }'

The response will include a token that you can use to authenticate in subsequent requests. When using the SDK, this token will be automatically cached and included in all subsequent requests, so you don't need to worry about including it manually.

To authenticate using the token, include it in the x-identity-token header.

Also, if the identity has a group, you must include the group in the x-identity-group header.

2024-12-11