@vymalo/medusa-keycloak
v1.0.10
Published
π Seamless Keycloak Identity and Access Management for MedusaJS
Maintainers
Readme
MedusaJS Keycloak Authentication
π Seamless Keycloak Identity and Access Management for MedusaJS
π Features
- Native Keycloak authentication integration
- Multi-provider authentication support
- Secure OAuth 2.0 / OpenID Connect implementation
- Flexible configuration options
- Role-based access control
- Single Sign-On (SSO) capabilities
ποΈ Authentication Architecture
graph TD
A[User] -->|Login Request| B[MedusaJS]
B -->|Redirect| C[Keycloak]
C -->|Authentication| D[Identity Verification]
D -->|Token| B
B -->|Access Granted| Aπ¦ Installation
Install the package using npm:
npm install @vymalo/medusa-keycloakOr using yarn:
yarn add @vymalo/medusa-keycloakπ Configuration Example
modules: [
{
resolve: '@medusajs/medusa/auth',
options: {
providers: [
// Keycloak Authentication Provider
{
resolve: `@vymalo/medusa-keycloak`,
id: 'vymalo-keycloak',
options: {
// Keycloak Server Configuration
url: process.env.KEYCLOAK_URL,
realm: process.env.KEYCLOAK_REALM,
clientId: process.env.KEYCLOAK_CLIENT_ID,
clientSecret: process.env.KEYCLOAK_CLIENT_SECRET,
// Optional Advanced Configuration
scope: 'openid profile email', // default
default_redirect_uri: process.env.KEYCLOAK_CALLBACK_URL,
}
},
...,
],
},
}
]π§ Environment Variables
Required Configuration:
KEYCLOAK_URL: Keycloak server base URLKEYCLOAK_REALM: Keycloak realm nameKEYCLOAK_CLIENT_ID: Application client IDKEYCLOAK_CLIENT_SECRET: Client secret
Optional Configuration:
KEYCLOAK_SCOPE: Authentication scopesKEYCLOAK_CALLBACK_URL: Custom callback URL
π‘οΈ Security Considerations
- Use environment variables for sensitive credentials
- Implement proper scope restrictions
- Rotate client secrets periodically
- Configure appropriate token lifetimes
π Advanced Integration Options
Authentication Flow Customization
- Support multiple authentication providers
- Fallback mechanisms
- Role-based access control
- Custom claim mapping
Token Management
- Access token validation
- Refresh token handling
- Session management
- Single sign-on (SSO) support
π Supported Authentication Flows
- Authorization Code Flow
- Implicit Flow
- Hybrid Flow
- Client Credentials Flow
- Direct Access Grants
π€ Contributing
Contributions are welcome!
- Improve authentication logic
- Add new Keycloak configuration options
- Enhance security features
- Provide more robust error handling
π Troubleshooting
- Verify Keycloak server connectivity
- Check client configuration
- Validate environment variables
- Review network and CORS settings
