Canvas provides a simple API token-based authentication system for secure remote access to the Canvas server. This document explains how to create, manage, and use API tokens with various clients.
API tokens are the primary authentication method for:
- canvas-electron
- canvas-cli
- canvas-shell (curl-based tools)
- browser extensions
- automated scripts and integrations
- all remote access
Each token is associated with a specific user account and has a unique identifier. Tokens start with the prefix canvas-
for easy identification and use secure cryptographic methods for generation and validation.
- Log in to the Canvas Web UI
- Navigate to Settings > API Tokens
- Click "Create New Token"
- Provide a name and optional expiration date
- Copy the generated token immediately (it will only be shown once)
# First authenticate with existing token or credentials
curl -X POST https://your-canvas-server/api/v2/auth/tokens \
-H "Authorization: Bearer canvas-your_existing_token" \
-H "Content-Type: application/json" \
-d '{"name": "My CLI Token", "description": "Token for CLI access"}'
API tokens can be used in several ways:
Add the token in the Authorization header:
curl https://your-canvas-server/api/v2/auth/me \
-H "Authorization: Bearer canvas-your_token_here"
curl https://your-canvas-server/api/v2/auth/me?token=canvas-your_token_here
# Set token permanently
canvas config set token canvas-your_token_here
# Or use environment variable
CANVAS_TOKEN=canvas-your_token_here canvas status
# Set token permanently
cs config token canvas-your_token_here
# Or provide with each command
cs --token=canvas-your_token_here status
curl https://your-canvas-server/api/v2/auth/tokens \
-H "Authorization: Bearer canvas-your_token_here"
curl -X DELETE https://your-canvas-server/api/v2/auth/tokens/TOKEN_ID \
-H "Authorization: Bearer canvas-your_token_here"
Canvas API tokens include several security features:
- Secure Generation: Tokens are created using cryptographically secure methods
- Secure Storage: Tokens are stored as SHA-256 hashes, not raw values
- Standard Format: All tokens use the
canvas-
prefix for easy identification - Expiration Support: Optional expiration dates can be set for sensitive tokens
- Usage Tracking: Each use of a token is logged with timestamps
- Create different tokens for different applications
- Use meaningful names to identify tokens in logs and UI
- Set expiration dates for sensitive tokens
- Revoke tokens when no longer needed
- Never share your tokens in public repositories or communications
- Use HTTPS when connecting to remote Canvas servers
- Regularly audit active tokens and their usage
If you're having issues with API token authentication:
- Verify the token is active in the Canvas Web UI
- Check that the token is being sent correctly (correct format, not expired)
- Make sure you're including the full token including the
canvas-
prefix - Check server logs for authentication errors
- Verify you're making HTTPS requests when connecting to remote servers
For more information, see the complete Canvas API documentation.