Authing DocsDocuments
Concept
workflow
Guides
Development Integration
Application integration
Concept
workflow
Guides
Development Integration
Application integration
Old Version
Development Integration
  • Single Sign-On (SSO)
  • Login component

  • JavaScript/Node.js

  • Java / Kotlin

  • Python

  • C#

  • PHP

  • Go

  • Ruby
  • Android

  • iOS

    • Quick start
    • Auth Flow
    • APIs

      • Authentication
      • OIDC
      • MFA
      • User management
      • Scan to login
    • Third-party identity source

    • Typical scene

    • On-premise
    • WebAuthn
    • Error Code List
  • Flutter

  • React Native
  • WeChat Mini Program
  • WeChat webpage authorization
  • Framework Integration
  • Error code
  1. Development Integration
  2. /
  3. iOS
  4. /
  5. APIs
  6. /
  7. Authentication

¶ Core Authentication API

Update Time: 2026-03-25 09:13:34
Edit

¶ 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 address
  • password password
  • context Request context, set here context 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 address
  • 2026 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 address
  • code code
  • context Request context, set here context 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 address
  • 2026 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 username
  • password password
  • context Request context, set here context 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 number
  • code SMS verification code
  • password initial password, it can be null
  • context Request context, set here context 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 error
  • 2026 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 address
  • code email verification code
  • autoRegister 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 here context 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 / username
  • password password
  • autoRegister 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 here context 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 number
  • code SMS verification code
  • autoRegister 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 here context 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 return
  • accessToken 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 +86
  • phone 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 address
  • scene 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 number
  • code SMS Verification code
  • password 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 address
  • code Verification code
  • password 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 password
  • oldPassword 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 in
  • 1320011 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 number
  • code 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 in
  • 1320005 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 address
  • code 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 in
  • 1320005 The current user is not bound to a mailbox

Prev: APIs Next: OIDC
  • Use email and password registration
  • Use email and verification code registration
  • Register using username
  • Use mobile phone number registration
  • Use the email to login
  • Use the username to login
  • Use the mobile phone number verification code to login
  • Mobile Fast Auth
  • Get the user information of current login
  • Sign out
  • Send verification code
  • Send email
  • Reset password via SMS verification code
  • Reset password via mail verification code
  • Reset password through the first login Token
  • Update user password
  • Binding mobile phone number
  • Solution to the mobile number
  • Binding mailbox
  • Menned mailbox

User identity management

Integrated third-party login
Mobile phone number flash check (opens new window)
Universal login form component
Custom authentication process

Enterprise internal management

Single Sign On
Multi-factor Authentication
Authority Management

Developers

Development Document
Framework Integration
Blog (opens new window)
GitHub (opens new window)
Community User Center (opens new window)

Company

400 888 2106
sales@authing.cn
16 / F, Block B, NORTH STAR CENTURY CENTER, Beijing(Total)
room 406, 4th floor, zone B, building 1, No. 200, Tianfu Fifth Street, Chengdu(branch)

Beijing ICP No.19051205-1

© Beijing Steamory Technology Co.