Authenticate with Private Key JWT
In this tutorial, you’ll learn how to use Private Key JWT to authenticate your OAuth client application to Qlik Cloud securely.
Instead of sharing a client secret, your application signs authentication requests with a private key, and Qlik Cloud validates them using your registered public key.
This approach avoids using a shared client secret and is suitable for applications that can securely manage private keys.
This tutorial uses a Web OAuth client with the client_credentials flow.
What you’ll learn
- How to generate a public/private key pair for OAuth authentication
- How to register your public key with an OAuth client in Qlik Cloud
- How to sign JWT assertions and request access tokens
- How to use tokens to authenticate API requests
Prerequisites
- A Qlik Cloud tenant with Tenant Admin access
- OpenSSL installed on your development machine
- A programming language with the required libraries (JavaScript with
jose, or Python withPyJWT,cryptography, andrequests)
How it works
Private Key JWT lets your application prove its identity using asymmetric cryptography instead of a shared secret:
- You generate a public/private key pair and register the public key with your OAuth client in Qlik Cloud
- Your application creates a JWT (JSON Web Token) signed with its private key
- Your application sends the signed JWT to Qlik Cloud’s token endpoint
- Qlik Cloud validates the signature using your registered public key and returns an access token
- Your application uses the access token for API requests
The private key remains with your application and is used to sign the JWT assertion. Qlik Cloud validates the assertion using the registered public key.
Step 1: Generate your key pair
Generate a public/private key pair that will be used to sign the JWT assertion and register the public key with your OAuth client.
For this tutorial, use OpenSSL to generate a 2048-bit RSA key pair, the minimum key size for RS256:
openssl genrsa -out private_key.pem 2048openssl rsa -in private_key.pem -pubout -out public_key.pemFor supported algorithms and production key-size guidance, see Private Key JWT reference.
Keep your private key (private_key.pem file) secure and never share it.
It is used to sign JWT assertions.
Convert the public key from PEM to JSON Web Key (JWK) format using the jose package:
Save the JWK output. You’ll register it with your OAuth client in the next step.
For other algorithms (RS512, ES384), see Supported algorithms in the reference.
Step 2: Create and configure your Web OAuth client
Now that you have your public key in JWK format, create a new Web OAuth client and register it.
-
In the Administration activity center, go to OAuth.
-
Select Create new, then Web as the client type.
-
Enter a name.
-
Select the
user_defaultscope. -
Under Authentication method, select Private Key JWT.
-
Paste your JWK (from Step 1) into the Public key field.
WarningPaste only the public key in JWK format. Never upload or share your private key.
-
For the
client_credentialsflow used in this tutorial, select the Machine-to-machine checkbox. -
Select Create.
-
Copy your Client ID for use in the next step.
-
Set the consent method to Trusted (select the action menu and select Change consent method).
Your OAuth client is now configured for Private Key JWT authentication.
Qlik Cloud will validate JWT signatures against this public key during token requests.
Step 3: Request an access token
To request an access token, first generate a signed JWT assertion, then send the assertion to the token endpoint.
Generate the JWT assertion
Use your private key to create a signed JWT assertion:
Copy the output (your signed JWT assertion). You’ll use it to request an access token in the next section.
Exchange the assertion for a token
Send your JWT assertion to the Qlik Cloud token endpoint. Use one of the methods below:
A successful response returns your access token:
{ "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...", "token_type": "bearer", "expires_at": "2026-01-15T18:24:31.000Z", "expires_in": 21600, "scope": "user_default"}Use the token in API requests
Add your access token to the Authorization header:
Troubleshooting
Private Key JWT authentication failures return 401 Unauthorized with a detail field describing the failure
and an error code.
| Error detail | Error code | Cause | Solution |
|---|---|---|---|
| No matching public key found | OAUTH-16 | The kid header is missing, or no registered JWK matches that kid and alg. | Set kid to the kid of the registered JWK and make sure alg matches. |
| JWT Verification failed: Assertion failure on claim ‘aud’ | OAUTH-16 | aud does not match your tenant token endpoint. | Set aud to https://<TENANT>.qlikcloud.com/oauth/token. |
| JWT Verification failed: Unexpected issuer | OAUTH-16 | iss does not match your client ID. | Set iss to your OAuth client ID. |
| JWT Verification failed: Assertion failure on claim ‘sub’ | OAUTH-16 | sub does not match your client ID. | Set sub to your OAuth client ID. |
| JWT Verification failed: Assertion lifetime exceeds maximum of 3600 seconds | OAUTH-16 | exp - iat is greater than 3600 seconds. | Shorten the assertion lifetime to 3600 seconds or less. |
| Invalid authentication method used for client | OAUTH-47 | client_assertion_type is incorrect, or the client is not configured for Private Key JWT. | Use the documented client_assertion_type and select Private Key JWT for the client. |
For supported signing algorithms, JWT requirements, and JWK specifications, see Private Key JWT reference.
Next steps
- Private Key JWT reference: Algorithms and JWK specifications
- OAuth API: Reference for the
/oauth/tokenendpoint, request parameters, and responses - Create an OAuth2 client: Set up a new OAuth client
- OAuth scopes: Understand permissions and scope requirements