- User Guide
- /
Quick Start
- /
Integration Methods for Different Applications
- /
- Integrate GenAuth with Mobile Apps
¶ 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
- Download the jar package and import the jar package into lib
Jar package download address:
- https://download.genauth.ai/packages/jar/commons-codec-1.15-rep.jar (opens new window)
- https://download.genauth.ai/packages/jar/core.jar (opens new window)
Import the Jar package into lib, as shown below:
- 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')
- 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.
// 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.
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:
- Send verification code
String phone = "phone number";
authenticationClient.sendSmsCode(phone).execute();
- Login using 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 .
¶ Integrate WeChat login
You can use the loginByWechat
method of AuthenticationClient
. The four required parameters are all parameters returned by WeChat:
Field name | Required | Type | Description |
---|---|---|---|
code | REQUIRED | string | The code returned by WeChat to APP |
country | OPTIONAL | string | The country returned by WeChat to APP |
lang | OPTIONAL | string | The lang returned by WeChat to APP |
state | OPTIONAL | string | The state returned by WeChat to APP |
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 (opens new window).