Version: v2.32.0 | Last Updated: 2025-06-17 | Status: PRODUCTION VERIFIED
EntityDB provides a secure authentication system using JWT session tokens with embedded credential storage. As of v2.29.0, user credentials are stored directly in the user entity's content field as salt|bcrypt_hash, eliminating the need for separate credential entities.
⚠️ BREAKING CHANGE in v2.29.0: Authentication architecture has fundamentally changed. User credentials are now embedded in user entities. NO BACKWARD COMPATIBILITY - all users must be recreated.
- Login: Submit username/password to receive session token
- Authorization: Include
Authorization: Bearer <token>header in API requests - Session Management: Tokens expire automatically and can be refreshed
- Logout: Invalidate token to end session
Authenticate user with username and password.
Request:
curl -k -X POST https://localhost:8085/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{
"username": "admin",
"password": "admin"
}'Response (200 OK):
{
"token": "a6a5fdca19fb3b4f0f24316bb57ccd7d5736503bcec68413c8fc0b90d31f9831",
"expires_at": "2025-06-17T15:29:06+01:00",
"user_id": "72ec2b0b1cc4f8cffb7ac33e521ad819",
"user": {
"id": "72ec2b0b1cc4f8cffb7ac33e521ad819",
"username": "admin",
"email": "admin@entitydb.local",
"roles": ["admin", "user"]
}
}Error Responses:
400 Bad Request: Invalid request body or missing credentials401 Unauthorized: Invalid username or password500 Internal Server Error: Failed to create session
Invalidate current session token.
Request:
curl -k -X POST https://localhost:8085/api/v1/auth/logout \
-H "Authorization: Bearer $TOKEN"Response (200 OK):
{
"message": "Logged out successfully"
}Error Responses:
401 Unauthorized: No token provided or invalid token format500 Internal Server Error: Failed to invalidate session
Refresh session token to extend expiration.
Request:
curl -k -X POST https://localhost:8085/api/v1/auth/refresh \
-H "Authorization: Bearer $TOKEN"Response (200 OK):
{
"token": "new_session_67890xyz...",
"expires_at": "2025-06-17T16:29:06+01:00",
"user_id": "72ec2b0b1cc4f8cffb7ac33e521ad819",
"user": {
"id": "72ec2b0b1cc4f8cffb7ac33e521ad819",
"username": "admin",
"email": "admin@entitydb.local",
"roles": ["admin", "user"]
}
}Get information about currently authenticated user.
Request:
curl -k -X GET https://localhost:8085/api/v1/auth/whoami \
-H "Authorization: Bearer $TOKEN"Response (200 OK):
{
"id": "72ec2b0b1cc4f8cffb7ac33e521ad819",
"username": "admin",
"email": "admin@entitydb.local",
"roles": ["admin", "user"]
}All authenticated API requests must include the Authorization header:
Authorization: Bearer <session-token>
Example:
curl -k -X GET https://localhost:8085/api/v1/entities/list \
-H "Authorization: Bearer session_12345abcdef..."EntityDB automatically creates a default admin user on first startup:
- Username:
admin - Password:
admin - Roles:
admin,user
⚠️ Security Warning: Change the default admin password immediately in production environments.
Users are assigned roles through RBAC tags:
rbac:role:admin- Full administrative accessrbac:role:user- Standard user access
Permissions are checked via tag-based RBAC:
rbac:perm:entity:create- Create entitiesrbac:perm:entity:view- View entitiesrbac:perm:entity:update- Update entitiesrbac:perm:system:admin- System administration
- Passwords hashed using bcrypt with cost 10
- Salt stored with hash in user entity content field
- No plaintext password storage
- Session tokens generated using crypto/rand
- Configurable session TTL (default: 1 hour)
- Automatic session cleanup for expired tokens
- IP address and user agent tracking
- Failed login attempts are logged
- Session activity monitoring
- Authentication metrics available via
/api/v1/rbac/metrics
All authentication endpoints return structured error responses:
{
"error": "Detailed error message"
}Common error scenarios:
- Invalid credentials: Username/password mismatch
- Missing token: Authorization header not provided
- Expired token: Session has exceeded TTL
- Invalid token format: Malformed Authorization header
# Login and extract token
TOKEN=$(curl -s -k -X POST https://localhost:8085/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"admin"}' | jq -r '.token')
# Use token for authenticated requests
curl -k -X GET https://localhost:8085/api/v1/entities/list \
-H "Authorization: Bearer $TOKEN"# Check current user
curl -k -X GET https://localhost:8085/api/v1/auth/whoami \
-H "Authorization: Bearer $TOKEN"
# Refresh token
curl -k -X POST https://localhost:8085/api/v1/auth/refresh \
-H "Authorization: Bearer $TOKEN"
# Logout
curl -k -X POST https://localhost:8085/api/v1/auth/logout \
-H "Authorization: Bearer $TOKEN"- v2.32.0: Current authentication system with embedded credentials and production battle-testing
- v2.29.0: Major authentication architecture change - embedded credentials introduced
- v2.28.0: Session-based authentication with JWT tokens