Skip to main content

Creating Users

Overview#

Once you've created object types to model the resources and relationships in your system, it's time to create users.

The most basic access rules in Warrant are specific to users. Before you can authorize user actions in your application, you need to create users in Warrant. Users can be created via a POST /v1/users request to Warrant. This logic should be implemented in your application's new user sign-up flow so whenever a new user is created in your system, a corresponding user is created in Warrant. More specifically, you have 2 options for creating users:

  • Create users where you provide an id for Warrant to assign to each user
  • Create users where Warrant generates a unique id for each user

Providing a userId#

The easiest way to create users in Warrant is to create them using the same id you use to identify them in your system. This is usually a unique id generated by your database or an id given to you by a third-party authentication provider. We recommend this approach because you do not need to track a separate Warrant-specific user id for each of your users. For example, if you have a user named Tony Stark with id d6ed6474-784e-407e-a1ea-42a91d4c52b9 in your system, you can create a user in Warrant with the same userId d6ed6474-784e-407e-a1ea-42a91d4c52b9:

POST /v1/users
curl "https://api.warrant.dev/v1/users" \    -X POST \    -H "Authorization: ApiKey YOUR_KEY" \    --data-raw \    '{"userId":"d6ed6474-784e-407e-a1ea-42a91d4c52b9"}'

This call will create a user with a userId of d6ed6474-784e-407e-a1ea-42a91d4c52b9 and return a response like this:

{    "userId": "d6ed6474-784e-407e-a1ea-42a91d4c52b9"}

Warrant-generated userId#

If you don't provide a userId on user creation, Warrant will generate a userId for that user. In this case, you will need to store this userId as a new field in your system and include it in all Authorization requests for that user.

POST /v1/users
curl "https://api.warrant.dev/v1/users" \    -X POST \    -H "Authorization: ApiKey YOUR_KEY" \

This call will create the user with a machine-generated userId and return a response like this:

{    "userId": "d6ed6474-784e-407e-a1ea-42a8883025d"}
note

We recommend that you store each user's userId as a warrantUserId in your system in order to identify your users for future authorization calls you will make to the Warrant API.

Creating Existing Users#

If you are integrating Warrant into a live system, chances are that you already have live users. In order to use Warrant for these users, you will need to create them in Warrant. The easiest way to do this is to bulk-create them via script using 1 of the 2 methods described above (method choice depends on your id preference).

We will be adding a CLI tool to make this process easier.