User management for your web or mobile application.
615
User management for your web or mobile application. Supports both int and uuid primary keys. Allows Local environment where everything is handled by this service (registration, login, access token management, ...) or AWS Cognito where everything is handled by AWS.
This project is Open Source and source code is available on GitHub.
List of routes with basic info. For testing purpose check Postman collection.
| Request | Path | Description | Data | Response |
|---|---|---|---|---|
| POST | /user/register | Register new user | | |
| GET | /auth/user/:id | User detail | | |
| DELETE | /auth/user/:id | Delete user | ||
| PUT | /auth/user/:id | Update user | ||
| POST | /user/login | Log in user | | |
| GET | /user/logout | Log out user | | |
| GET | /user/refresh-token | Renew refresh token | | |
| DELETE | /user/refresh-token | Log out user | |
Geolocation is used when user logs in to see loacation from where the request came. This can be then used to inform user about new login event with data about the device.
UNKNOWN always return "unknown" for both city and country and can be used for local development or to disable geolocation:
SERVICES_GEOLOCATION_TYPE=UNKNOWN
IPLOCATION uses IP location service to see geographical location of IP address:
SERVICES_GEOLOCATION_TYPE=IPLOCATION
IPSTACK uses ipstack and requires accessKey:
SERVICES_GEOLOCATION_TYPE=IPSTACK
SERVICES_GEOLOCATION_IPSTACK_ACCESS_KEY
One Time Passwords are used for two factor authentication.
OTPAUTH uses OTPAuth package to generate one time passwords:
SERVICES_ONE_TIME_PASSWORD_TYPE=OTPAUTH
SPEAKEASY uses Speakeasy package to generate one time passwords:
SERVICES_ONE_TIME_PASSWORD_TYPE=SPEAKEASY
Token service is used to create and verify access tokens.
JWT uses JWT:
SERVICES_TOKEN_TYPE=JWT
SERVICES_TOKEN_SECRET=secret
SERVICES_TOKEN_TTL=900
onRegisterWhen new user successfully register (no duplicate email or other error) the service will notify all subscribed services.
Set in the config:
{
callbacks: {
onRegister: [
type: 'HTTP',
url: 'https://',
],
},
}
Data:
{
name: 'user_register',
user: {
id: user.id,
email: user.email,
meta: user.meta,
},
parameters: {
token: token,
},
}
onLoginWhen user successfully logs in the service will notify all subscribed services.
Set in the config:
{
callbacks: {
onLogin: [
type: 'HTTP',
url: 'https://',
],
},
}
Data:
{
name: 'user_login',
user: {
id: user.id,
email: user.email,
meta: user.meta,
},
parameters: {
os: useragent.os,
browser: useragent.browser,
version: useragent.version,
city: geolocation.city,
country: geolocation.country,
ip: ip,
},
}
onLoginFailonDeleteonPasswordResetRequestData:
{
name: 'user_password_reset_request',
user: {
id: user.id,
email: user.email,
},
parameters: {
token: verificationToken.token,
},
}
onPasswordResetData:
{
name: 'user_password_reset',
user: {
id: user.id,
email: user.email,
},
}
Locally in your docker-compose.yml:
services:
mysql_user_service:
container_name: db_user_service
image: mysql
environment:
- MYSQL_DATABASE=user_service
- MYSQL_USER=user_service
- MYSQL_PASSWORD=password
- MYSQL_ROOT_PASSWORD=password
- MYSQL_PORT=3306
ports:
- 3306:3306
volumes:
- 'mysql_user_service_data:/data/db'
user_service:
image: juffalow/user-service:latest
depends_on:
- mysql_user_service
restart: unless-stopped
ports:
- 3010:3010
environment:
- PORT=3010
- DOMAIN=localhost
- ROUTE_PREFIX=/auth
- CORS_ORIGINS=localhost,example.com
- LOGGER_LEVEL=info
- DATABASE_HOST=mysql_user_service
- DATABASE_NAME=user_service
- DATABASE_USER=user_service
- DATABASE_PASSWORD=password
- DATABASE_PORT=3306
- SERVICES_TOKEN_TYPE=JWT
- SERVICES_TOKEN_SECRET=secret
- SERVICES_TOKEN_TTL=900
- SERVICES_GEOLOCATION_TYPE=UNKNOWN
links:
- mysql_user_service
volumes:
mysql_user_service_data:
server {
listen 80;
listen [::]:80;
server_name _;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://localhost:3010;
}
}
Content type
Image
Digest
sha256:b871d5991…
Size
86.8 MB
Last updated
almost 2 years ago
docker pull juffalow/user-service