# Core Authentication Module

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().registerByEmail(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> mailbox
  • password <string> password
  • profile <RegisterProfile> user profile
  • options <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

var email = "test@example.com";
var password = "123456";
var user = await authenticationClient.RegisterByEmail(email, password);
Console.WriteLine(user.Email);

# Register with username

AuthenticationClient().registerByUsername(username, password, profile, options)

Register with username

# Parameters

  • username <string> username
  • password <string> password
  • profile <RegisterProfile> user profile
  • options <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

var username = "test";
var password = "123456";
var user = await authenticationClient.RegisterByUsername(email, password);
Console.WriteLine(user.Username);

# Use mobile phone number to register

AuthenticationClient().registerByPhoneCode(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 number
  • code <string> SMS verification code
  • password <string> initial password
  • profile <RegisterProfile> user profile
  • options <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

var phone = "phone number";
var code = "1234";
var password = "123456";
var user = await authenticationClient.RegisterByPhoneCode(phone, code, password);
Console.WriteLine(user.Phone);

# Send SMS verification code

AuthenticationClient().sendSmsCode(phone)

Send SMS verification code, the validity time of the SMS verification code is 60 s.

# Parameters

  • phone <string>

# Example

var phone = "phone number";
await authenticationClient.SendSmsCode(phone);

# Login with email

AuthenticationClient().loginByEmail(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> mailbox
  • password <string> password
  • options <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 code
  • 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

var email = "test@example.com";
var password = "123456";
var user = await authenticationClient.LoginByEmail(email, password);
Console.WriteLine(user.Email);

# Login with username

AuthenticationClient().loginByUsername(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> username
  • password <string> password
  • options <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 code
  • 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

var username = "username";
var password = "123456";
var user = await authenticationClient.LoginByUsername(username, password);
Console.WriteLine(user.Username);

# Login with mobile phone number verification code

AuthenticationClient().loginByPhoneCode(phone, code)

Use the mobile phone number verification code to log in.

# Parameters

  • phone <string> phone number
  • code <string> SMS verification code
  • 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

var phone = "phone number";
var code = "1234";
var user = await authenticationClient.LoginByPhoneCode(phone, code);
Console.WriteLine(user.Phone);

# Login with mobile phone number and password

AuthenticationClient().loginByPhonePassword(phone, password, options)

Use your phone number and password to log in.

# Parameters

  • phone <string> phone number
  • password <string> password
  • options <Object>
  • options.captchaCode <string> Graphic verification code
  • 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

var phone = "phone number";
var password = "123456";
var user = await authenticationClient.LoginByPhonePassword(phone, password);
Console.WriteLine(user.Phone);

# Check Token login status

AuthenticationClient().checkLoginStatus(token)

Check Token login status

# Parameters

  • token <string> user's login credentials token

# Example

Console.WriteLine(status.code == 200);

# send email

AuthenticationClient().sendEmail(email, scene)

Send mail

# Parameters

  • email <string> mailbox
  • scene <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

using Authing.ApiClient.Types;
var message = await authenticationClient.SendEmail("test@example.com", EmailScene.RESET_PASSWORD);

# Reset password via SMS verification code

AuthenticationClient().resetPasswordByPhoneCode(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 number
  • code <string> verification code
  • newPassword <string> new password

# Example

var phone = "phone number";
var code = "1234";
var password = "123456";
var message = await authenticationClient.ResetPasswordByPhoneCode(phone, code, password);

# Reset password via email verification code

AuthenticationClient().resetPasswordByEmailCode(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 number
  • code <string> verification code
  • newPassword <string> new password

# Example

var email = "test@example.com";
var code = "1234";
var password = "123456";
var message = await authenticationClient.ResetPasswordByEmailCode(email, code, password);

# Modify user information

AuthenticationClient().updateProfile(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 profile
  • updates.username <string> username
  • updates.nickname <string> nickname
  • updates.photo <string> Avatar
  • updates.company <string> company
  • updates.browser <string> browser
  • updates.device <string> device
  • updates.lastIP <string> Last logged in IP
  • updates.name <string> Name
  • updates.givenName <string> Given Name
  • updates.familyName <string> Family Name
  • updates.middleName <string> Middle Name
  • updates.profile <string> Profile Url
  • updates.preferredUsername <string> Preferred Name
  • updates.website <string> personal website
  • updates.gender <string> gender, M stands for male, W stands for female, and U stands for unknown.
  • updates.birthdate <string> birthday
  • updates.zoneinfo <string> time zone
  • updates.locale <string> language
  • updates.address <string> address
  • updates.streetAddress <string> street address
  • updates.locality <string>
  • updates.region <string> region
  • updates.postalCode <string> Zip code
  • updates.city <string> city
  • updates.province <string> province
  • updates.country <string> country

# Example

var user = await authenticationClient.UpdateProfile(new UpdateUserInput()
{
  Nickname = nickname,
});

# Update user password

AuthenticationClient().updatePassword(newPassword, oldPassword)

Update user password

# Parameters

  • newPassword <string> new password
  • oldPassword <string> Old password, if the user has not set a password, you can leave it blank.

# Example

var oldPassword = "111111";
var newPassword = "123456";
await authenticationClient.UpdatePassword(newPassword, oldPassword);

# Update user phone number

AuthenticationClient().updatePhone(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 number
  • phoneCode <string> The verification code of the new phone number
  • oldPhone <string> old phone number
  • oldPhoneCode <string> The verification code of the old phone number

# Example

await authenticationClient.UpdatePhone("phone number", "1234");

# Update user mailbox

AuthenticationClient().updateEmail(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 mailbox
  • emailCode <string> The verification code of the new mailbox
  • oldEmail <string> old email
  • oldEmailCode <string> The verification code of the old email

# Example

var newEmail = "new@example.com";
var emailCode = "1234"
await authenticationClient.UpdateEmail(newEmail, emailCode);

# Refresh the current user's token

AuthenticationClient().refreshToken()

Refresh the token of the current user, and call this interface to require login first.

# Parameters

# Example

var refreshToken = await authenticationClient.RefreshToken();
Console.WriteLine(refreshToken.Token);

# Bind mobile phone number

AuthenticationClient().bindPhone(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

var phone = "phone number";
var phoneCode = "1234"
await authenticationClient.BindPhone(phone, phoneCode);

# Unbind mobile phone number

AuthenticationClient().unbindPhone()

User unbind mobile phone number

# Parameters

# Example

await authenticationClient.UnbindPhone();

# Unbind mobile phone number

AuthenticationClient().unbindPhone()

User unbind mobile phone number

# Parameters

# Example

await authenticationClient.UnbindPhone();

# Get the currently logged-in user information