x-app-id header, and a user, with an
access token in Authorization: Bearer <accessToken>. Market data and quotes without a user need
only the app. Balances, deposits, trading, and withdrawals need a user. See
Base URL, app IDs & API keys for which headers go on which call.
Users sign in on the client, and your backend includes that user’s access token on trading calls.
Sign-in methods
Code for each provider is in Sign-in providers.
Wallet sign-in flow
1
Get a nonce
POST /auth/start with { "provider": "siwe" } and x-app-id. The response is
{ "type": "nonce", "nonce": "...", "statement"?: "..." }. When bot protection is active it
can instead be { "type": "challenge_required", "siteKey": "..." }. See
Bot protection.2
Build and sign the message
Build an EIP-4361 message with that nonce. Its domain must be one of your app’s allowed
origins. The SDK’s
buildSiweMessage produces the exact format. The user’s wallet signs it.3
Verify
POST /auth/verify with { "message": "...", "signature": "0x..." }. The response is
{ accessToken, refreshToken, user }.Tokens
The access token is bound to the app that issued it. Using it with another app’s
x-app-id fails.
The SDK stores the session and adds the header for you. In the browser, set
authDelivery: "cookie-refresh" on createAggClient to keep the refresh token in an HttpOnly
cookie scoped to the AGG API host and /auth routes. In that mode verify() and
exchangeAuthCode() can omit refreshToken from the JSON response.
If your backend already holds a user’s tokens, seed an SDK client with
client.setSession({ accessToken, refreshToken }).
Refresh a session
When a user-tier call returns401, refresh once and retry. If the refresh also fails, sign the
user in again.
Sign out
POST /auth/sign-out with the user’s token revokes all of that user’s tokens. client.signOut()
also clears the stored session.
Sign-in errors
Related
Sign-in providers
Code for SIWE, SIWS, Google, X, Apple, email, and Privy.
Account linking
Add more sign-in methods or wallets to one user.