UserManagement class provides comprehensive methods for user authentication, user lifecycle management, session handling, and organization membership management.
User Methods
getUser
Retrieves a user by their ID.The unique identifier of the user
Unique identifier for the user
User’s email address
Whether the user’s email has been verified
User’s first name
User’s last name
URL to user’s profile picture
ISO 8601 timestamp of user creation
ISO 8601 timestamp of last update
External identifier from your system
Custom metadata associated with the user
getUserByExternalId
Retrieves a user by their external ID.The external identifier of the user
Returns the same User object as
getUserlistUsers
Retrieves a paginated list of users.Filter by email address
Filter by organization ID
Number of results to return (default: 10)
Cursor for pagination (previous page)
Cursor for pagination (next page)
Paginated list of users
createUser
Creates a new user.User’s email address
User’s password (plain text, will be hashed)
Pre-hashed password
Type of password hash (e.g., ‘bcrypt’, ‘firebase-scrypt’)
User’s first name
User’s last name
Whether the email is already verified
External identifier from your system
Custom metadata to associate with the user
The created user object
updateUser
Updates an existing user.The ID of the user to update
Updated first name
Updated last name
Updated email verification status
Updated metadata
The updated user object
deleteUser
Deletes a user.The ID of the user to delete
Authentication Methods
authenticateWithPassword
Authenticates a user with email and password.User’s email address
User’s password
OAuth client ID (optional if configured globally)
Session options for sealing the session
The authenticated user
JWT access token
Refresh token for obtaining new access tokens
ID of the user’s organization
Method used for authentication (e.g., ‘Password’)
Encrypted session data (if sealSession option was enabled)
authenticateWithCode
Exchanges an authorization code for tokens. Auto-detects public vs confidential client mode based on whether a code verifier or API key is provided.Authorization code from OAuth callback
OAuth client ID (optional if configured globally)
PKCE code verifier (for public clients)
Session options for sealing the session
Authentication response with user and tokens
authenticateWithRefreshToken
Refreshes an access token using a refresh token.The refresh token
OAuth client ID (optional if configured globally)
Session options for sealing the session
New authentication response with refreshed tokens
authenticateWithMagicAuth
Authenticates a user with a magic auth code.Magic auth code from email
User’s email address
OAuth client ID (optional if configured globally)
Session options for sealing the session
Authentication response with user and tokens
authenticateWithTotp
Authenticates a user with a TOTP code.TOTP code from authenticator app
ID of the authentication challenge
Token from the initial authentication attempt
OAuth client ID (optional if configured globally)
Session options for sealing the session
Authentication response with user and tokens
getAuthorizationUrl
Generates an OAuth 2.0 authorization URL.OAuth provider (e.g., ‘authkit’, ‘GoogleOAuth’)
SSO connection ID
Organization ID
URL to redirect after authorization
State parameter for CSRF protection
PKCE code challenge
PKCE code challenge method (e.g., ‘S256’)
Screen hint for AuthKit (e.g., ‘sign-up’, ‘sign-in’)
The authorization URL
getAuthorizationUrlWithPKCE
Generates an OAuth 2.0 authorization URL with automatic PKCE generation.OAuth provider (e.g., ‘authkit’)
SSO connection ID
Organization ID
URL to redirect after authorization
Screen hint for AuthKit
Session Methods
loadSealedSession
Loads a sealed session for session management.Encrypted session data from cookie
Password used to encrypt the session
Session object for managing the session
authenticateWithSessionCookie
Authenticates and validates a session cookie.Encrypted session data from cookie
Password used to encrypt the session (defaults to WORKOS_COOKIE_PASSWORD env var)
listSessions
Lists all sessions for a user.The user ID
Number of results to return
Cursor for pagination
Cursor for pagination
Paginated list of sessions
revokeSession
Revokes a user session.The session ID to revoke
getLogoutUrl
Generates a logout URL.The session ID to log out
URL to redirect after logout
The logout URL
Organization Membership Methods
getOrganizationMembership
Retrieves an organization membership by ID.The organization membership ID
Membership ID
User ID
Organization ID
Organization name
Membership status
User’s role in the organization
ISO 8601 timestamp
ISO 8601 timestamp
listOrganizationMemberships
Lists organization memberships with filtering.Filter by user ID
Filter by organization ID
Filter by membership status
Number of results to return
Paginated list of memberships
createOrganizationMembership
Creates a new organization membership.The user ID
The organization ID
Role slug to assign
The created membership
updateOrganizationMembership
Updates an organization membership.The membership ID to update
New role slug
The updated membership
deleteOrganizationMembership
Deletes an organization membership.The membership ID to delete
deactivateOrganizationMembership
Deactivates an organization membership.The membership ID to deactivate
The deactivated membership
reactivateOrganizationMembership
Reactivates an organization membership.The membership ID to reactivate
The reactivated membership
Email Verification Methods
sendVerificationEmail
Sends a verification email to a user.The user ID
Object containing the user
verifyEmail
Verifies a user’s email with a code.The user ID
Verification code from email
Object containing the verified user
getEmailVerification
Retrieves email verification details.The email verification ID
Email verification object
Password Reset Methods
createPasswordReset
Creates a password reset request.User’s email address
Password reset object
resetPassword
Resets a user’s password.Password reset token
New password
Object containing the user with reset password
getPasswordReset
Retrieves password reset details.The password reset ID
Password reset object
Magic Auth Methods
createMagicAuth
Creates a magic authentication link.User’s email address
Magic auth object with authentication link
getMagicAuth
Retrieves magic auth details.The magic auth ID
Magic auth object
Auth Factor Methods
enrollAuthFactor
Enrolls a new authentication factor (MFA).The user ID
Type of authentication factor
Phone number (required for SMS type)
TOTP issuer (required for TOTP type)
TOTP user (required for TOTP type)
listAuthFactors
Lists authentication factors for a user.The user ID
Number of results to return
Paginated list of authentication factors
Invitation Methods
sendInvitation
Sends an organization invitation.Email address to invite
Organization ID
The created invitation
listInvitations
Lists invitations.Filter by organization ID
Filter by email
Number of results to return
Paginated list of invitations
getInvitation
Retrieves an invitation by ID.The invitation ID
The invitation object
revokeInvitation
Revokes an invitation.The invitation ID to revoke
The revoked invitation
resendInvitation
Resends an invitation.The invitation ID to resend
The resent invitation
Utility Methods
getJwksUrl
Returns the JWKS URL for token verification.The client ID
The JWKS URL