Overview
jshERP uses a token-based authentication system with Redis-backed session management. After successful login, users receive an access token that must be included in all subsequent API requests.Authentication Flow
Login
Standard Login
Authenticate with username and password: Endpoint:POST /user/login
Request Body:
loginName(string, required) - User’s login namepassword(string, required) - MD5 hashed passwordcode(string, required) - Verification code from captchauuid(string, required) - UUID from captcha request
Passwords should be MD5 hashed on the client side before sending to the API.
WeChat Login
Authenticate using WeChat OAuth: Endpoint:POST /user/weixinLogin
Request Body:
200- Login successful501- WeChat account not bound to any user500- Login failed
Users must first bind their WeChat account to their jshERP account using the
/user/weixinBind endpoint.Captcha Verification
Get Captcha
Before logging in, obtain a captcha image: Endpoint:GET /user/randomImage
Response:
- Request captcha image
- Display image to user
- User enters the code they see
- Submit code and uuid with login request
Using Authentication Token
After successful login, include the token in all API requests:Request Header
Example Authenticated Request
Session Management
Session Storage
Session data is stored in Redis with the following characteristics:- Storage Key: The access token itself
- Storage Type: Redis Hash
- Timeout: 36000 seconds (10 hours)
- Auto-renewal: Each authenticated request extends the session
userId- Current user’s IDclientIp- Client IP address- Additional user context as needed
Get Current User Session
Endpoint:GET /user/getUserSession
Response:
Logout
End the user session and invalidate the token: Endpoint:GET /user/logout
Response:
- Redis session data is deleted (
userIdremoved) - Client IP information is cleared
- Token becomes invalid immediately
Access Control
Public Endpoints (No Authentication Required)
These endpoints can be accessed without authentication:POST /user/login- User loginPOST /user/registerUser- User registrationPOST /user/weixinLogin- WeChat loginPOST /user/weixinBind- Bind WeChat accountGET /user/randomImage- Get captcha imageGET /doc.html- Swagger documentation- Platform and system config endpoints (for initial setup)
Protected Endpoints
All other endpoints require authentication. Requests without a valid token will receive:500
Path Traversal Protection
Attempts to use path traversal will result in:User Registration
New users can register through the API: Endpoint:POST /user/registerUser
Request Body:
New users are automatically assigned to a tenant and given the default role. Tenant limits apply to the number of users that can be created.
Password Management
Update Password (Authenticated User)
Endpoint:PUT /user/updatePwd
Request Body:
1- Password updated successfully2- Original password is incorrect3- Exception occurred during update
Reset Password (Admin)
Endpoint:POST /user/resetPwd
Request Body:
Role-Based Access Control
Get Current User Role Type
Endpoint:GET /user/getRoleTypeByCurrentUser
Response:
Get Current User Button Permissions
Endpoint:GET /user/getUserBtnByCurrentUser
Response:
The admin user automatically has all permissions and doesn’t need button permission checks.
Multi-Tenant Considerations
Tenant Information
Get current user’s tenant details: Endpoint:GET /user/infoWithTenant
Response:
type- Tenant type (0: free, 1: paid)expireTime- Tenant expiration dateuserCurrentNum- Current number of usersuserNumLimit- Maximum allowed userstenantId- Tenant identifier
Security Best Practices
- Always hash passwords using MD5 before sending to the API
- Store tokens securely using secure storage mechanisms
- Implement token refresh logic before session expiration
- Clear tokens on logout from client-side storage
- Handle session expiration gracefully with automatic re-login
- Validate captcha on every login attempt
- Use HTTPS in production environments
- Implement rate limiting on the client side for login attempts
- Monitor failed login attempts for security purposes
- Never log or expose authentication tokens
Error Handling
Common Authentication Errors
Invalid Credentials:BusinessRunTimeException with specific error code.
Tenant Expired:
Session automatically cleared, next request returns loginOut.
Example: Complete Authentication Flow
Next Steps
API Introduction
Learn about API structure and common patterns
User Management
Explore user management endpoints