Skip to main content

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

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:
Mini App Server → Neynar 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:
Miniapp 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:
Mini App Server → Neynar Server:
For Miniapp flow with user data:

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:
Mini App Server → Neynar Server:

Step 8: Register a Signed Key

Register the signer’s public key with the Farcaster protocol. Mini App Client → Mini App Server:
Mini App Server → Neynar Server:

Step 9: Start Polling

Begin polling the signer status to detect when it’s approved.
Polling API Implementation:

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):
Miniapp flow (NextAuth Session):

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:
  1. Secure Authentication: Using SIWF protocol with cryptographic nonces
  2. Signer Management: Creating and approving signers for Farcaster actions
  3. Multi-Platform Support: Works in web browsers and Farcaster mobile clients
  4. State Persistence: Maintains authentication across sessions
The system abstracts the complexity of Farcaster protocol interactions while providing a seamless user experience for both web and mobile environments. Feel Free to reach out with any questions or for further assistance in integrating this authentication flow into your Farcaster mini app!

Happy coding! 🎉