Skip to content

Integrate GenAuth in mobile (iOS, Android)

GenAuth provides Android SDK and iOS SDK to help developers quickly integrate GenAuth in mobile apps.

The following takes the integration method of Android apps as an example.

Installation

  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 GenAuth Java/Kotlin SDK

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

Example

Java

  • Initialize AuthenticationClient with the user pool ID.
  • Call AuthenticationClient methods.
java
// Initialize with AppId and appHost
AuthenticationClient authentication = new AuthenticationClient(APP_ID, APP_HOST);

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 AuthenticationClient method.
kotlin
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

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

  1. Send verification code
java
String phone = "phone number";
authenticationClient.sendSmsCode(phone).execute();
  1. Login using verification code
java
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 .

Integrate WeChat login

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

Field nameRequiredTypeDescription
codeREQUIREDstringThe code returned by WeChat to APP
countryOPTIONALstringThe country returned by WeChat to APP
langOPTIONALstringThe lang returned by WeChat to APP
stateOPTIONALstringThe state returned by WeChat to APP
kotlin
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
    }
})

Get help

Please visit the GenAuth forum.

Agent infrastructure for identity, memory, and web action.