Authentication & Signer Management
Although titled “Mini app authentication”, this can also be used in web apps if you’d like.Overview
The authorization 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 Kit This authentication system is designed to work both in a regular web browser and inside a miniapp. In other words, it supports authentication when the miniapp context is not present (web browser) as well as when the app is running inside a miniapp. If you only need authentication for a web application, follow the Webapp flow; if you only need authentication inside a miniapp, follow the Miniapp flow.Architecture 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 (Miniapp) |
/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 | Miniapp 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. Webapp 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. Webapp flow (LocalStorage):State Management & Storage
Webapp flow State (LocalStorage)
Miniapp flow State (NextAuth Session)
Security & Configuration
EIP-712 Signature Validation
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