Plugins
Admin Plugin
Administrative operations for managing users, accounts, sessions, and user impersonation
Overview
The Admin plugin provides administrative operations for managing users, accounts, sessions, and user impersonation. It enables system administrators to perform CRUD operations on users and accounts, manage user and session states (banning, revoking sessions), control impersonation activities, and maintain comprehensive audit trails.
Features
- User Management — Create, read, update, and delete users with full lifecycle support
- Account Management — Manage linked provider accounts for users
- User State Management — Ban and unban users with optional expiration and reason tracking
- Session State Management — Revoke sessions with audit trail and reason tracking
- User Impersonation — Admin impersonation of users with time-limited sessions and audit logging
- Audit Trail — Comprehensive tracking of all administrative actions
Configuration
Standalone Mode
[plugins.admin]
enabled = true
impersonation_max_expires_in = "15m"Library Mode
import (
adminplugin "github.com/Authula/authula/plugins/admin"
adminplugintypes "github.com/Authula/authula/plugins/admin/types"
)
adminplugin.New(adminplugintypes.AdminPluginConfig{
Enabled: true,
ImpersonationMaxExpiresIn: 15 * time.Minute,
}),API Reference
Each endpoint in this plugin requires the caller to have a specific hardcoded permission assigned to their role(s).
User Management
| Method | Endpoint | Description | Required Permission |
|---|---|---|---|
POST | /admin/users | Create a new user | admin:users:create |
GET | /admin/users | List all users with cursor-based pagination | admin:users:list |
GET | /admin/users/{user_id} | Get a specific user by ID | admin:users:read |
PATCH | /admin/users/{user_id} | Update user details | admin:users:update |
DELETE | /admin/users/{user_id} | Delete a user | admin:users:delete |
Account Management
| Method | Endpoint | Description | Required Permission |
|---|---|---|---|
POST | /admin/users/{user_id}/accounts | Create a linked provider account for a user | admin:accounts:create |
GET | /admin/users/{user_id}/accounts | List all accounts associated with a user | admin:accounts:list |
GET | /admin/accounts/{id} | Get a specific account by ID | admin:accounts:read |
PATCH | /admin/accounts/{id} | Update account details | admin:accounts:update |
DELETE | /admin/accounts/{id} | Delete a user account and remove provider linkage | admin:accounts:delete |
User State Management
| Method | Endpoint | Description | Required Permission |
|---|---|---|---|
GET | /admin/users/{user_id}/state | Get user state including banned status and ban details | admin:user-state:read |
POST | /admin/users/{user_id}/state | Create user state record | admin:user-state:create |
PATCH | /admin/users/{user_id}/state | Update user state | admin:user-state:update |
DELETE | /admin/users/{user_id}/state | Delete user state record | admin:user-state:delete |
GET | /admin/users/states/banned | List all banned users | admin:user-state:list-banned |
POST | /admin/users/{user_id}/ban | Ban a user with optional expiration and reason | admin:user-state:ban |
POST | /admin/users/{user_id}/unban | Remove ban from a user | admin:user-state:unban |
Session State Management
| Method | Endpoint | Description | Required Permission |
|---|---|---|---|
GET | /admin/sessions/{session_id}/state | Get session state including revocation status | admin:session-state:read |
POST | /admin/sessions/{session_id}/state | Create session state record | admin:session-state:create |
PATCH | /admin/sessions/{session_id}/state | Update session state | admin:session-state:update |
DELETE | /admin/sessions/{session_id}/state | Delete session state record | admin:session-state:delete |
POST | /admin/sessions/{session_id}/revoke | Revoke a session with optional reason | admin:session-state:revoke |
GET | /admin/sessions/states/revoked | List all revoked sessions with session state | admin:session-state:list-revoked |
GET | /admin/users/{user_id}/sessions | List all sessions with session state for a user | admin:user-state:list-sessions |
Impersonation Management
| Method | Endpoint | Description | Required Permission |
|---|---|---|---|
GET | /admin/impersonations | List all active impersonations | admin:impersonations:list |
GET | /admin/impersonations/{impersonation_id} | Get a specific impersonation by ID | admin:impersonations:read |
POST | /admin/impersonations | Start impersonating a user with audit trail | admin:impersonations:start |
POST | /admin/impersonations/{impersonation_id}/stop | End impersonation and restore original admin session | admin:impersonations:stop |
Database Schema
Table: admin_impersonations
| Field | Type | Key | Description |
|---|---|---|---|
id | string | PK | Unique identifier for the impersonation record |
actor_user_id | string | FK | Reference to the admin user initiating impersonation |
target_user_id | string | FK | Reference to the user being impersonated |
actor_session_id | string? | FK | Reference to the admin's original session |
impersonation_session_id | string? | FK | Reference to the impersonation session |
reason | string | - | Reason for impersonation |
started_at | timestamp | - | When impersonation began |
expires_at | timestamp | - | When impersonation expires |
ended_at | timestamp? | - | When impersonation ended |
ended_by_user_id | string? | FK | Reference to the user who ended impersonation |
created_at | timestamp | - | Record creation time |
updated_at | timestamp | - | Record last update time |
Table: admin_user_states
| Field | Type | Key | Description |
|---|---|---|---|
user_id | string | PK | Reference to the user |
banned | boolean | - | Whether the user is currently banned |
banned_at | timestamp? | - | When the ban was issued |
banned_until | timestamp? | - | When the ban expires (if temporary) |
banned_reason | string? | - | Reason for the ban |
banned_by_user_id | string? | FK | Reference to the admin who issued the ban |
created_at | timestamp | - | Record creation time |
updated_at | timestamp | - | Record last update time |
Table: admin_session_states
| Field | Type | Key | Description |
|---|---|---|---|
session_id | string | PK | Reference to the session |
revoked_at | timestamp? | - | When the session was revoked |
revoked_reason | string? | - | Reason for revocation |
revoked_by_user_id | string? | FK | Reference to the admin who revoked the session |
impersonator_user_id | string? | FK | Reference to the impersonating admin (if applicable) |
impersonation_reason | string? | - | Reason for impersonation (if applicable) |
impersonation_expires_at | timestamp? | - | When impersonation expires (if applicable) |
created_at | timestamp | - | Record creation time |
updated_at | timestamp | - | Record last update time |
Migrations are automatically handled when the plugin is initialized.
Plugin Capabilities
The Admin plugin provides the following capabilities:
- User CRUD Operations — Full lifecycle management for user accounts
- Account Linking — Manage external provider account associations
- User Banning — Temporary or permanent user suspension with reason tracking
- Session Revocation — Invalidate sessions with audit trail
- User Impersonation — Admin impersonation with time-limited sessions and comprehensive logging
- Audit Logging — All administrative actions are tracked for compliance and debugging
Impersonation Lifecycle
┌─────────────┐ ┌──────────────┐ ┌─────────────┐
│ Start │────▶│ Impersonation│────▶│ Active │
│ Impersonation│ │ Created │ │ Session │
└─────────────┘ └──────────────┘ └──────┬──────┘
│
┌─────────────────────────┼──────────────────────┐
│ │ │
▼ ▼ ▼
┌──────────────┐ ┌─────────────┐ ┌─────────────┐
│ Expiration │ │ Manual │ │ Target │
│ (Timeout) │ │ Stop │ │ Deleted │
└──────┬───────┘ └──────┬──────┘ └──────┬──────┘
│ │ │
▼ ▼ ▼
┌──────────────┐ ┌─────────────┐ ┌─────────────┐
│ Session │ │ Session │ │ Session │
│ Ended │ │ Ended │ │ Ended │
└──────────────┘ └─────────────┘ └─────────────┘Client Plugin
If you're using the Authula SDK, add the plugin to the SDK like so:
import { createClient } from "authula";
import { AdminPlugin } from "authula/plugins";
export const authulaClient = createClient({
url: "http://localhost:8080/auth",
plugins: [
// other plugins...
new AdminPlugin(),
],
});Security Recommendations
- Access Control — All admin endpoints should be protected by appropriate authentication and authorization ideally using the Access Control plugin alongside this plugin to restrict access to authorized administrators only.
- Impersonation Limits — Set reasonable
impersonation_max_expires_invalues to limit exposure window - Audit Review — Regularly review impersonation and ban logs for compliance and security auditing
- Least Privilege — Only grant access to routes for users who absolutely require it
- Reason Tracking — Always document reasons for bans and session revocations for audit purposes
- Session Security — Impersonation sessions should be treated with the same security considerations as regular sessions
