- Docs
- CBTC Authentication
CBTC Authentication
Overview: How Authentication Works for CBTC on Canton
Section titled “Overview: How Authentication Works for CBTC on Canton”All CBTC operations go through the Canton Ledger API, which requires a valid JWT (JSON Web Token) for every request. The JWT is issued by an OIDC (OpenID Connect) provider connected to your Canton participant node.
This guide covers two authentication options for developers building with CBTC and the Canton Network:
- Keycloak (officially supported by BitSafe)
- Auth0 (community example, not officially maintained) For deeper background on how Canton handles authentication and authorization at the platform level, see the Canton Authorization Documentation.
CBTC Authentication Flow: JWT and OIDC
Section titled “CBTC Authentication Flow: JWT and OIDC”sequenceDiagram participant App as Your Application participant OIDC as OIDC Provider<br>(Keycloak / Auth0) participant Canton as Canton Participant<br>(Ledger API) App->>OIDC: 1. Request token (client credentials or auth code) OIDC-->>App: 2. JWT access token App->>Canton: 3. API call with Bearer token Canton-->>App: 4. Response
Set Up Keycloak for CBTC Authentication (Officially Supported) ✅
Section titled “Set Up Keycloak for CBTC Authentication (Officially Supported) ✅”Keycloak is the officially supported OIDC provider for CBTC integrations. BitSafe engineering provides support for Keycloak-based authentication.
Prerequisites
Section titled “Prerequisites”- Keycloak instance running and accessible
- A realm configured for your Canton participant
- A client application registered in Keycloak
Step 1: Register a Client
Section titled “Step 1: Register a Client”In your Keycloak admin console:
- Navigate to your realm → Clients → Create client
- Set Client type to
OpenID Connect - Set Client ID (e.g.,
cbtc-minting-app) - Enable Client authentication (for server-to-server flows)
- Under Service account roles, enable as needed
Step 2: Configure Your Canton Participant
Section titled “Step 2: Configure Your Canton Participant”Your Canton participant must be configured to trust your OIDC provider. Participant configuration is complex and environment-specific. Refer to the official validator operator documentation:
Canton Validator Operator Guide →
Step 3: Obtain a Token
Section titled “Step 3: Obtain a Token”Client Credentials flow (for server-to-server / backend integrations):
curl -X POST "https://<your-keycloak>/auth/realms/<your-realm>/protocol/openid-connect/token" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=client_credentials" \ -d "client_id=cbtc-minting-app" \ -d "client_secret=$CLIENT_SECRET"Password grant flow (for user-facing / interactive applications):
curl -X POST "https://<your-keycloak>/auth/realms/<your-realm>/protocol/openid-connect/token" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=password" \ -d "client_id=cbtc-minting-app" \ -d "username=$KEYCLOAK_USERNAME" \ -d "password=$KEYCLOAK_PASSWORD"Response (both flows):
{ "access_token": "eyJhbGciOiJSUzI1NiIs...", "expires_in": 300, "token_type": "Bearer"}Step 4: Use the Token
Section titled “Step 4: Use the Token”Include the token in all Canton Ledger API calls:
curl -X POST "https://<your-participant>/v2/state/active-contracts" \ -H "Authorization: Bearer $ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d '{... }'Token Refresh
Section titled “Token Refresh”Tokens expire (typically 5 minutes for Keycloak). Your application should:
- Cache the token until near expiry
- Request a new token before the current one expires
- Retry failed requests with a fresh token if you receive a
401
Set Up Auth0 for CBTC Authentication (Community Example) ⚠️
Section titled “Set Up Auth0 for CBTC Authentication (Community Example) ⚠️”Prerequisites
Section titled “Prerequisites”- Auth0 tenant and API configured
- Application registered as Machine to Machine (for backend) or Single Page Application (for frontend)
Step 1: Create an Auth0 API
Section titled “Step 1: Create an Auth0 API”In the Auth0 dashboard:
- Navigate to Applications → APIs → Create API
- Set Name (e.g.,
Canton Ledger API) - Set Identifier to your participant’s Ledger API URL
- Set Signing Algorithm to
RS256
Step 2: Register a Machine-to-Machine Application
Section titled “Step 2: Register a Machine-to-Machine Application”- Navigate to Applications → Create Application
- Select Machine to Machine Applications
- Authorise the application to call your Canton Ledger API
- Note the Client ID and Client Secret
Step 3: Configure Your Canton Participant
Section titled “Step 3: Configure Your Canton Participant”Point your participant to Auth0’s JWKS endpoint. Participant configuration is complex and environment-specific. Refer to the official validator operator documentation:
Canton Validator Operator Guide →
Step 4: Obtain a Token
Section titled “Step 4: Obtain a Token”curl -X POST "https://<your-auth0-domain>/oauth/token" \ -H "Content-Type: application/json" \ -d '{ "client_id": "'$CLIENT_ID'", "client_secret": "'$CLIENT_SECRET'", "audience": "https://<your-participant>/v2/", "grant_type": "client_credentials" }'Step 5: Use the Token
Section titled “Step 5: Use the Token”Same as Keycloak. Include the Bearer token in all API requests.
Wallet-Based Authentication for Canton dApps
Section titled “Wallet-Based Authentication for Canton dApps”For applications that use Canton-compatible wallets (Loop, Console/Zoro, Bron), authentication is handled by the wallet provider. Your application receives a JWT through the wallet’s SDK or connect flow.
Supported wallets:
- Loop Wallet
- Console / Zoro Wallet
- Bron Wallet
- WalletConnect (for dApp integrations)
- Node login (direct participant authentication) See the Integration Guides for wallet-specific connection patterns.
Troubleshooting
Section titled “Troubleshooting”| Issue | Cause | Resolution |
|---|---|---|
401 Unauthorized on every request |
JWT not trusted by participant | Verify JWKS URL in participant config matches your OIDC provider |
| Token expires immediately | Clock skew between OIDC provider and participant | Sync system clocks (NTP) |
| CORS errors in browser | Ingress not configured for CORS | Add CORS annotations to your ingress - see Minting App Installation Guide |
invalid_grant from OIDC provider |
Client secret rotated or incorrect | Regenerate and update client secret |
JWT Security Best Practices for Canton Applications
Section titled “JWT Security Best Practices for Canton Applications”- Never expose client secrets in frontend code. Use the Client Credentials flow only from backend services.
- Rotate secrets regularly. Update client secrets in both your OIDC provider and your application config.
- Use short-lived tokens. The default 5-minute expiry is appropriate for most use cases.
- Restrict party access. Configure your JWT claims to limit which Canton parties a token can act as.
Ask the docs
Answers come only from this documentation and can be wrong. Check the linked pages.
Ask a question about BitSafe, CBTC or the developer guides. For example: