Authentication Guide (RS256)
To authenticate with our API, you’ll need to generate a public/private RSA key pair. We use RS256 (RSA Signature with SHA-256) to sign and verify requests securely. This guide will help you:- ✅ Generate your keys
- 🛠 Use them to sign JWTs
- 🔑 Share your public key with us
- 🔄 Decode webhook JWTs from us
1. ✅ Generate RSA Key Pair
Run the following command in your terminal to generate a 2048-bit RSA key pair:2. 🛠 Encode your JWTs
JSON Web Tokens (JWTs) are a compact, URL-safe means of representing claims securely between two parties. When using RS256, you’ll sign the JWT with your private key, and we’ll verify it with your public key.JWT Structure
A JWT consists of three parts separated by dots (.):
- Header: Contains the token type and signing algorithm
- Payload: Contains the claims (data)
- Signature: Verifies the token hasn’t been altered
| Claim | Description | Example |
|---|---|---|
iss | Issuer - Your partner_uid (provided by us) | "iss": "your_partner_uid" |
iat | Issued At - Current timestamp (seconds since epoch) | "iat": 1686104400 |
exp | Expiration Time - Must be within 30 minutes of iat | "exp": 1686106200 |
Code Examples
PHP
Using the firebase/php-jwt library:Node.js
Using the jsonwebtoken library:Python
Using the PyJWT library:Important Notes
- Token Expiration: Your token must expire within 30 minutes of creation. The server will reject tokens with longer expiration times.
-
Token Format: Always include the token in your Authorization header with the “Bearer” prefix:
- Security: Keep your private key secure. Never share it or commit it to version control.
-
Validation: The server validates:
- The token signature using your public key
- The presence of required claims (
iss,iat,exp) - That the token hasn’t expired
- That the expiration is within 30 minutes of issuance
3. 🔑 Share Your Public Key
After generating your key pair, you need to share your public key with us. This allows us to verify the JWTs you sign.- Contact your account manager or support team
- Send them your
public_key.pemfile - We’ll associate it with your partner account
4. 🔄 Decoding Webhook JWTs
When you receive webhooks from our service, the payload is secured with a JWT signed using our private key. To verify and decode these JWTs, you’ll need to use our public key.Webhook JWT Structure
Webhooks sent from our service include a JWT in theAuthorization header with the following structure:
- Header: Contains
alg: "RS256"andtyp: "JWT" - Payload: Contains:
iss: Always set to"unihop"(our issuer identifier)exp: Expiration timestamp (30 minutes from creation)payload: The actual webhook data
Verification Process
When receiving a webhook, you should:- Extract the JWT from the
Authorizationheader - Verify the JWT signature using our public key
- Check that the
issclaim is"unihop" - Ensure the token hasn’t expired
- Extract and process the webhook data from the
payloadfield
Code Examples
PHP
Using the firebase/php-jwt library:Node.js
Using the jsonwebtoken library:Python
Using the PyJWT library:Important Security Considerations
- Always Verify the Signature: Never process webhook data without first verifying the JWT signature with our public key.
-
Check the Issuer: Confirm that the
issclaim is"unihop"to ensure the webhook came from our service. - Validate Expiration: Reject tokens that have expired to prevent replay attacks.
- Implement Idempotency: Webhooks may be sent multiple times in rare cases. Implement idempotency checks to avoid processing the same webhook twice.
- Use HTTPS: Always use HTTPS for your webhook endpoint to ensure the data remains encrypted in transit.
Obtaining Our Public Key
To verify webhooks from our service, you’ll need our public key. Contact your account manager or support team to obtain the public key file (unihop_public_key.pem).
Testing Webhook Verification
You can test your webhook verification implementation using our webhook testing tool in the developer dashboard. This allows you to send test webhooks to your endpoint and verify that your verification logic works correctly.Testing Your JWT
You can use online tools like jwt.io to verify your JWT is correctly formatted:- Paste your JWT in the “Encoded” field
- Paste your public key in the “Verify Signature” section
- Confirm the signature is verified and the payload contains the correct claims
Troubleshooting
If you’re experiencing authentication issues, check:- Your JWT includes all required claims (
iss,iat,exp) - The
issclaim matches your partner_uid - The token hasn’t expired
- The expiration time is within 30 minutes of the issued time
- You’re using the correct private key to sign the token
- We have your correct public key on file
- The Authorization header format is correct (
Bearer <token>)