Central authentication & authorization service for CaptainBook internal tools. Manages users, permissions, and API keys.
https://auth.ops.withcaptainbook.com
All protected endpoints accept one of:
POST /api/login (browser use)POST /api/tokenPOST /api/keysAuthorization: Bearer <jwt_or_api_key>
Session-based login (sets cookie).
{
"email": "user@captainbook.io",
"password": "secret"
}
Returns: { "ok": true, "user": { "id", "name", "email", "role" } }
Get a JWT token (for programmatic access).
{
"email": "user@captainbook.io",
"password": "secret"
}
Returns: { "token": "eyJ...", "user": { ... } } — token valid for 7 days.
Clear session cookie.
Validate a token/API key and optionally check tool-level permission.
// Headers
Authorization: Bearer <user_token_or_api_key>
// Body (optional)
{ "tool": "dealroom" }
Returns:
// Without tool check
{ "valid": true, "user": { "id": 1, "email": "...", "name": "...", "role": "viewer" } }
// With tool check
{ "valid": true, "user": { ... }, "permission": "read" }
// No access
{ "valid": true, "user": { ... }, "permission": null, "error": "No access to this tool" }
// Admin users always get permission: "admin"
Add this middleware to any tool:
async function checkAuth(req, res, next) {
const token = req.headers.authorization;
if (!token) return res.status(401).json({ error: 'No token' });
const resp = await fetch('https://auth.ops.withcaptainbook.com/api/validate', {
method: 'POST',
headers: { 'Authorization': token, 'Content-Type': 'application/json' },
body: JSON.stringify({ tool: 'my-tool-slug' })
});
const data = await resp.json();
if (!data.valid) return res.status(401).json({ error: 'Invalid token' });
if (!data.permission) return res.status(403).json({ error: 'No access' });
req.user = data.user;
req.permission = data.permission; // 'read', 'write', or 'admin'
next();
}
List all users.
Create a user.
{
"email": "investor@example.com",
"name": "John Doe",
"password": "secure123",
"role": "viewer" // "admin" or "viewer"
}
Update user (name, email, role, status, password).
Delete a user and all their permissions/keys.
List registered tools.
Register a new tool.
{ "slug": "analytics", "name": "Analytics Dashboard", "url": "https://analytics.ops.withcaptainbook.com" }
Remove a tool (also deletes its permissions).
List all permissions (admin only).
Grant or update a permission.
{
"user_id": 2,
"tool_slug": "dealroom",
"level": "read" // "read", "write", or "admin"
}
Revoke a permission.
List your API keys (admins can pass ?user_id=N).
Create a new API key.
{ "name": "ci-deploy", "user_id": 1 }
Returns the full key once — save it immediately:
{ "ok": true, "key": "cb_a1b2c3...", "prefix": "cb_a1b2c3...", "warning": "Save this key now" }
Revoke an API key.
Get current user info and permissions.
Change your password.
{
"current_password": "old-pass",
"new_password": "new-secure-pass"
}