Install the client

First your environment variables, then the Block-Auth client for your language.

Your environment variables

Before you touch any code, set up your server environment variables. Pick the keys based on where your app is going to run. Each environment has its own in Applications » Integration details, and they don't mix:

Where your app runsWhich keys to useWhere you put them
Your computer (localhost)The Development ones. They work right away.The .env on your computer
Your live serverThe Production ones. They work once you validate your domain.Your server's environment variables

Put these variables in your server environment. Here they are with your data:

These files use example values. Fill in your data once in the SDK Quickstart and they come out with yours, ready to copy.Fill in my data

In a .env next to your backend package.json. Load it with node --env-file=.env (Node 20.6+) or the dotenv package (import 'dotenv/config' at the top of your entry file).

.env
APP_URL=http://localhost:4000
BLOCKAUTH_API_KEY=your_api_key
BLOCKAUTH_API_SECRET=<paste the API Secret from the Dashboard>
SESSION_SECRET=<generate one: openssl rand -hex 32>

Replace the API Secret placeholder with your API Secret, copied straight from the Dashboard. Never paste it on this site.

Replace the SESSION_SECRET placeholder with a random value generated on your computer: openssl rand -hex 32.

Replace your_api_key with your API Key, or fill in your data in the SDK Quickstart and it is filled in for you.

Install the client

Install the Block-Auth client for your language, in your project folder (the one with its package.json, composer.json, requirements.txt or .csproj). It gives you AuthCodeClient, the same in every language.

Terminal · in your project folder
npm install @block-auth.io/node express express-session

Without the Block-Auth client (optional)

If you installed the client above, skip this section: the client already makes these calls for you in the next steps. Use it only if you can’t or don’t want to install any package. In that case, instead of the client, your login route and your callback call the API with plain HTTP, from any language. Send the SHA-256 hash (hex) of your apiSecret, never the secret itself: compute it on your computer with printf '%s' "$BLOCKAUTH_API_SECRET" | sha256sum | cut -d' ' -f1.

Your login route asks for a link and your callback redeems the code:

Terminal · to try it
curl -X POST https://wss.block-auth.io/api/auth/authorize \
  -H 'Content-Type: application/json' \
  -d '{
    "apiKey": "your_api_key",
    "apiSecret": "sha256_hex_of_your_api_secret",
    "redirectUri": "https://your-app.com/blockauth/callback",
    "state": "random_value_kept_in_the_session"
  }'

Replace the sha256_… value with the SHA-256 hash (hex) of your API Secret. Compute it on your computer, never on a web page.

Replace your_api_key with your API Key, or fill in your data in the SDK Quickstart and it is filled in for you.

Replace https://your-app.com with your app URL, or fill in your data in the SDK Quickstart and it is filled in for you.

Every response is { "success": true, "message": … }; for /api/auth/token, message holds address, did and roles. To verify a webhook, compute v1= + HMAC-SHA256 of timestamp.body (the X-BlockAuth-Timestamp header, a dot and the raw body), keyed with the SHA-256 hash of your apiSecret, and compare it with X-BlockAuth-Signature. All the parameters and errors are in User login.