Overview
PriceSignal uses Firebase Authentication with JWT (JSON Web Tokens) to secure API access. All GraphQL queries, mutations, and subscriptions require a valid Firebase JWT token.Authentication Flow
- Authenticate with Firebase on the client side
- Obtain a Firebase JWT token
- Include the token in your GraphQL requests
- Token is validated against Firebase’s public keys
Firebase Configuration
The API is configured to validate tokens from the Firebase project:https://securetoken.google.com/nxtspechttps://securetoken.google.com/nxtspecnxtspecThe API validates token issuer, audience, and lifetime automatically.
Sending Authenticated Requests
You can authenticate requests in two ways:Option 1: Authorization Header (Recommended)
Include the JWT token in theAuthorization header using the Bearer scheme:
Option 2: HTTP-Only Cookie
For browser-based applications, you can use the/api/login endpoint to set an HTTP-only cookie:
HTTP-only cookies provide additional security by preventing JavaScript access to tokens. The cookie is set with
Secure and SameSite=Strict flags.Token Validation
When a request is received, the API performs the following validations:Verifies the token was issued by
https://securetoken.google.com/nxtspecConfirms the token audience matches
nxtspecChecks that the token has not expired
Validates the token signature using Firebase’s public keys
User Context
After successful authentication, the user’s identity is available in GraphQL resolvers:- Scope queries to the authenticated user
- Enforce user-level permissions
- Track rule ownership and access control
Error Responses
If authentication fails, you’ll receive an appropriate HTTP status code:No token provided or token is invalid
Token is valid but user lacks permission for the requested resource
WebSocket Authentication
For WebSocket subscriptions, include the token in the connection parameters:Security Best Practices
Never expose Firebase tokens in client-side code or version control. Tokens should be obtained dynamically from Firebase Authentication.
- Use HTTPS for all API requests in production
- Refresh tokens before they expire (Firebase tokens are valid for 1 hour)
- Store tokens securely (use HTTP-only cookies or secure storage)
- Implement proper logout to invalidate sessions
- Monitor for suspicious authentication patterns
Getting Your Firebase Credentials
- Create a Firebase project at console.firebase.google.com
- Enable Authentication with your preferred sign-in methods
- Add your app to the Firebase project
- Use the Firebase SDK to authenticate users and obtain tokens