kwai.modules.identity
¶
The identity module is responsible for user management.
kwai.modules.identity.authenticate_user
¶
Module that implements the use case: authenticate user.
AuthenticateUser
¶
Use case to authenticate a user.
Attributes:
Name | Type | Description |
---|---|---|
_user_account_repo |
UserAccountRepository
|
The repository for getting the user account. |
_access_token_repo |
UserAccountRepository
|
The repository for creating the access token. |
_refresh_token_repo |
UserAccountRepository
|
The repository for creating the refresh token. |
execute(command)
async
¶
Execute the use case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command |
AuthenticateUserCommand
|
The input for this use case. |
required |
Returns:
Name | Type | Description |
---|---|---|
RefreshTokenEntity |
RefreshTokenEntity
|
On success, a refresh token entity will be returned. |
Raises:
Type | Description |
---|---|
InvalidEmailException
|
Raised when the username contains an invalid email address. |
UserAccountNotFoundException
|
Raised when the user with the given email address doesn't exist. |
AuthenticateUserCommand
dataclass
¶
Input for the (AuthenticateUser) use case.
Attributes:
Name | Type | Description |
---|---|---|
username |
str
|
The email address of the user. |
password |
str
|
The password of the user. |
access_token_expiry_minutes |
int
|
Minutes before expiring the access token. Default is 2 hours. |
refresh_token_expiry_minutes |
int
|
Minutes before expiring the refresh token. Default is 2 months. |
kwai.modules.identity.create_user
¶
Use case: create a user.
CreateUser
¶
Use case for creating a new user.
__init__(user_account_repo)
¶
Create the use case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_account_repo |
UserAccountRepository
|
Repository that creates a new user account. |
required |
execute(command)
async
¶
Execute the use case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command |
CreateUserCommand
|
The input for this use case. |
required |
Returns:
Type | Description |
---|---|
UserAccountEntity
|
An entity for a user account. |
Raises:
Type | Description |
---|---|
UnprocessableException
|
when the email address is already used by another user. |
CreateUserCommand
dataclass
¶
Input for the CreateUser use case.
See: CreateUser
Attributes:
Name | Type | Description |
---|---|---|
email |
str
|
The email address for the new user. |
first_name |
str
|
The first name of the new user. |
last_name |
str
|
The last name of the new user. |
password |
str
|
The password for the new user. |
remark |
str
|
A remark about the new user. |
kwai.modules.identity.delete_user_invitation
¶
Implement the use case: delete a user invitation.
DeleteUserInvitation
¶
Implements the use case 'delete a user invitation'.
__init__(user_invitation_repo)
¶
Initialize the use case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_invitation_repo |
UserInvitationRepository
|
A repository for deleting the user invitation. |
required |
execute(command)
async
¶
Execute the use case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command |
DeleteUserInvitationCommand
|
The input for this use case. |
required |
Raises:
Type | Description |
---|---|
UserInvitationNotFoundException
|
Raised when then invitation is not found. |
DeleteUserInvitationCommand
dataclass
¶
Input for the use case.
Attributes:
Name | Type | Description |
---|---|---|
uuid |
str
|
The unique id of the user invitation. |
kwai.modules.identity.get_user_invitation
¶
Implement the use case: get a user invitation.
GetUserInvitation
¶
Implements the use case 'get a user invitation'.
__init__(user_invitation_repo)
¶
Initialize the use case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_invitation_repo |
UserInvitationRepository
|
A repository for getting the user invitation. |
required |
execute(command)
async
¶
Execute the use case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command |
GetUserInvitationCommand
|
The input for this use case. |
required |
Returns:
Type | Description |
---|---|
UserInvitationEntity
|
A user invitation entity |
Raises:
Type | Description |
---|---|
UserInvitationNotFoundException
|
Raised when then invitation is not found. |
GetUserInvitationCommand
dataclass
¶
Input for the use case.
Attributes:
Name | Type | Description |
---|---|---|
uuid |
str
|
The unique id of the user invitation. |
kwai.modules.identity.get_invitations
¶
Implement the use case: get user invitations.
GetInvitations
¶
Implementation of the use case.
Use this use case for getting user invitations.
__init__(user_invitation_repo)
¶
Initialize the use case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_invitation_repo |
UserInvitationRepository
|
A repository for getting the user invitations. |
required |
execute(command)
async
¶
Execute the use case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command |
GetInvitationsCommand
|
The input for this use case. |
required |
Returns:
Type | Description |
---|---|
tuple[int, AsyncIterator[UserInvitationEntity]]
|
A tuple with the number of entities and an iterator for invitation entities. |
GetInvitationsCommand
dataclass
¶
Input for the use case.
Attributes:
Name | Type | Description |
---|---|---|
offset |
int | None
|
Offset to use. Default is None. |
limit |
int | None
|
The max. number of elements to return. Default is None, which means all. |
kwai.modules.identity.invite_user
¶
Module for the invite user use case.
InviteUser
¶
Invite user use case.
This use case will try to create an invitation for a user.
__init__(user, user_repo, user_invitation_repo, bus)
¶
Initialize the use case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user |
UserEntity
|
The inviter. |
required |
user_repo |
UserRepository
|
The repository to check if the email address is still free. |
required |
user_invitation_repo |
UserInvitationRepository
|
The repository for creating an invitation. |
required |
bus |
Bus
|
A message bus for publishing the user invitation created event. |
required |
execute(command)
async
¶
Execute the use case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command |
InviteUserCommand
|
The input for this use case. |
required |
Returns:
Type | Description |
---|---|
UserInvitationEntity
|
A user invitation |
Raises:
Type | Description |
---|---|
UnprocessableException
|
raised when the email address is already in use or when there are still pending invitations for the email address. |
InviteUserCommand
dataclass
¶
Input for the use case.
Attributes:
Name | Type | Description |
---|---|---|
first_name |
str
|
Firstname of the invited |
last_name |
str
|
Lastname of the invited |
email |
str
|
Email address of the invited |
expiration_in_days |
int
|
After how many days will the invitation expire? |
remark |
str
|
A remark about this invitation |
kwai.modules.identity.logout
¶
Module that implements the logout use case.
Logout
¶
Use case: logout a user.
A user is logged out by revoking the refresh token. The access token that is related to this refresh token will also be revoked.
Attributes:
Name | Type | Description |
---|---|---|
_refresh_token_repository |
RefreshTokenRepository
|
The repository to get and update the refresh token. |
_access_token_repository |
AccessTokenRepository
|
The repository to get and update the access token. |
execute(command)
async
¶
Execute the use case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command |
LogoutCommand
|
The input for this use case. |
required |
Raises:
Type | Description |
---|---|
RefreshTokenNotFoundException
|
The refresh token with the identifier could not be found. |
LogoutCommand
dataclass
¶
Command for the logout use case.
Attributes:
Name | Type | Description |
---|---|---|
identifier(str) |
The refresh token to revoke |
kwai.modules.identity.mail_user_invitation
¶
Module that defines the use case for sending a user invitation email.
MailUserInvitation
¶
Use case for sending a user invitation email.
execute(command)
async
¶
Execute the use case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command |
MailUserInvitationCommand
|
the input for this use case. |
required |
Raises:
Type | Description |
---|---|
UserInvitationNotFoundException
|
Raised when the user invitation cannot be found. |
UnprocessableException
|
Raised when the mail was already sent. Raised when the user recovery was already confirmed. |
MailUserInvitationCommand
dataclass
¶
Command for the use case MailUserInvitation.
Attributes:
Name | Type | Description |
---|---|---|
uuid |
str
|
The unique id of the user invitation. |
kwai.modules.identity.mail_user_recovery
¶
Module that defines the use case for sending a recovery email.
MailUserRecovery
¶
Use case for sending a recovery email.
execute(command)
async
¶
Execute the use case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command |
MailUserRecoveryCommand
|
The input for this use case. |
required |
Raises:
Type | Description |
---|---|
UserRecoveryNotFoundException
|
Raised when the user recovery cannot be found. |
UnprocessableException
|
Raised when the mail was already sent. Raised when the user recovery was already confirmed. |
MailUserRecoveryCommand
dataclass
¶
Command for the use case MailUserRecovery.
Attributes:
Name | Type | Description |
---|---|---|
uuid |
str
|
The unique id of the user recovery. |
kwai.modules.identity.recover_user
¶
Module that implements the recover user use case.
RecoverUser
¶
Use case: recover user.
Attributes:
Name | Type | Description |
---|---|---|
_user_account_repo |
UserAccountRepository
|
The repository for getting the user account. |
_user_recovery_repo |
UserRecoveryRepository
|
The repository for creating a user recovery. |
_event_bus |
Bus
|
An event bus for dispatching the UserRecoveryCreatedEvent event. |
execute(command)
async
¶
Execute the use case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command |
RecoverUserCommand
|
The input for this use case. |
required |
Raises:
Type | Description |
---|---|
UserAccountNotFoundException
|
Raised when the user with the given email address does not exist. |
UnprocessableException
|
Raised when the user is revoked |
RecoverUserCommand
dataclass
¶
Command for the recover user use case.
kwai.modules.identity.refresh_access_token
¶
Module that defines the use case for refreshing an access token.
RefreshAccessToken
¶
Use case for refreshing an access token.
Attributes:
Name | Type | Description |
---|---|---|
_refresh_token_repo |
RefreshTokenRepository
|
The repo for getting and creating a new refresh token. |
_access_token_repo |
AccessTokenRepository
|
The repo for updating and creating an access token. |
Note
A new access token will also result in a new refresh token.
execute(command)
async
¶
Execute the use case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command |
RefreshAccessTokenCommand
|
The input for this use case. |
required |
Raises:
Type | Description |
---|---|
RefreshTokenNotFoundException
|
Raised when the refresh token does not exist. |
AuthenticationException
|
Raised when the refresh token is expired, the refresh token is revoked or the user is revoked. |
RefreshAccessTokenCommand
dataclass
¶
Input for the refresh access token use case.
Attributes:
Name | Type | Description |
---|---|---|
identifier |
str
|
The identifier of the refresh token. |
access_token_expiry_minutes |
int
|
Minutes before expiring the access token. Default is 2 hours. |
refresh_token_expiry_minutes |
int
|
Minutes before expiring the refresh token. Default is 2 months. |
kwai.modules.identity.reset_password
¶
Module that implements the reset password use case.
ResetPassword
¶
Reset password use case.
This use case will try to reset the password of a user. A user can reset the password with a unique id. This unique id is linked to a user recovery.
__init__(user_account_repo, user_recovery_repo)
¶
Initialize the use case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_account_repo |
UserAccountRepository
|
The repository for getting the user account. |
required |
user_recovery_repo |
UserRecoveryRepository
|
The repository for getting and updating the user recovery. |
required |
execute(command)
async
¶
Execute the use case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command |
ResetPasswordCommand
|
The input for this use case. |
required |
Raises:
Type | Description |
---|---|
UserRecoveryNotFoundException
|
Raised when the user recovery with the given uuid does not exist. |
UserRecoveryExpiredException
|
Raised when the user recovery is expired. |
UserRecoveryConfirmedException
|
Raised when the user recovery is already used. |
UserAccountNotFoundException
|
Raised when the user with the email address that belongs to the user recovery, does not exist. |
NotAllowedException
|
Raised when the user is revoked. |
ResetPasswordCommand
dataclass
¶
Command for the reset password use case.
Attributes:
Name | Type | Description |
---|---|---|
uuid |
str
|
The unique id of the user recovery |
password |
str
|
The new password. |
UserRecoveryConfirmedException
¶
Bases: Exception
Raised when the user recovery was already used.
UserRecoveryExpiredException
¶
Bases: Exception
Raised when the user recovery is expired.