GenAuth DocsDocuments
Concepts
User Guide
Development Integration
AgentAuth
Metadata
Development Integration
Multi-tenant (beta)
Console Documentation
Multi-tenant Console
Tenant Console
Saas Application Demo
Concepts
User Guide
Development Integration
AgentAuth
Metadata
Development Integration
Multi-tenant (beta)
Console Documentation
Multi-tenant Console
Tenant Console
Saas Application Demo
Old version
  • Single Page Web Application

  • Mobile and Client Applications

    • Android

      • Quick Start
      • Hosted Pages
      • Components

      • APIs

      • Social Login

        • 微信登录
        • 企业微信登录
        • 支付宝登录
        • 飞书登录
        • 手机号一键登录
      • Typical Scenarios

      • Private Deployment
      • Version History
    • C#

    • Flutter

    • iOS

    • React Native
  • Standard Web Application

  • Framework Integration

  • Others

  1. Development Integration
  2. /
  3. Mobile and Client Applications
  4. /
  5. Android
  6. /
  7. Social Login
  8. /
  9. 手机号一键登录

¶ 手机号一键登录

Update time: 2025-07-23 07:34:21
Edit

集成手机号一键登录需要三个主要步骤:

  • 在网易易盾开放平台进行配置
  • 在 GenAuth 管理控制台进行配置
  • 集成 Android SDK

STEP1 和 STEP2 请参考:

手机号一键登录配置

¶ STEP3:集成 Android SDK 步骤

  1. 添加依赖
implementation 'cn.authing:guard:+'
implementation 'io.github.yidun:quicklogin:3.1.1'

Guard 只是 compileOnly 依赖飞书,这样可以让 App 按需引入,防止 Guard aar 包随着支持的第三方登录增加而越来越大。所以每增加一个第三方身份源,都需要 App 手动加上该身份源的依赖

  1. 在应用启动时初始化 GenAuth
// context is application or initial activity
// ”your_GEN_AUTH_APP_ID“ is obtained from the GenAuth console
GenAuth.init(context, "your_GEN_AUTH_APP_ID");

通过以上 3 步即可简单快速的通过 GenAuth 管理控制台配置后自动拥有一键登录功能,登录入口会在 Guard 内置登录界面的社会化登录按钮列表中体现

  • 接下来,如果使用我们提供的一键登录按钮,则在布局文件里面加上(或者代码初始化添加)
 <cn.authing.guard.oneclick.OneClickAuthButton
    android:id="@+id/btn_one_click_login"
    android:background="@drawable/authing_button_background"
    android:textColor="@color/white"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

认证结果的返回方式为 Guard 标准返回方式,参考 这里。也就是说,如果之前已经实现了基础的登录界面,添加“手机号一键登录”能力就只需要放置一个语义化的按钮。

然后在 java 代码里面处理事件

OneClickAuthButton button = findViewById(R.id.btn_one_click_login);
button.setOnLoginListener((ok, data) -> {
    if (ok) {
        // 登录成功,data 是用户信息
    } else {
        // 登录失败
    }
});
  • 如果不想使用我们内置的按钮,则可以在自己按钮的点击事件里面调用 GenAuth 一键登录登录 API:
new oneClick(this).start("your_yidun_business_id", null, ((code, message, userInfo) -> {
    if (code == 200) {
        // userInfo:用户信息
    }
}));
  • 若需要自定义 UI,首先参考 易盾文档 (opens new window) 生成 UnifyUiConfig 对象,然后调用:
UnifyUiConfig config = new UnifyUiConfig.Builder()
                 // build your config here
                .build(this);
new OneClick(this).start("your_yidun_business_id", config, ((code, message, userInfo) -> {
    if (code == 200) {
        // userInfo:用户信息
    }
}));
  • 若想基于易盾自己实现一键登录流程,在拿到 token 和 access token 后,可以调用:
public static void loginByOneAuth(String token, String accessToken, @NotNull AuthCallback<UserInfo> callback)

参数

  • token 运营商返回
  • accessToken 运营商返回

示例

AuthClient.loginByOneAuth(token, accessToken, (code, message, userInfo)->{
    if (code == 200) {
        // userInfo:用户信息
    }
});
Previous article: 飞书登录 Next article: Typical Scenarios
  • STEP3:集成 Android SDK 步骤

User identity management

Integrated third-party login
Customized authentication process

Enterprise internal management

Single sign-on
Multi-factor authentication
Permission management

Developer

Development Documentation
GitHub (opens new window)

Company

official@genauth.ai
16th Floor, Building B, Beichen Century Center, Chaoyang District, Beijing (Total)
Room 406, 4th Floor, Block B, No. 200, Tianfu Fifth Street, High-tech Zone, Chengdu (Branch)

© Beijing Steamory Technology Co., Ltd.