|
| 1 | +# Authentication Module |
| 2 | + |
| 3 | +This document provides a high-level overview of the authentication strategy used in our application, explaining the flow involving Firebase AppCheck, XMTP, and Ethereum wallet integration via Privy passkeys, as well as the two primary endpoints for user creation and authentication. |
| 4 | + |
| 5 | +## Loom Recordings |
| 6 | + |
| 7 | +[Convos Authentication Modeling Discussion](https://www.loom.com/share/0a1277074f2a4e989ecfe0141deac359) |
| 8 | +Participants: Ry, Michael, Thierry |
| 9 | +Date: Friday February 14, 2025 |
| 10 | + |
| 11 | +## Overview |
| 12 | + |
| 13 | +Our authentication mechanism involves two primary endpoints: |
| 14 | + |
| 15 | +- **Create User Endpoint**: Creates a new user account. It accepts four header keys and optional profile data. |
| 16 | +- **Authenticate Endpoint**: Authenticates an existing user and returns a JSON Web Token (JWT) for subsequent requests. |
| 17 | + |
| 18 | +All other endpoints require the JWT for authentication. |
| 19 | + |
| 20 | +## Authentication Flow |
| 21 | + |
| 22 | +1. **Passkey Authentication via Privy** |
| 23 | + |
| 24 | + - The user logs in using a passkey with Privy |
| 25 | + - Successful authentication provides access to a Privy account, which in turn gives access to a smart contract Ethereum wallet |
| 26 | + |
| 27 | +2. **Smart Contract Wallet as Signer** |
| 28 | + |
| 29 | + - The Ethereum wallet obtained from Privy acts as the cryptographic signer |
| 30 | + - This wallet is used to create an XMTP inbox |
| 31 | + |
| 32 | +3. **Signing the Firebase AppCheck Token** |
| 33 | + |
| 34 | + - The Firebase AppCheck token is provided by Firebase |
| 35 | + - The XMTP inbox on the client side signs the AppCheck token |
| 36 | + - The backend then verifies the cryptographic signature |
| 37 | + |
| 38 | +4. **JWT Generation** |
| 39 | + - Once verified, the backend issues a JWT |
| 40 | + - This JWT is then used to authenticate all subsequent API requests |
| 41 | + - There is no refresh token as the persistent cryptographic signer (passkey via Privy) handles re-authentication |
| 42 | + |
| 43 | +## Endpoints |
| 44 | + |
| 45 | +### Create User Endpoint |
| 46 | + |
| 47 | +**Purpose**: Creates a new user account |
| 48 | + |
| 49 | +**Headers** (all four required): |
| 50 | + |
| 51 | +1. **Installation ID**: Identifier for the XMTP inbox, derived from the device |
| 52 | +2. **Firebase AppCheck Token**: Provided by Firebase |
| 53 | +3. **Signed AppCheck Token**: The Firebase AppCheck token signed by the XMTP inbox (client-side) |
| 54 | +4. **XMTP Inbox ID**: The XMTP inbox ID of the user, created during the onboarding flow |
| 55 | + |
| 56 | +**Profile Data** (optional but currently always provided): |
| 57 | + |
| 58 | +- `profile_name`: Must be between 3 and 30 characters |
| 59 | +- `avatar_url`: No strict URL validation is enforced at this time |
| 60 | +- `description`: Cannot exceed 500 characters |
| 61 | + |
| 62 | +**Response**: Returns the newly created user's ID along with metadata such as createdAt, updatedAt, and the provided profile information |
| 63 | + |
| 64 | +### Authenticate Endpoint |
| 65 | + |
| 66 | +**Purpose**: Authenticates an existing user |
| 67 | + |
| 68 | +**Headers** (same four as above): |
| 69 | + |
| 70 | +- Installation ID |
| 71 | +- Firebase AppCheck Token |
| 72 | +- Signed AppCheck Token |
| 73 | +- Ethereum Wallet |
| 74 | + |
| 75 | +**Response**: Returns a JWT which is used for authenticating all further API calls |
| 76 | + |
| 77 | +## Package Organization |
| 78 | + |
| 79 | +All authentication-related code and documentation are located in the `feature/authentication` directory. |
| 80 | + |
| 81 | +## Additional Notes |
| 82 | + |
| 83 | +### Security |
| 84 | + |
| 85 | +The Firebase AppCheck token is signed on the client side by the XMTP inbox and verified by the backend. The integration with Privy and the smart contract wallet removes the need for refresh tokens, as the persistent signer can always re-authenticate. |
| 86 | + |
| 87 | +### Profile Data Validation |
| 88 | + |
| 89 | +Currently, the profile creation is always provided during the Create User process. In future iterations, if profile creation becomes optional or additional validation (e.g., URL validation for avatars) is required, this documentation and the corresponding code should be updated accordingly. |
0 commit comments