Certainly! Below is a detailed expert recommendation on designing a modern microservices authentication and authorization system with RBAC for your myHospitalnow ecosystem, addressing your multi-tenant login challenge and overall architecture.
Expert Software Design & Architecture Recommendation for myHospitalnow Authentication & Authorization (RBAC)
1. High-Level Architecture Overview
+---------------------------------------------------------------+
| API Gateway |
| - Routes requests to appropriate microservices |
| - Performs JWT/OAuth2 token validation |
| - Propagates user claims (roles, permissions) |
| - Enforces rate limiting, throttling, logging |
+--------------------+-------------------+----------------------+
| |
| |
+------------+---+ +-----+-------------+
| Authentication | | Authorization |
| Service | | Service (RBAC) |
| (JWT/OAuth2) | | Validates roles & |
| Handles login,| | permissions on |
| token issue, | | each request |
| refresh | +-------------------+
+-------+-------+
|
| (gRPC/REST)
|
+--------+---------+
| User Management |
| Service |
| (Registration, |
| Profile, Roles, |
| Password Reset) |
+--------+---------+
|
| (SQL/Directory)
|
+--------+---------+
| Central Identity |
| Store (MySQL) |
| Users, Roles, |
| Permissions |
+------------------+
+---------------------------------------------------------------+
| Resource Microservices (Patients, Doctors, Hospitals, Nurses) |
| - Delegate auth to API Gateway & Auth Services |
| - Enforce RBAC via Authorization Service |
+---------------------------------------------------------------+
+---------------------------------------------------------------+
| External Identity Providers (Google, Azure AD, LDAP) |
| - Integrated via Authentication Service for SSO/Federation |
+---------------------------------------------------------------+
2. Key Components & Responsibilities
| Component | Responsibilities |
|------------------------|----------------------------------------------------------------------------------------------------|
| API Gateway | - Central entry point for all traffic- Validates JWT tokens- Routes requests- Propagates user claims- Enforces security policies (rate limiting, IP whitelisting) |
| Authentication Service | - Handles login, logout, token issuance (JWT/OAuth2)- Supports token refresh flows- Integrates with external IdPs for SSO- Stateless, scalable |
| Authorization Service | - Enforces RBAC policies- Validates user roles and permissions for each request- Provides APIs for permission checks- Supports dynamic policy updates |
| User Management Service| - Manages user registration, profile updates- Manages role assignments- Handles password resets and account recovery- Syncs user-role data with central store |
| Central Identity Store | - Stores users, roles, permissions- SQL-based for relational integrity- Supports audit logging and history tracking |
| Resource Microservices | - Business domain logic for Patients, Doctors, Hospitals, Nurses- Delegates auth decisions to API Gateway and Authorization Service- Enforces least privilege access |
| External Identity Providers | - Enable SSO/federated login- OAuth2/OpenID Connect integration- Managed by Authentication Service |
3. RBAC Decision Flow
sequenceDiagram
participant User
participant API_Gateway
participant Auth_Service
participant Authz_Service
participant Resource_Service
User->>API_Gateway: Sends request with JWT token
API_Gateway->>Auth_Service: Validate token & extract claims
Auth_Service-->>API_Gateway: Valid token + user claims
API_Gateway->>Authz_Service: Check user roles & permissions for resource/action
Authz_Service-->>API_Gateway: Authorization decision (Allow/Deny)
API_Gateway->>Resource_Service: Forward request with user claims
Resource_Service-->>API_Gateway: Response
API_Gateway->>User: Response
4. Addressing Your Multi-Tenant Login Problem
You have 3 user types (Patients, Doctors, Hospitals) with separate microservices and login portals, but users cannot login across portals simultaneously due to session/token conflicts.
Recommended Solution: Centralized Authentication Domain with Multi-Tenant Support
Use a dedicated auth domain: auth.myhospitalnow.com
(Option 2)
Single Sign-On (SSO) across portals and apps:
All login/register flows redirect to auth.myhospitalnow.com
for authentication.
On successful login, a JWT token (with user role and tenant info) is issued.
Token is valid across subdomains via proper cookie/domain settings or bearer tokens in headers.
Each portal (www.myhospitalnow.com
, doctors.myhospitalnow.com
, hospitals.myhospitalnow.com
) validates token via API Gateway.
Role-based routing and UI:
After login, users are redirected to their respective portals based on role.
The token contains role claims (patient
, doctor
, hospital
, nurse
).
Resource microservices enforce RBAC to restrict access accordingly.
Benefits:
No login conflicts — one token per user session valid across all portals/apps.
Simplified user experience with SSO.
Centralized user management and auditing.
Easier to add new user types (e.g., nurses) without login conflicts.
5. Cross-Domain Authentication Considerations
- Use OAuth2 Authorization Code Flow with PKCE for web and mobile apps.
- Use JWT tokens with short expiration and refresh tokens securely stored.
- For web apps, use HTTP-only, Secure cookies scoped to
.myhospitalnow.com
domain for token storage.
- For mobile apps, store tokens securely (e.g., Android Keystore, iOS Keychain).
- API Gateway validates tokens on every request.
- Use CORS policies to allow cross-subdomain requests.
6. Technology & Integration Suggestions
| Aspect | Recommendation |
|----------------------------|-------------------------------------------------------------------------------------------------------|
| Authentication Protocol| OAuth2 / OpenID Connect for standard compliance and extensibility |
| Token Format | JWT with embedded claims (roles, tenant info, permissions) |
| Inter-service Communication| gRPC for internal microservice calls (fast, efficient), REST for external APIs |
| API Gateway | Use mature API Gateway like Kong, Ambassador, or AWS API Gateway with JWT validation plugin |
| Directory/Identity Store| MySQL for user/role/permission data; consider LDAP or Azure AD integration for external IdPs |
| Audit Logging | Centralized logging (ELK stack, Splunk) for auth events, login attempts, role changes |
| Security Best Practices| Zero Trust model: verify every request, least privilege principle, rotate keys, secure secrets management |
| Session Management | Stateless tokens, no server-side sessions to scale easily |
| Password Security | Hash passwords with bcrypt/argon2, enforce strong policies |
7. Proposed Domain & Login Flow Diagram
User visits: www.myhospitalnow.com (Patient Portal)
|
v
Redirect to auth.myhospitalnow.com/login
|
User logs in (Patient credentials)
|
Auth Service issues JWT token with role=patient
|
Redirect back to www.myhospitalnow.com with token
|
API Gateway validates token, routes to Patient Resource Service
|
Patient accesses features (bookings, find doctors, etc.)
Similarly for doctors.myhospitalnow.com and hospitals.myhospitalnow.com,
users authenticate at auth.myhospitalnow.com and get tokens scoped by role.
8. Summary: Why Option 2 (Central Auth Domain) is Best
| Criteria | Option 1 (Separate Domains) | Option 2 (Central Auth Domain) |
|-------------------------------|-------------------------------------|-----------------------------------------------|
| User Experience | Multiple logins, confusing | Single login, seamless SSO |
| Token Sharing Across Services | Difficult (cross-domain cookies) | Easy (single domain for auth) |
| Scalability | Harder to maintain multiple auths | Easier to maintain & extend |
| Security | Fragmented policies | Centralized security policies |
| Future Extensibility | Complex to add new user types | Simple to add new roles & tenants |
Final Recommendations
- Implement Option 2 with
auth.myhospitalnow.com
as the central auth domain.
- Build a dedicated Authentication Service supporting OAuth2/JWT and external IdP integration.
- Use an API Gateway to validate tokens and route requests.
- Implement a central Authorization Service enforcing RBAC policies.
- Design User Management Service to handle user lifecycle and role assignments.
- Ensure secure token storage and transmission across all portals and mobile apps.
- Adopt Zero Trust and least privilege principles.
- Enable audit logging for all auth and authorization events.
If you want, I can also provide a detailed sequence diagram, example JWT payload structure, or sample API specs for each service. Just let me know!