Skip to main content

Token Generation

This page walks through the full flow: client registration, JWT creation, and obtaining access tokens.


1. Client Registration

1.1 Generate an RSA Key Pair

Generate an RSA key pair suitable for RS256 (2048-bit recommended):

openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048
openssl rsa -in private_key.pem -pubout -out public_key.pem
  • Keep private_key.pem secret and secure
  • Use public_key.pem for registration

1.2 Register Your Public Key

Send public_key.pem to your Uzabase Customer Success Manager or appointed technical contact.

After registration, you will receive:

CredentialDescription
client_idYour client identifier
kidKey identifier linked to your registered public key

You will use client_id as both iss and sub when generating JWTs.


2. Client Invocations

These steps are performed each time your client needs to authenticate and call the API.

2.1 Generate a JWT

Create a JWT with the following header and payload, then sign it with your private key using RS256.

JWT Structure

FieldValue
algRS256
typJWT
kidKey ID issued by Uzabase

Claim Details

ClaimDescription
issIssuer — your client_id
subSubject — your client_id
audAudience — must be https://datafeed.ub-speeda.com/token
iatIssued-at time (Unix timestamp)
expExpiration time (Unix timestamp); within 5 minutes recommended
jtiUnique ID per request (UUID recommended)

Sample Code

import jwt
import time
import uuid

private_key = open("private_key.pem").read()

payload = {
"iss": "YOUR_CLIENT_ID",
"sub": "YOUR_CLIENT_ID",
"aud": "https://datafeed.ub-speeda.com/token",
"iat": int(time.time()),
"exp": int(time.time()) + 300,
"jti": str(uuid.uuid4()),
}

signed_jwt = jwt.encode(
payload,
private_key,
algorithm="RS256",
headers={"kid": "YOUR_KID"},
)

2.2 Request an Access Token

Exchange the signed JWT for an access token.

Endpoint: POST https://datafeed.ub-speeda.com/token

Request Parameters

ParameterValue
grant_typeclient_credentials (fixed)
client_idYour client_id
client_assertion_typeurn:ietf:params:oauth:client-assertion-type:jwt-bearer (fixed)
client_assertionYour signed JWT from step 2.1

Example Response

{
"access_token": "xxx.yyy.zzz",
"token_type": "bearer",
"expires_in": 300
}

Sample Code

import requests

response = requests.post(
"https://datafeed.ub-speeda.com/token",
headers={"Content-Type": "application/x-www-form-urlencoded"},
data={
"grant_type": "client_credentials",
"client_id": "YOUR_CLIENT_ID",
"client_assertion_type": "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
"client_assertion": signed_jwt,
},
)

access_token = response.json()["access_token"]

2.3 Use the Access Token

Include the access token in the Authorization header for all API requests.

Sample Code

import requests

response = requests.get(
"https://datafeed.ub-speeda.com/private-company/v1/companies",
headers={"Authorization": f"Bearer {access_token}"},
params={"country": "KOR"},
)

print(response.json())

2.4 Quick Setup Guide

The following complete examples combine steps 2.1, 2.2, and 2.3 — generating the JWT, exchanging it for an access token, and making an API call — in a single runnable snippet.

Prerequisites

Requires Python 3.8+.

pip install pyjwt[crypto] requests
import jwt
import time
import uuid
import requests

# ── Step 2.1: Generate a JWT ─────────────────────────────────────────────────
private_key = open("private_key.pem").read()

signed_jwt = jwt.encode(
{
"iss": "YOUR_CLIENT_ID",
"sub": "YOUR_CLIENT_ID",
"aud": "https://datafeed.ub-speeda.com/token",
"iat": int(time.time()),
"exp": int(time.time()) + 300,
"jti": str(uuid.uuid4()),
},
private_key,
algorithm="RS256",
headers={"kid": "YOUR_KID"},
)

# ── Step 2.2: Request an Access Token ────────────────────────────────────────
token_response = requests.post(
"https://datafeed.ub-speeda.com/token",
headers={"Content-Type": "application/x-www-form-urlencoded"},
data={
"grant_type": "client_credentials",
"client_id": "YOUR_CLIENT_ID",
"client_assertion_type": "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
"client_assertion": signed_jwt,
},
)
access_token = token_response.json()["access_token"]

# ── Step 2.3: Call the API ────────────────────────────────────────────────────
response = requests.get(
"https://datafeed.ub-speeda.com/private-company/v1/companies",
headers={"Authorization": f"Bearer {access_token}"},
params={"country": "KOR"},
)
print(response.json())

Notes

  • Access tokens are intentionally short-lived (typically 5 minutes). Re-issue as needed.
  • Protect your private key — never share it or commit it to version control.
  • Each JWT must have a unique jti claim.