API Authentication
Access the Graphlit Data API with a JSON Web Token (JWT).
The API uses the GraphQL query language, which supports client libraries for most programming languages.
You can use a GraphQL client library, or use our native SDKs for Python and JavaScript.
To authenticate to the Graphlit Data API, you will need a JSON Web Token, or JWT for short.
On the Project Settings page of the Graphlit Developer Portal, you will find the Environment ID
, Organization ID
, and JWT Secret
for the Environments, which have been provisioned for each Project.
Depending on your programming language, there are different approaches to create the JWT.
Native SDK Authentication
GraphQL Client Authentication
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
The HMAC SHA256 (aka HS256) signing algorithm is required for the signing credentials. More information on JWT signing can be found here.
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:
Security Considerations
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.
Last updated