Authentication
BrainMaps API uses token-based authentication. There are two types of tokens:
- Session Tokens (Web Application)
- Personal Access Tokens (CLI/API Usage)
Session Tokens
Session tokens are automatically created when you log in through the web interface. These tokens:
- Are created on login
- Are automatically revoked on logout
- Cannot be manually created or revoked
- Are intended for web session management only
Personal Access Tokens
Personal Access Tokens (PATs) are long-lived tokens intended for CLI tools and API integrations. These tokens:
- Can be created manually through the API or web interface
- Persist until manually revoked
- Can have custom names for easy identification
- Are ideal for CLI tools and automated scripts
Creating a Personal Access Token
- Log in to the BrainMaps platform
- Go to your Account Settings
- Navigate to the API Tokens section
- Click “Create New Token”
- Give your token a descriptive name
- Copy the token immediately (it won’t be shown again)
Using Tokens with CLI
For automated or scripted usage of the CLI tool, you can authenticate using a token from the environment:
export BRAINMAPS_API_KEY=your_token_here
brainmaps --visualOr directly when running the command:
BRAINMAPS_API_KEY=your_token_here brainmaps --visualYou can also store tokens in your .env file:
BRAINMAPS_API_KEY=your_token_hereThe CLI will automatically:
- Verify the token on startup
- Skip the login screen if the token is valid
- Fall back to the login screen if the token is invalid or missing
Token Security
- Keep your tokens secure and never share them
- Store tokens in environment variables or secure configuration files
- Avoid committing tokens to version control
- Revoke tokens immediately if they’re compromised
- Consider rotating tokens periodically for security
Managing Tokens
You can manage your tokens through:
- The web platform interface
- The CLI tool:
brainmaps token revoke <token_id> - The API endpoints (for programmatic management)
Token Expiration
- Session tokens expire after inactivity or logout
- Personal Access Tokens remain valid until manually revoked
API Authentication
All authenticated requests should include the token in the Authorization header:
curl http://localhost:8000/api/brains/ \
-H "Authorization: Token YOUR_TOKEN"Web Authentication Flow
- User submits login credentials
- Server validates credentials
- Server generates session token
- Token is stored in browser
- Token is included in subsequent requests
- Token is invalidated on logout