¶ Core Authentication API
¶ Use email and password registration
Use the email registration, the mailbox is not case sensitive and the only userpool is unique. This interface does not require the user to verify the mailbox, after the user registration, the emailVerified field will be false.
func registerByEmail(email: String, password: String, _ context: String? = nil, completion: @escaping(Int, String?, UserInfo?) -> Void)
Parameter
email
email addresspassword
passwordcontext
Request context, set herecontext
you can get pipeline context .
Example
AuthClient().registerByEmail(email: "me@gmail.com", password: "strong") { code, message, userInfo in
if (code == 200) {
// userInfo
}
}
Error Code
2003
Illegal email address2026
Registered mailbox
¶ Use email and verification code registration
Use the email registration, the mailbox is not case sensitive and the only userpool is unique, you need to call sendEmail interface to send a reset password message (the scene value VERIFY_CODE
).
func registerByEmailCode(email: String, code: String, _ context: String? = nil, completion: @escaping(Int, String?, UserInfo?) -> Void)
Parameter
email
email addresscode
codecontext
Request context, set herecontext
you can get pipeline context .
Example
AuthClient().registerByEmailCode(email: "me@gmail.com", code: "code") { code, message, userInfo in
if (code == 200) {
// userInfo
}
}
Error Code
2003
Illegal email address2026
Registered mailbox
¶ Register using username
Use the username to register, the username is case sensitive and the only user pool.
func registerByUserName(username: String, password: String, _ context: String? = nil, completion: @escaping(Int, String?, UserInfo?) -> Void)
Parameter
username
usernamepassword
passwordcontext
Request context, set herecontext
you can get pipeline context .
Example
AuthClient().registerByUserName(username: "username", password: "strong") { code, message, userInfo in
if (code == 200) {
// userInfo
}
}
Error Code
2026
The user name already exists
¶ Use mobile phone number registration
Use your mobile phone number to register, you can set the initial password of the account at the same time. You can pass sendSmsCode method sends SMS verification code.
func registerByPhoneCode(phone: String, code: String, password: String, _ context: String? = nil, completion: @escaping(Int, String?, UserInfo?) -> Void)
Parameter
phone
The phone numbercode
SMS verification codepassword
initial password, it can be nullcontext
Request context, set herecontext
you can get pipeline context .
Example
AuthClient().registerByPhoneCode(phone: "188xxxx8888", code: "1234", password: "strong") { code, message, userInfo in
if (code == 200) {
// userInfo
}
}
Error Code
2001
SMS verification code error2026
Cell phone number registered
¶ Use the email to login
func loginByEmail(email: String, code: String, _ autoRegister: Bool = false, _ context: String? = nil, completion: @escaping(Int, String?, UserInfo?) -> Void)
Parameter
email
email addresscode
email verification codeautoRegister
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.context
Request context, set herecontext
you can get pipeline context .
Example
AuthClient().loginByEmail(email: "email", code: "code") { code, message, userInfo in
if (code == 200) {
// userInfo
}
}
Error Code
2001
email verification code error
¶ Use the username to login
func loginByAccount(account: String, password: String, _ autoRegister: Bool = false, _ context: String? = nil, completion: @escaping(Int, String?, UserInfo?) -> Void)
Parameter
account
The phone number / email address / usernamepassword
passwordautoRegister
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.context
Request context, set herecontext
you can get pipeline context .
Example
AuthClient().loginByAccount(account: "account", password: "strong") { code, message, userInfo in
if (code == 200) {
// userInfo
}
}
Error Code
2333
The account or password is incorrect
¶ Use the mobile phone number verification code to login
Use the mobile phone number verification code to log in. You need to use it first sendSmsCode sends a SMS verification code.
func loginByPhoneCode(phone: String, code: String, _ autoRegister: Bool = false, _ context: String? = nil, completion: @escaping(Int, String?, UserInfo?) -> Void)
Parameter
phone
The phone numbercode
SMS verification codeautoRegister
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.context
Request context, set herecontext
you can get pipeline context .
Example
AuthClient().loginByPhoneCode(phone: "188xxxx8888", code: "1234") { code, message, userInfo in
if (code == 200) {
// userInfo
}
}
Error Code
2001
SMS verification code error
¶ Mobile Fast Auth
func loginByOneAuth(token: String, accessToken: String, completion: @escaping(Int, String?, UserInfo?) -> Void)
Parameter
token
Operators returnaccessToken
Operators return
Example
AuthClient().loginByOneAuth(token: "token", accessToken: "accessToken") { code, message, userInfo in
if (code == 200) {
// userInfo
}
}
Error Code
2333
The account or password is incorrect
¶ Get the user information of current login
Get the user information of the current login user, you need that is currently logged in to get it.
func getCurrentUser(completion: @escaping(Int, String?, UserInfo?) -> Void)
Example
AuthClient().getCurrentUser { code, message, userInfo in
if (code == 200) {
// userInfo
}
}
Error Code
2020
Not logged in
¶ Sign out
Log out. Clear token and user information for both memory and local persistence. Authing.getcurrentuser () returns empty after logging out.
func logout(completion: @escaping(Int, String?) -> Void)
Example
AuthClient().logout { code, message in
}
Error Code
1010001
If the user id token is invalid or expired
¶ Send verification code
Sends an SMS verification code to the specified mobile phone.
func sendSms(phone: String, phoneCountryCode: String? = nil, completion: @escaping(Int, String?) -> Void)
Parameter
phoneCountryCode
Telephone country code, If null, the default value is +86phone
The phone number
Example
AuthClient().sendSms(phone: "188xxxx8888", phoneCountryCode: "+86") { code, message in
}
Error Code
500
The mobile phone number format is invalid
¶ Send email
Sends an email to the specified mailbox.
func sendEmail(email: String, scene: String, completion: @escaping(Int, String?) -> Void)
Parameter
email
email addressscene
Send a scene, optional value is :RESET_PASSWORD
: Send a reset password message, including the verification code.CHANGE_EMAIL
: Send a modified mailbox message, including the verification code.MFA_VERIFY
: Send MFA verification email.VERIFY_CODE
: Send verification email.
Example
AuthClient().sendEmail(email: "cool@gmail.com", scene: "RESET_PASSWORD") { code, message in
if (code == 200) {
// success
}
}
Error Code
1020017
Invalid email address
¶ Reset password via SMS verification code
Reset your password by SMS verification code, you can send SMS verification code by sendSmsCode method.
func resetPasswordByPhone(phone: String, code: String, newPassword: String, completion: @escaping(Int, String?) -> Void)
Parameter
phone
The phone numbercode
SMS Verification codepassword
New password
Example
AuthClient().resetPasswordByPhone(phone: "188xxxx8888", code: "1234", newPassword: "strong") { code, message in
if (code == 200) {
}
}
Error Code
2004
User does not exist
¶ Reset password via mail verification code
Reset password by email verification code, you need to call sendEmail interface to send a reset password message (the scene value RESET_PASSWORD
).
func resetPasswordByEmail(email: String, code: String, newPassword: String, completion: @escaping(Int, String?) -> Void)
Parameter
email
Email addresscode
Verification codepassword
New password
Example
AuthClient().resetPasswordByEmailCode(email: "me@gmail.com", code: "1234", newPassword: "strong") { code, message, in
if (code == 200) {
}
}
Error Code
2004
User does not exist
¶ Reset password through the first login Token
Reset password through the first login Token. You need to set Force User to change password at first login when creating a user.
func resetPasswordByFirstTimeLoginToken(token: String, password: String, completion: @escaping(Int, String?) -> Void)
参数
- token token
- password password
示例
AuthClient().resetPasswordByFirstTimeLoginToken(token: "token", password: "strong") { code, message in
if (code == 200) {
}
}
¶ Update user password
Update the user password. If the user does not set a password, such as SMS verification code, social login, etc., oldPassword is left blank.
func updatePassword(newPassword: String, oldPassword: String? = nil, completion: @escaping(Int, String?, UserInfo?) -> Void)
Parameter
newPassword
New passwordoldPassword
Old password, if the user does not set a password, you can not fill
Example
AuthClient().updatePassword(newPassword: "newStrong", oldPassword: "oldStrong") { code, message, userInfo in
if (code == 200) {
}
}
Error Code
2020
Not logged in1320011
The old password is incorrect
¶ Binding mobile phone number
Bind the mobile phone number of the current login user. you can send SMS verification code by sendSmsCode method.
func bindPhone(phone: String, code: String, completion: @escaping(Int, String?, UserInfo?) -> Void)
Parameter
phone
Thie phone numbercode
SMS Verification code
Example
AuthClient().bindPhone(phone: "188xxxx8888", code: "1234") { code, message, userInfo in
if (code == 200) {
}
}
Error Code
2020
Not logged in
¶ Solution to the mobile number
The user unbinds the mobile phone number. If the user does not bind other login methods (such as email or social login account), the mobile phone number cannot be unbound and an error message is displayed.
func unbindPhone(completion: @escaping(Int, String?, UserInfo?) -> Void)
Example
AuthClient().unbindPhone { code, message, userInfo in
if (code == 200) {
}
}
Error Code
2020
Not logged in1320005
The current user is not bound to any other login mode
¶ Binding mailbox
The mailbox is bound to the current login user. call [Send emai](#Send email) to get the verification code.
func bindEmail(email: String, code: String, completion: @escaping(Int, String?, UserInfo?) -> Void)
Parameter
email
Email addresscode
Email verification code
Example
AuthClient().bindEmail(email: "me@gmail.com", code: "1234") { code, message, userInfo in
if (code == 200) {
}
}
Error Code
2020
Not logged in
¶ Menned mailbox
The user solves the mobile phone number. If the user does not bind other login mode (mobile phone number, social login account), it will not be able to decompose the mailbox, will prompt the error.
func unbindEmail(completion: @escaping(Int, String?, UserInfo?) -> Void)
Example
AuthClient().unbindEmail { code, message, userInfo in
if (code == 200) {
}
}
Error Code
2020
Not logged in1320005
The current user is not bound to a mailbox