# Core Authentication Module
- Core Authentication Module
- Register with Email
- Register with username
- Use mobile phone number to register
- Send SMS verification code
- Login with email
- Login with username
- Login with mobile phone number verification code
- Login with mobile phone number and password
- Check Token login status
- send email
- Reset password via SMS verification code
- Reset password via email verification code
- Modify user information
- Update user password
- Update user phone number
- Update user mailbox
- Refresh the current user's token
- Bind mobile phone number
- Unbind mobile phone numberAuthenticationClient().unbind_phone()
- Unbind mobile phone number
- Get the currently logged-in user information
- sign out
- Get the current user's custom data list
- Add custom data
- Delete custom data
This module contains methods such as registering and logging in, resetting the mobile phone number, email, and modifying account information. It is requested as your end user (End User), and is suitable for use in situations where the identity of the user needs to be verified.
# Register with Email
AuthenticationClient().register_by_email(email, password, profile, options)
Use email to register. This interface does not require the user to verify the email. After the user registers, the emailVerified field will be false. If you want users with unauthenticated mailboxes to be unable to log in, you can use the pipeline to intercept such requests.
# Parameters
email
<string> mailboxpassword
<string> passwordprofile
<RegisterProfile> user profileoptions
<Object>options.forceLogin
<boolean> Whether to go through the complete login, it will trigger the pipeline function before and after the login and the login event webhook, and the cumulative login times of the user will be increased by 1. The default is false.options.generateToken
<boolean> Whether to generate a token for the user, it will not trigger the complete process after login, and the user's cumulative login times will not increase by 1. The default is false.options.clientIp
<string> The real IP of the client. If you call this interface on the server, you must set this parameter to the real IP of the end user.
# Example
email ='test@example.com'
user = authentication_client.register_by_email(
email=email,
password='passw0rd',
profile={
'nickname':'Nick'
}
)
# Register with username
AuthenticationClient().register_by_username(username, password, profile, options)
Register with username
# Parameters
username
<string> usernamepassword
<string> passwordprofile
<RegisterProfile> user profileoptions
<Object>options.forceLogin
<boolean> Whether to go through the complete login, it will trigger the pipeline function before and after the login and the login event webhook, and the cumulative login times of the user will be increased by 1. The default is false.options.generateToken
<boolean> Whether to generate a token for the user, it will not trigger the complete process after login, and the user's cumulative login times will not increase by 1. The default is false.options.clientIp
<string> The real IP of the client. If you call this interface on the server, you must set this parameter to the real IP of the end user.
# Example
username ='bob'
user = authentication_client.register_by_username(
username=username,
password='passw0rd',
profile={
'nickname':'Nick'
}
)
# Use mobile phone number to register
AuthenticationClient().register_by_phone_code(phone, code, password, profile, options)
Register with your mobile phone number, you can set the initial password of the account at the same time. Please see sendSmsCode for the interface to send SMS
# Parameters
phone
<string> phone numbercode
<string> SMS verification codepassword
<string> initial passwordprofile
<RegisterProfile> user profileoptions
<Object>options.forceLogin
<boolean> Whether to go through the complete login, it will trigger the pipeline function before and after the login and the login event webhook, and the cumulative login times of the user will be increased by 1. The default is false.options.generateToken
<boolean> Whether to generate a token for the user, it will not trigger the complete process after login, and the user's cumulative login times will not increase by 1. The default is false.options.clientIp
<string> The real IP of the client. If you call this interface on the server, you must set this parameter to the real IP of the end user.
# Example
phone = '176xxxx7041'
user = authentication_client.register_by_phone_code(
phone=phone,
code='1234',
password='passw0rd',
profile={
'nickname':'Nick'
}
)
# Send SMS verification code
AuthenticationClient().send_sms_code(phone)
Send SMS verification code, the validity time of the SMS verification code is 60 s.
# Parameters
phone
<string>
# Example
authentication_client.send_sms_code(
phone="176xxxx7041",
)
# Login with email
AuthenticationClient().login_by_email(email, password, options)
Use email to log in. By default, the interface does not restrict logins to unverified emails. If you want users with unverified emails to not log in, you can use the pipeline to intercept such requests.
If your user pool is configured with login failure detection, the user will be asked to enter a graphic verification code (code 2000) when the login fails multiple times under the same IP.
# Parameters
email
<string> mailboxpassword
<string> passwordoptions
<Object>options.autoRegister
<boolean> Whether to register automatically. If it detects that the user does not exist, an account will be automatically created based on the login account password.options.captchaCode
<string> Graphic verification codeoptions.clientIp
<string> The real IP of the client. If you call this interface on the server, you must set this parameter to the real IP of the end user.
# Example
email ='test@example.com'
user = authentication_client.register_by_email(
email=email,
password='passw0rd',
auto_register=True, # If the user does not exist, whether to register automatically.
)
# Login with username
AuthenticationClient().login_by_username(username, password, options)
Log in with username.
If your user pool is configured with login failure detection, the user will be asked to enter a graphic verification code (code 2000) when the login fails multiple times under the same IP.
# Parameters
username
<string> usernamepassword
<string> passwordoptions
<Object>options.autoRegister
<boolean> Whether to register automatically. If it detects that the user does not exist, an account will be automatically created based on the login account password.options.captchaCode
<string> Graphic verification codeoptions.clientIp
<string> The real IP of the client. If you call this interface on the server, you must set this parameter to the real IP of the end user.
# Example
username ='bob'
user = authentication_client.register_by_username(
username=username,
password='passw0rd',
auto_register=True, # If the user does not exist, whether to register automatically.
)
# Login with mobile phone number verification code
AuthenticationClient().login_by_phone_code(phone, code)
Use the mobile phone number verification code to log in.
# Parameters
phone
<string> phone numbercode
<string> SMS verification codeoptions.clientIp
<string> The real IP of the client. If you call this interface on the server, you must set this parameter to the real IP of the end user.
# Example
phone = '176xxxx7041'
# Mobile phone number verification code login, if the user does not exist, an account will be created automatically
user = authentication_client.login_by_phone_code(
phone=phone,
code='1234',
)
# Login with mobile phone number and password
AuthenticationClient().login_by_phone_password(phone, password, options)
Use your phone number and password to log in.
# Parameters
phone
<string> phone numberpassword
<string> passwordoptions
<Object>options.captchaCode
<string> Graphic verification codeoptions.clientIp
<string> The real IP of the client. If you call this interface on the server, you must set this parameter to the real IP of the end user.
# Example
phone = '176xxxx7041'
user = authentication_client.login_by_phone_password(
phone=phone,
password='passw0rd',
)
# Check Token login status
AuthenticationClient().check_login_status(token)
Check Token login status
# Parameters
token
<string> user's login credentials token
# Example
# Check the valid status of any tokendata = authentication.check_login_status(token="TOKEN")
# Called login before or initialized through access_token
# Check the login status of the current user
data = authentication.check_login_status()
# send email
AuthenticationClient().send_email(email, scene)
Send mail
# Parameters
email
<string> mailboxscene
<EmailScene> Sending scene, optional values are RESET_PASSWORD (send reset password email, the email contains the verification code), VerifyEmail (send the email to verify the email), ChangeEmail (send the modified email, the email contains Verification code)
# Example
authentication_client.send_email(
email="test@example.com",
scene="RESET_PASSWORD",
)
# Reset password via SMS verification code
AuthenticationClient().reset_password_by_phone_code(phone, code, newPassword)
To reset the password by SMS verification code, you need to call the sendSmsCode interface to send the reset password email.
# Parameters
phone
<string> phone numbercode
<string> verification codenewPassword
<string> new password
# Example
authentication_client.reset_password_by_phone_code(
phone="176xxxx7041",
code="1234",
new_password="passw0rd"
)
# Reset password via email verification code
AuthenticationClient().reset_password_by_email_code(phone, code, newPassword)
To reset the password through the email verification code, you need to call the sendEmail interface to send the reset password email.
# Parameters
phone
<string> phone numbercode
<string> verification codenewPassword
<string> new password
# Example
authentication_client.reset_password_by_email_code(
email="test@example.com",
code="1234",
new_password="passw0rd"
)
# Modify user information
AuthenticationClient().update_profile(updates)
Modify user information. This interface cannot be used to modify the phone number, email address, and password. If necessary, please call the updatePhone, updateEmail, and updatePassword interfaces.
# Parameters
updates
<UpdateUserInput> modified user profileupdates.username
<string> usernameupdates.nickname
<string> nicknameupdates.photo
<string> Avatarupdates.company
<string> companyupdates.browser
<string> browserupdates.device
<string> deviceupdates.lastIP
<string> Last logged in IPupdates.name
<string> Nameupdates.givenName
<string> Given Nameupdates.familyName
<string> Family Nameupdates.middleName
<string> Middle Nameupdates.profile
<string> Profile Urlupdates.preferredUsername
<string> Preferred Nameupdates.website
<string> personal websiteupdates.gender
<string> gender, M stands for male, W stands for female, and U stands for unknown.updates.birthdate
<string> birthdayupdates.zoneinfo
<string> time zoneupdates.locale
<string> languageupdates.address
<string> addressupdates.streetAddress
<string> street addressupdates.locality
<string>updates.region
<string> regionupdates.postalCode
<string> Zip codeupdates.city
<string> cityupdates.province
<string> provinceupdates.country
<string> country
# Example
user = authentication_client.update_profile({
'nickname':'Nick'
})
# Update user password
AuthenticationClient().update_password(newPassword, oldPassword)
Update user password
# Parameters
newPassword
<string> new passwordoldPassword
<string> Old password, if the user has not set a password, you can leave it blank.
# Example
# If you register by other means such as mobile phone number, social login, etc., no password is set for the first time, and leave old_password blank.
authentication_client.update_password(
new_password="passw0rd",
)
# The user has previously set a password
authentication_client.update_password(
new_password="passw0rd",
old_password="123456!"
)
# Update user phone number
AuthenticationClient().update_phone(phone, phoneCode, oldPhone, oldPhoneCode)
Update the user's mobile phone number. Just like modifying the mailbox, by default, if the user has already bound a mobile phone number, the original mobile phone number (the mobile phone number bound to the current account) and the current mailbox (the mobile phone number to be bound) need to be verified at the same time. In other words, the mobile phone number currently bound to user A is 15888888888, and if you want to change it to 15899999999, you need to verify both mobile phone numbers. Developers can also choose not to turn on "Verify original phone number", which can be turned off in the security information module under the settings directory of the Authing console. To bind a mobile phone number for the first time, please use the bindPhone interface.
# Parameters
phone
<string> new phone numberphoneCode
<string> The verification code of the new phone numberoldPhone
<string> old phone numberoldPhoneCode
<string> The verification code of the old phone number
# Example
# Turn off the "Verify original phone number" option
authentication_client.update_email(
phone="test1@example.com",
phoneCode="1234",
)
# Turn on the "Verify original phone number" option
authentication_client.update_email(
phone="test1@example.com",
phoneCode="1234",
oldPhone="test2@exmaple.com",
oldPhoneCode="1234"
)
# Update user mailbox
AuthenticationClient().update_email(email, emailCode, oldEmail, oldEmailCode)
If the user has already bound the mailbox, by default, the original mailbox (the mailbox bound to the current account) and the current mailbox (the mailbox to be bound) need to be verified at the same time. In other words, the currently bound mailbox of user A is 123456@qq.com, and wants to modify it to 1234567@qq.com, then both mailboxes need to be verified at the same time. Developers can also choose not to turn on "Verify original mailbox", which can be turned off in the security information module under the settings directory of the Authing console. For the first time to bind a mobile phone number, please use the bindEmail interface.
# Parameters
email
<string> new mailboxemailCode
<string> The verification code of the new mailboxoldEmail
<string> old emailoldEmailCode
<string> The verification code of the old email
# Example
# Turn off the "Verify original mailbox" option
authentication_client.update_email(
email="test1@example.com",
emailCode="1234",
)
# Turn on the "Verify original mailbox" option
authentication_client.update_email(
email="test1@example.com",
emailCode="1234",
oldEmail="test2@exmaple.com",
oldEmailCode="1234"
)
# Refresh the current user's token
AuthenticationClient().refresh_token()
Refresh the token of the current user, and call this interface to require login first.
# Parameters
# Example
authentication_client.refresh_token()
# Bind mobile phone number
AuthenticationClient().bind_phone(phone, phoneCode)
The user binds the mobile phone number for the first time. If you need to modify the mobile phone number, please use the updatePhone interface.
# Parameters
phone
<string>phoneCode
<string>
# Example
phone = '176xxxx7041'
user = authentication_client.bind_phone(
phone=phone,
phoneCode='1234',
)
# Unbind mobile phone numberAuthenticationClient().unbind_phone()
User unbind mobile phone number
# Parameters
# Example
user = authentication_client.unbind_phone()
# Unbind mobile phone number
AuthenticationClient().unbind_phone()
User unbind mobile phone number
# Parameters
# Example
user = authentication_client.unbind_phone()
# Get the currently logged-in user information
AuthenticationClient().get_current_user()
Get the information of the currently logged in user
# Parameters
# Example
# sign out
AuthenticationClient().logout()
Log out, clear the user and token in localStorage
# Parameters
# Example
authentication_client.logout()
# Get the current user's custom data list
AuthenticationClient().list_udv()
Get the current user's custom data list
# Parameters
# Example
udvs = authentication_client.list_udv()
# Add custom data
AuthenticationClient().set_udv(key, value)
Add custom data
# Parameters
key
<string> custom field keyvalue
<any> The value of the custom data, the value type must be consistent with the custom field type defined by the user pool.
# Example
# Set int type data
authentication_client.set_udv(
key="age",
value=15
)
# Set boolen type data
authentication_client.set_udv(
key="is_ok",
value=True
)
# Delete custom data
AuthenticationClient().remove_udv(key)
Delete custom data
# Parameters
key
<null> custom field key
# Example
authentication_client.remove_udv(
key="age"
)