Learn how to authenticate with Infisical using JWT-based authentication.
JWT Auth is a platform-agnostic authentication method that validates JSON Web Tokens (JWTs) issued by your JWT issuer or authentication system, allowing secure authentication from any platform or environment that can obtain valid JWTs.
The following sequence diagram illustrates the JWT Auth workflow for authenticating with Infisical.
At a high-level, Infisical authenticates a client by verifying the JWT and checking that it meets specific requirements (e.g. it is signed by a trusted key) at the /api/v1/auth/jwt-auth/login
endpoint. If successful, then Infisical returns a short-lived access token that can be used to make authenticated requests to the Infisical API.
To be more specific:
/api/v1/auth/jwt-auth/login
endpoint.For JWKS configuration, Infisical needs network-level access to the configured JWKS endpoint.
In the following steps, we explore how to create and use identities to access the Infisical API using the JWT authentication method.
Creating an identity
To create an identity, head to your Organization Settings > Access Control > Identities and press Create identity.
When creating an identity, you specify an organization level role for it to assume; you can configure roles in Organization Settings > Access Control > Organization Roles.
Now input a few details for your new identity. Here’s some guidance for each field:
Once you’ve created an identity, you’ll be redirected to a page where you can manage the identity.
Since the identity has been configured with Universal Auth by default, you should re-configure it to use JWT Auth instead. To do this, press to edit the Authentication section, remove the existing Universal Auth configuration, and add a new JWT Auth configuration onto the identity.
Here’s some more guidance for each field:
Static configuration:
JWKS configuration:
Common fields for both configurations:
2592000
equivalent to 30 days): The lifetime for an access token in seconds. This value will be referenced at renewal time.2592000
equivalent to 30 days): The maximum lifetime for an access token in seconds. This value will be referenced at renewal time.0
): The maximum number of times that an access token can be used; a value of 0
implies infinite number of uses.0.0.0.0/0
, allowing usage from any network address.subject
, audiences
, and claims
fields support glob pattern matching; however, we highly recommend using hardcoded values whenever possible.Adding an identity to a project
To enable the identity to access project-level resources such as secrets within a specific project, you should add it to that project.
To do this, head over to the project you want to add the identity to and go to Project Settings > Access Control > Machine Identities and press Add identity.
Next, select the identity you want to add to the project and the project level role you want to allow it to assume. The project role assigned will determine what project level resources this identity can have access to.
Accessing the Infisical API with the identity
To access the Infisical API as the identity, you will need to obtain a JWT from your JWT issuer that meets the validation requirements configured in step 2.
Once you have obtained a valid JWT, you can use it to authenticate with Infisical at the /api/v1/auth/jwt-auth/login
endpoint.
We provide a code example below of how you might use the JWT to authenticate with Infisical to gain access to the Infisical API.
Sample code for inside an application
The shown example uses Node.js but you can use any other language to authenticate with Infisical using your JWT.
We recommend using one of Infisical’s clients like SDKs or the Infisical Agent to authenticate with Infisical using JWT Auth as they handle the authentication process for you.
Each identity access token has a time-to-live (TTL) which you can infer from the response of the login operation;
the default TTL is 2592000
seconds (30 days) which can be adjusted in the configuration.
If an identity access token exceeds its max TTL or maximum number of uses, it can no longer authenticate with the Infisical API. In this case, a new access token should be obtained by performing another login operation with a valid JWT.