JWT Authentication
Mercoa uses JSON Web Tokens (JWTs) for frontend authentication. JWTs provide a secure and efficient way to authenticate users and control access to the Mercoa platform.
JWT Creation
JWTs can be created at multiple levels within your organization:
Entity Level
Entity User Level
Entity Group Level
Entity Group User Level
Token Revocation
All JWTs can be revoked at the organization level using the invalidateTokens
endpoint:
Session Management
JWTs can be created with a session ID, which is controlled by the platform. This allows for more granular control over token lifecycle:
Sessions will automatically be invalidated if a new token for that session is not created within 24 hours. This time limit is subject to change.
To revoke tokens for a specific sessions:
Role-Based Access Control
JWTs work in conjunction with Mercoa’s Role-Based Access Control (RBAC) system. The roles and permissions assigned to a user are encoded in the JWT, ensuring that users can only access the resources and perform the actions they are authorized for.
For more information about roles and permissions, see our RBAC documentation.
Best Practices
-
Token Expiration: Set appropriate expiration times for your JWTs based on your security requirements. Shorter expiration times are generally more secure.
-
Session Management: Use session IDs when you need to track and manage user sessions, especially for features like “logout everywhere” or session invalidation.
-
Token Storage: Store JWTs securely in your frontend application or not at all. Consider using secure HTTP-only cookies or secure local storage mechanisms.
-
Token Refresh: Implement a token refresh mechanism for long-lived sessions to maintain security while providing a good user experience.