# SDK for Android

Developers can use Authing Java/Kotlin SDK to integrate Authing service in Andorid applications.

# Integration Steps

  1. Download the jar package and import the jar package into lib

Jar package download address:

Import the Jar package into lib, as shown below:

  1. Configure build.gradle
implementation "com.google.code.gson:gson:2.8.6"
implementation "com.squareup.okhttp3:okhttp:4.8.0"
implementation files('libs/core.jar')
implementation files('libs/commons-codec-1.15-rep.jar')
  1. Install Authing Java/Kotlin SDK

For detailed installation instructions, please see: Authing Java/Kotlin SDK.

# Usage example

# Java

-Initialize AuthenticationClient with user pool ID. -Call the method of AuthenticationClient.

AuthenticationClient client = new AuthenticationClient("YOUR_USERPOOL_ID");

client.registerByEmail(new RegisterByEmailInput("xxx@qq.com", "123456")).enqueue(new cn.authing.core.http.Callback<cn.authing.core.types.User>() {
    @Override
    public void onSuccess(cn.authing.core.types.User user) {

    }

    @Override
    public void onFailure(@Nullable GraphQLResponse.ErrorInfo errorInfo) {

    }
});

# Kotlin

-Initialize AuthenticationClient with user pool ID. -Call the method of AuthenticationClient.

val authenticationClient = AuthenticationClient("YOUR_USERPOOL_ID")

authenticationClient.registerByEmail(
    RegisterByEmailInput(
        "xxx@.qq.com",
        "123456"
    )
).enqueue(object: cn.authing.core.http.Callback<User> {
    override fun onFailure(error: ErrorInfo?) {

    }

    override fun onSuccess(result: User) {

    }
})

# User registration and login

Authing Java SDK supports multiple registration and login methods such as mobile phone number verification code, email address, and user name. Take mobile phone number verification code login as an example:

  1. Send verification code
String phone = "phone number";
authenticationClient.sendSmsCode(phone).execute();
  1. Login with verification code
String phone = "phone number";
String code = "1234";
User user = authenticationClient.loginByPhoneCode(new LoginByPhoneCodeInput(phone, code)).execute();

For detailed documentation, please see: User Registration and Login API.

# Manage user-defined data

For an introduction to the use of user-defined data, please see: User-defined fields, you can get, add, and delete user-defined data in the Authing Java/Kotlin SDK. For details, see : [Manage user-defined data] (./sdk-for-java/authentication/README.md##Get the current user's custom data list).

# Integrated WeChat login

You can use the loginByWechat method of AuthenticationClient, the required four parameters are all parameters returned by WeChat:

Field name Is it required Type Description
code REQUIRED string code returned by WeChat to APP
country OPTIONAL string WeChat returns to APP country
lang OPTIONAL string WeChat return to APP lang
state OPTIONAL string State returned to APP by WeChat
val authenticationClient = AuthenticationClient("YOUR_USERPOOL_ID")

val code = "#returned code from wechat#";

authenticationClient.loginByWechat(code).enqueue(object: cn.authing.core.http.Callback<User> {
    override fun onFailure(error: ErrorInfo?) {

    }

    override fun onSuccess(result: User) {
        val user = result
    }
})

# Other

For other details, please see: Authing SDK for Java/Android.