Skip to main content

HandCash Authentication Integration Guide

Prerequisites

  1. Create an application in the Developer Dashboard
  2. Configure callback URLs in your application settings
  3. Get your credentials (AppId and AppSecret)

Configure Callback URLs

Configure callback URLs in dashboard.handcash.io:
  1. Select your application
  2. Go to Settings or Configuration
  3. 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)
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-memory
Server: Database, Redis, session, or JWT

Step 3: Redirect to HandCash

The user will log in and authorize your app on 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

  1. Generate a private/public key pair
  2. Send the public key to HandCash during authorization
  3. User authorizes your app on HandCash
  4. Use the private key for all API calls - it serves as your authentication credential
  5. HandCash validates the private key matches the authorized public key

Check User Permissions

Error Handling

State Parameter Security

Recommended: Use the state parameter to prevent CSRF attacks and ensure the callback originated from your app session.

What This Means in Practice

1️⃣ App Generates State When Starting Connect

Generate a random, unguessable string and store it in your app session:
Include the state in the redirect URL:

2️⃣ Wallet Requires State

The HandCash wallet will:
  • Require state to be present in the authorization request
  • Echo the same state back in the callback URL
  • Treat state as 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:
If state mismatch → reject the request - This indicates a potential CSRF attack.

Security Best Practices

  • Use state parameter - Always include and validate state to 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