API Authentication
Access the Graphlit Data API with a JSON Web Token (JWT).
Last updated
Was this helpful?
Access the Graphlit Data API with a JSON Web Token (JWT).
Last updated
Was this helpful?
The API uses the GraphQL query language, which supports client libraries for most programming languages.
You can use a , or use our native SDKs for and .
To authenticate to the Graphlit Data API, you will need a , or JWT for short.
Depending on your programming language, there are different approaches to create the JWT.
You will need a JavaScript JWT library to create and sign tokens. In this guide, we'll use the jsonwebtoken
library in Node.js for illustrative purposes. Please adapt the instructions to your chosen library.
Install the jsonwebtoken library in your Node.js project with this command:
Creating and Signing a JWT
After installing the necessary library, use the following steps to create and sign a JWT:
Configure the Graphlit organization and environment IDs
Configure the JWT secret signing key for the Graphlit environment
Specify the expiration date/time of the JWT
Create the security key
Create the JWT signing credentials
Create the required Graphlit claims
Create the JWT and write to a string
Verifying a JWT
You can verify the JWT using the same secret used to sign it. Below is an example in Node.js using the jsonwebtoken
library:
This will print the decoded JWT to the console. If the JWT was modified or if it has expired, jwt.verify
will throw an error.
Code Sample
Here is a JavaScript code sample to start with:
Be sure to keep your secret key private. If someone else obtains it, they can create and verify JWTs as if they were you, leading to potential security breaches.
Your secrets should always be stored as environment variables. Never hard-code them in your codebase or commit them to a repository.
The HMAC SHA256 (aka HS256) signing algorithm is required for the signing credentials. More information on JWT signing can be found .
The HMAC SHA256 (aka HS256) signing algorithm is required for the signing credentials. More information on JWT signing can be found .
When developing, you can use a strategy to protect your secrets.