HandCash Authentication Integration Guide
Prerequisites
- Create an application in the Developer Dashboard
- Configure callback URLs in your application settings
- Get your credentials (
AppIdandAppSecret)
Configure Callback URLs
Configure callback URLs in dashboard.handcash.io:- Select your application
- Go to Settings or Configuration
- Set:
- Authorization Success URL: Where users redirect after authorization (e.g.,
https://yourapp.com/auth/success) - Authorization Failed URL: Where users redirect if they decline (e.g.,
https://yourapp.com/auth/failed)
- Authorization Success URL: Where users redirect after authorization (e.g.,
Important: Use HTTPS in production. For local development,
http://localhost is allowed.Key Generation
Required Dependency
Generate Key Pair
Authentication Flow
Step 1: Generate Keys
Step 2: Store Private Key
Store the private key securely: Client:localStorage, sessionStorage, or in-memoryServer: Database, Redis, session, or JWT
Step 3: Redirect to HandCash
Recommended: Use State Parameter for CSRF ProtectionFor enhanced security, include a
state parameter to prevent CSRF attacks. See the State Parameter Security section below.Step 4: Handle Callback
After authorization, HandCash redirects to your Authorization Success URL. Retrieve the stored private key and validate:Step 5: Store Private Key for Session
Associate the private key with the user’s session:How It Works
- Generate a private/public key pair
- Send the public key to HandCash during authorization
- User authorizes your app on HandCash
- Use the private key for all API calls - it serves as your authentication credential
- HandCash validates the private key matches the authorized public key
Check User Permissions
Error Handling
State Parameter Security
What This Means in Practice
1️⃣ App Generates State When Starting Connect
Generate a random, unguessable string and store it in your app session:2️⃣ Wallet Requires State
The HandCash wallet will:- Require
stateto be present in the authorization request - Echo the same
stateback in the callback URL - Treat
stateas proof that the key came from the same app session that initiated connect
3️⃣ Wallet Redirects Back with Same State
After authorization, HandCash redirects to your callback URL with the state included:4️⃣ App Validates State
Validate that the state matches the one stored in your session:Security Best Practices
- Use state parameter - Always include and validate
stateto prevent CSRF attacks - Store private keys securely - Use encrypted storage or secure sessions
- Use HTTPS - Always use HTTPS for redirect URLs
- Validate private keys - Check validity before making API calls
- Protect the private key - Treat it as sensitive authentication data