Authing DocsDocuments
Concept
workflow
Guides
Development Integration
Application integration
Concept
workflow
Guides
Development Integration
Application integration
Old Version
Development Integration
  • Single Sign-On (SSO)
  • Login component

  • JavaScript/Node.js

  • Java / Kotlin

  • Python

  • C#

  • PHP

  • Go

  • Ruby
  • Android

    • Quick start
    • Hosting page
    • APIs

    • Third-party identity source

      • Wechat
      • Alipay
      • Google
      • Facebook
      • Wechat MiniProgram
      • QQ
      • Weibo
      • Baidu
      • Linkedin
      • Github
      • Gitee
      • GitLab
      • Douyin
      • Kuaishou
      • Huawei
      • OPPO
      • Xiaomi
      • Line
      • Slack
      • Amazon
      • Wecom
      • Lark
      • DingTalk
    • Scenario

    • On-premise
    • Android Guard Change log
    • Error code
  • iOS

  • Flutter

  • React Native
  • WeChat Mini Program
  • WeChat webpage authorization
  • Framework Integration
  • Error code
  1. Development Integration
  2. /
  3. Android
  4. /
  5. Third-party identity source
  6. /
  7. Alipay

¶ Login by Alipay

Update Time: 2025-02-18 09:00:47
Edit
  1. Go to this page to download Alipay Android SDK (opens new window)

Alipay put Android、iOS SDK, as well as Demo into one single folder. Locate Android SDK inside this folder and copy it to app's libs folder.

  1. Add dependency:
implementation 'cn.authing:guard:+'
implementation files('libs/alipaysdk.aar')
  1. Init Authing upon App startup. e.g. Application's onCreate:
// AUTHING_APP_ID is Authing app id which can be obtained at Authing console
Authing.init(context, “AUTHING_APP_ID”);
Authing.setAuthProtocol(Authing.AuthProtocol.EOIDC)

Next, we recommend to use our UI component, all you need to do is 'place' it on the layout xml where you think appropriate, you can also create an instance of this component via code:

<cn.authing.guard.social.view.AlipayLoginButton
    android:id="@+id/btn_alipay_login"
    android:layout_width="44dp"
    android:layout_height="44dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"/>

Then handle callback event after login:

AlipayLoginButton button = findViewById(R.id.btn_alipay_login);
button.setOnLoginListener(new AuthCallback<UserInfo>() {
    @Override
    public void call(int code, String message, UserInfo data) {
      	if (code == 200) {
        	// login success, data is user info.
       	} else {
        	// login fail
      	}
    }
});

In case you don't want to use our UI component, you can have your own Button, and then inside your Button's onClick event, you can start alipay authentication and handle callback event like this:

Alipay alipay = new Alipy();
alipay.login(appContext, new AuthCallback<UserInfo>() {
    @Override
    public void call(int code, String message, UserInfo data) {
        if (code == 200) {
          // login success, data is user info.
        } else {
          // login fail
        }
    }
});

userInfo contains idToken and user information (username, nickname, name, etc.).


If you want to implement the whole process by your own, right after you get auth code, please call this API to get Authing user info:

public static void loginByAlipay(String authCode, @NotNull AuthCallback<UserInfo> callback)

param

authCode auth code from alipay

example

If all you need is access to user information (username, nickname, name, etc.) and idToken,call like this:

AuthClient.loginByAlipay(authCode, new AuthCallback<UserInfo>() {
    @Override
    public void call(int code, String message, UserInfo data) {
        if (code == 200) {
          // login success, data is user info, contains idToken.
        } else {
          // login fail
        }
    }
});

If you need to get user information (username, nickname, name, etc.) , idToken, accessToken and refreshToken, call like this:

OIDCClient oidcClient = new OIDCClient();
oidcClient.loginByAlipay(authCode, new AuthCallback<UserInfo>() {
    @Override
    public void call(int code, String message, UserInfo data) {
        if (code == 200) {
          // ogin success, data is user info, contains idToken、accessToken and refreshToken.
        } else {
          // login fail
        }
    }
});
Prev: Wechat Next: Google

User identity management

Integrated third-party login
Mobile phone number flash check (opens new window)
Universal login form component
Custom authentication process

Enterprise internal management

Single Sign On
Multi-factor Authentication
Authority Management

Developers

Development Document
Framework Integration
Blog (opens new window)
GitHub (opens new window)
Community User Center (opens new window)

Company

400 888 2106
sales@authing.cn
16 / F, Block B, NORTH STAR CENTURY CENTER, Beijing(Total)
room 406, 4th floor, zone B, building 1, No. 200, Tianfu Fifth Street, Chengdu(branch)

Beijing ICP No.19051205-1

© Beijing Steamory Technology Co.