Authentication & Signer Management
This document provides a comprehensive overview of the authentication system and signer creation process in your Farcaster mini app. The system uses Sign in with Farcaster (SIWF) protocol to authenticate users and create signers for Farcaster protocol interactions. Although titled “Mini app authentication”, this can also be used in web apps if you’d like.Overview
The authentication system is built around signers - cryptographic keys that allow your application to act on behalf of a user within the Farcaster protocol. Full code for this flow can be found in the Neynar Mini App Starter KitArchitecture Components
The system involves four main components:API Endpoints
Endpoint | Method | Purpose | Step |
---|---|---|---|
/api/auth/nonce | GET | Generate authentication nonce | Step 1 |
/api/auth/signers | GET | Fetch user signers | Step 5 |
/api/auth/session-signers | GET | Fetch signers with user data | Step 5 (Backend) |
/api/auth/signer | POST | Create new signer | Step 7 |
/api/auth/signer | GET | Check signer status | Step 9 |
/api/auth/signer/signed_key | POST | Register signed key | Step 8 |
/api/auth/[...nextauth] | GET/POST | NextAuth handlers | Backend Flow |
Complete Authentication Flow
Step 1: Get the Nonce
The authentication process begins by fetching a cryptographic nonce from the Neynar server. Mini App Client → Mini App Server:Step 2: Inject Nonce in Sign in with Farcaster
The nonce is used to create a Sign in with Farcaster message.Step 3: Ask User for the Signature
The user is prompted to sign the SIWF message through their Farcaster client. Frontend Flow:Step 4: Receive Message and Signature
Once the user signs the message, the client receives the signature.Step 5: Send to /api/auth/signers to Fetch Signers
With the signed message and signature, fetch existing signers for the user. Mini App Client → Mini App Server:Step 6: Check if Signers are Present
Determine if the user has existing approved signers.Step 7: Create a Signer
If no signers exist, create a new signer. Mini App Client → Mini App Server:Step 8: Register a Signed Key
Register the signer’s public key with the Farcaster protocol. Mini App Client → Mini App Server:Step 9: Start Polling
Begin polling the signer status to detect when it’s approved.Step 10: Show Signer Approval URL
Display QR code for desktop users or deep link for mobile users.Step 11: Store Signers
Once approved, store the signers in appropriate storage. Frontend Flow (LocalStorage):State Management & Storage
Frontend Flow State (LocalStorage)
Backend Flow State (NextAuth Session)
Security & Configuration
EIP-712 Signature Validation
The system uses EIP-712 typed data signing for secure signer registration:Required Environment Variables
Flow Detection
Integration Examples
Checking Authentication Status
Using Signers for Farcaster Actions
Summary
Authentication flow provides a comprehensive system for:- Secure Authentication: Using SIWF protocol with cryptographic nonces
- Signer Management: Creating and approving signers for Farcaster actions
- Multi-Platform Support: Works in web browsers and Farcaster mobile clients
- State Persistence: Maintains authentication across sessions