Insites Docs Developers guide Data and UsersUsersAuthenticating a User with a JWT Token

Authenticating a User with a JWT Token

Last updated on June 26, 2024.

This guide discusses how to authenticate JSON requests with a JWT token.

Prerequisites

To follow the steps in this tutorial, you must understand the concept of pages, users, and Permissions.

Steps

Authenticating a user with a JWT token is a three-step process:

  • Step 1: Fetch the JWT token for a user
  • Step 2: Create a page with a policy that checks the JWT token
  • Step 3: Send signed request

Step 1: Fetch JWT Token for a User

You can do this after the user login; The system should usually store the token in the browser memory.

app/graphql/user_jwt_token.graphql

Note

Every time you fetch the , the old token becomes inactive.

Step 2: Create a Page with a Policy that Checks the JWT Token

The Authorization Policy fetches the JWT token from the request header and sets the current user using this token.

app/graphql/jwt_login

app/authorization_policies/api_set_current_user.liquid

app/views/pages/api/orders.json.liquid

Step 3: Send the Signed Request

curl

js fetch

Have a suggestion for this page?

Didn't quite find what you are looking for or have feedback on how we can make the content better then we would love to hear from you. Please provide us feedback and we will get back to you shortly.