Auth Providers
Auth providers handle user authentication and identity management. They support various authentication methods including email/password, OAuth providers (Google, GitHub), and custom authentication flows.Available Auth Providers
Medusa includes three authentication providers:Email/Password Provider
@medusajs/medusa/auth-emailpass - Traditional email and password authentication.
Features:
- User registration with email and password
- Secure password hashing using Scrypt
- Password updates
- Email-based authentication
Google OAuth Provider
@medusajs/medusa/auth-google - Google OAuth 2.0 authentication.
Features:
- Google Sign-In integration
- OAuth 2.0 flow
- Email verification enforcement
- User profile metadata (name, picture, etc.)
GitHub OAuth Provider
@medusajs/medusa/auth-github - GitHub OAuth authentication.
Features:
- GitHub Sign-In integration
- OAuth flow
- User profile metadata
Installation
All auth providers are included in the core Medusa package:Configuration
- Email/Password
- Google OAuth
- GitHub OAuth
- Multiple Providers
Configure email/password authentication:
medusa-config.ts
Higher
logN values increase security but slow down hashing. The default (15)
provides a good balance for most applications.Auth Provider Interface
All auth providers extendAbstractAuthModuleProvider and implement the following methods:
authenticate(input: AuthenticationInput, authIdentityService: AuthIdentityProviderService): Promise<AuthenticationResponse>
Authenticates a user.
Email/Password Example:
register(input: AuthenticationInput, authIdentityService: AuthIdentityProviderService): Promise<AuthenticationResponse>
Registers a new user (email/password only).
validateCallback(input: AuthenticationInput, authIdentityService: AuthIdentityProviderService): Promise<AuthenticationResponse>
Validates OAuth callback (OAuth providers only).
update(data: any, authIdentityService: AuthIdentityProviderService): Promise<AuthenticationResponse>
Updates auth identity (email/password only).
Using the Auth Module
Access auth providers through the Auth Module:Authentication Flows
Email/Password Flow
-
Registration:
-
Login:
-
Password Update:
OAuth Flow (Google/GitHub)
-
Initiate OAuth:
-
Handle Callback:
-
Access User Data:
Creating Custom Auth Providers
Create a custom auth provider by extendingAbstractAuthModuleProvider:
packages/modules/providers/auth-custom/src/services/custom-auth.ts
packages/modules/providers/auth-custom/src/index.ts
Reference
- Email/Password:
packages/modules/providers/auth-emailpass/src/services/emailpass.ts - Google OAuth:
packages/modules/providers/auth-google/src/services/google.ts - GitHub OAuth:
packages/modules/providers/auth-github/src/services/github.ts - Base class:
packages/core/utils/src/auth/abstract-auth-module-provider.ts - Types:
packages/core/types/src/auth/provider.ts
Next Steps
Providers Overview
Explore other provider types
Notification Providers
Send welcome emails to new users