user-tagAuthorization flow

JWT Authentication

The auth() method allows you to authenticate a wallet and receive a JWT token. This is useful for backend authentication and verifying wallet ownership.

How it works:

  1. Opens a UI popup asking the user to sign a message

  2. Generates a random seed and creates a cryptographic nonce

  3. Signs intents (or empty array) with the nonce

  4. Sends the signed commitment to the API

  5. Returns a JWT token string

Basic Usage:

// Get JWT token for authentication
const wallet = wibe3.priorityWallet; // or any connected wallet
if (wallet) {
  const jwt = await wallet.auth();
  console.log("JWT token:", jwt);

  // Use JWT for backend authentication
  // Example: send to your backend API
  await fetch("https://your-api.com/authenticate", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${jwt}`,
      "Content-Type": "application/json",
    },
  });
}

Auth with Intents (Optional):

You can optionally pass intents to be signed during authentication:

Validate JWT Token:

You can validate a JWT token using the API:

Complete Example:

Important Notes:

  • The auth() method opens a UI popup that requires user interaction to sign the message

  • The JWT token is generated server-side and returned after successful signature verification

  • The token can be used for backend authentication to verify wallet ownership

  • The authentication process is safe - it only signs a message, not a transaction

  • You can optionally pass intents to be signed during authentication

Last updated