Magistrala
Dev GuideServices

Users

User management service for Magistrala — handles registration, login, profile management, password reset, email verification and account lifecycle.

The Users service provides an HTTP API for managing user accounts on the Magistrala platform. It handles registration, login, profile updates, password reset, email verification, and account lifecycle (enable/disable/delete). It communicates with the Auth service over gRPC for token issuance and validation.

Configuration

VariableDescriptionDefault
MG_USERS_LOG_LEVELLog level (debug, info, warn, error)info
MG_USERS_ADMIN_EMAILDefault admin account created on startupadmin@example.com
MG_USERS_ADMIN_PASSWORDDefault admin password12345678
MG_USERS_PASS_REGEXPassword validation regex^.{8,}$
MG_USERS_HTTP_HOSTHTTP hostlocalhost
MG_USERS_HTTP_PORTHTTP port9002
MG_USERS_DB_HOSTDatabase hostlocalhost
MG_USERS_DB_PORTDatabase port5432
MG_USERS_DB_USERDatabase usermagistrala
MG_USERS_DB_PASSDatabase passwordmagistrala
MG_USERS_DB_NAMEDatabase nameusers
MG_USERS_DB_SSL_MODESSL mode (disable, require, verify-ca, verify-full)disable
MG_AUTH_GRPC_URLAuth service gRPC URLlocalhost:8181
MG_AUTH_GRPC_TIMEOUTAuth service gRPC timeout1s
MG_EMAIL_HOSTSMTP server hostlocalhost
MG_EMAIL_PORTSMTP server port25
MG_EMAIL_USERNAMESMTP username""
MG_EMAIL_PASSWORDSMTP password""
MG_EMAIL_FROM_ADDRESSSender email address""
MG_EMAIL_FROM_NAMESender display name""
MG_PASSWORD_RESET_URL_PREFIXURL prefix for password reset linkshttp://localhost/password/reset
MG_VERIFICATION_URL_PREFIXURL prefix for email verification linkshttp://localhost/verify-email
MG_USERS_ES_URLEvent store URLnats://localhost:4222
MG_USERS_DELETE_INTERVALInterval for running the account deletion sweep24h
MG_USERS_DELETE_AFTERGrace period before a disabled account is permanently deleted720h
MG_JAEGER_URLJaeger tracing endpointhttp://localhost:4318/v1/traces
MG_SEND_TELEMETRYSend telemetry to Magistrala call-home servertrue

Deployment

git clone https://github.com/absmach/magistrala
cd magistrala

make users
make install

MG_USERS_LOG_LEVEL=info \
MG_USERS_ADMIN_EMAIL=admin@example.com \
MG_USERS_ADMIN_PASSWORD=12345678 \
MG_USERS_HTTP_HOST=localhost \
MG_USERS_HTTP_PORT=9002 \
MG_USERS_DB_HOST=localhost \
MG_USERS_DB_PORT=5432 \
MG_USERS_DB_USER=magistrala \
MG_USERS_DB_PASS=magistrala \
MG_USERS_DB_NAME=users \
MG_AUTH_GRPC_URL=localhost:8181 \
MG_EMAIL_HOST=smtp.example.com \
MG_EMAIL_PORT=587 \
MG_EMAIL_FROM_ADDRESS=noreply@example.com \
$GOBIN/magistrala-users

Set MG_USERS_HTTP_SERVER_CERT and MG_USERS_HTTP_SERVER_KEY to enable TLS. If MG_EMAIL_HOST is not reachable, the service still starts but password reset emails will not be sent.

HTTP API

Base URL defaults to http://localhost:9002.

OperationDescription
RegisterCreate a user account
Issue tokenExchange credentials for access/refresh tokens (login)
Refresh tokenObtain a new access token using a refresh token
ProfileFetch the authenticated user's own profile
View userRetrieve a user by ID
List usersPage and filter users
Update userPatch name, metadata, tags, profile picture
Change identityUpdate email or username
Change secretUpdate password
Enable/DisableActivate or deactivate an account
DeletePermanently remove an account
Verify emailConfirm email address via link
Password resetRequest and apply a password reset

Register a user

curl -X POST http://localhost:9002/users \
  -H "Content-Type: application/json" \
  -d '{
    "first_name": "Ada",
    "last_name": "Lovelace",
    "credentials": { "username": "ada", "secret": "changeMe123" },
    "email": "ada@example.com"
  }'

Login

curl -X POST http://localhost:9002/users/tokens/issue \
  -H "Content-Type: application/json" \
  -d '{ "identity": "ada@example.com", "secret": "changeMe123" }'

View own profile

curl http://localhost:9002/users/profile \
  -H "Authorization: Bearer $ACCESS_TOKEN"

List users

curl "http://localhost:9002/users?limit=10&status=enabled" \
  -H "Authorization: Bearer $ACCESS_TOKEN"

Request password reset

curl -X POST http://localhost:9002/password/reset-request \
  -H "Content-Type: application/json" \
  -d '{ "email": "ada@example.com" }'

Health check

curl http://localhost:9002/health

Best Practices

  • Disable self-registration in production and onboard users via admin tokens.
  • Require email verification before granting domain roles (MG_ALLOW_UNVERIFIED_USER=false).
  • Harden passwords with MG_USERS_PASS_REGEX and enforce rotation.
  • Use MG_USERS_DELETE_AFTER to automatically purge stale disabled accounts.
  • Store SMTP credentials in a secrets manager, not in image environment.

For the full API reference, see the API documentation.

On this page