- 使用指南
- /
快速开始
- /
不同类型应用的接入方式
- /
- 在客户端应用中集成 Authing
¶ 在移动端(iOS、Android)中集成 Authing
更新时间: 2025-02-18 09:00:47
Authing 提供 Android SDK 和 iOS SDK 帮助开发者在移动 APP 中快速集成 Authing。
下面以 Android 应用的集成方式为例。
¶ 安装
- 下载 jar 包并将 jar 包导入 lib
Jar 包下载地址:
- https://download.authing.cn/packages/jar/commons-codec-1.15-rep.jar (opens new window)
- https://download.authing.cn/packages/jar/core.jar (opens new window)
将 Jar 包导入 lib,如下图所示:
- 配置
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')
复制成功
- 安装 Authing Java/Kotlin SDK
详细的安装指引请见:Authing Java/Kotlin SDK 。
¶ 使用示例
¶ Java
- 使用用户池 ID 初始化
AuthenticationClient
。 - 调用
AuthenticationClient
的方法。
// 使用 AppId 和 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
- 使用用户池 ID 初始化
AuthenticationClient
。 - 调用
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) { } })
复制成功
¶ 用户注册登录
Authing Java SDK 支持手机号验证码、邮箱、用户名等多种注册登录方式,以手机号验证码登录为例:
- 发送验证码
String phone = "phone number"; authenticationClient.sendSmsCode(phone).execute();
复制成功
- 使用验证码登录
String phone = "phone number"; String code = "1234"; User user = authenticationClient.loginByPhoneCode(new LoginByPhoneCodeInput(phone, code)).execute();
复制成功
详细文档请见:用户注册登录 API 。
¶ 集成微信登录
你可以使用 AuthenticationClient
的 loginByWechat
方法,所需四个参数均为微信返回的参数:
字段名 | 是否必填 | 类型 | 说明 |
---|---|---|---|
code | REQUIRED | string | 微信返回给 APP 的 code |
country | OPTIONAL | string | 微信返回给 APP 的 country |
lang | OPTIONAL | string | 微信返回给 APP 的 lang |
state | OPTIONAL | string | 微信返回给 APP 的 state |
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 } })
复制成功
¶ 获取帮助
评价此篇文档
有帮助
无帮助