Token helpers
Token helpers and verification
Create and validate API tokens for programmatic access to Scalekit APIs in Java.
Use tokens for service access that is not a full end-user session. Create a token, store it securely, and validate it on incoming requests.
create
Section titled “create”#create
Creates a new API token for an organization with custom options.
The organization ID to scope the token to
Optional user ID to scope the token to a specific user
Optional custom claims key-value pairs
Optional expiry timestamp
Optional human-readable description
The created resource.
import java.util.HashMap;import java.util.Map;import com.google.protobuf.Timestamp;
Map<String, String> claims = new HashMap<>();claims.put("environment", "production");
Timestamp expiry = Timestamp.newBuilder() .setSeconds(System.currentTimeMillis() / 1000 + 86400) .build();
scalekitClient.tokens().create("org_123", "user_123", claims, expiry, "Production access token");validate
Section titled “validate”#validate
Validates an API token and returns associated context.
The opaque token string or token_id (apit_xxxxx)
Verified claims or result.
scalekitClient.tokens().validate("apit_xxxxx");invalidate
Section titled “invalidate”#invalidate
Invalidates (soft deletes) an API token.
The opaque token string or token_id (apit_xxxxx)
No return value
scalekitClient.tokens().invalidate("apit_xxxxx");#list
Lists API tokens for an organization and user with pagination.
The organization ID to list tokens for
The user ID to filter tokens for
Page size (default 10, max 30)
Pagination cursor for next page
Paginated results.
scalekitClient.tokens().list("org_123", "user_123", 20, "");update
Section titled “update”#update
Updates the custom claims and/or description of an existing API token.
The opaque token string or token_id (apit_xxxxx)
Claims to merge; set value to "" to remove a claim
Replacement description; null leaves unchanged, empty.
The updated resource.
import java.util.HashMap;import java.util.Map;
Map<String, String> newClaims = new HashMap<>();newClaims.put("environment", "staging");newClaims.put("old_claim", ""); // Remove this claim
scalekitClient.tokens().update("apit_xxxxx", newClaims, "Updated description");