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. Douyin

¶ Login by Douyin

Update Time: 2025-02-18 09:00:47
Edit

¶ Preparatory work

Configure in Douyin open platform (opens new window) and Authing Console (opens new window),See Preparing for Douyin、Douyin document (opens new window)。

This feature was added in android guard sdk 1.5.4 version.


¶ Integrate steps

¶ Step 1:Add dependency

//gradle文件中添加:
repositories {
    maven { url 'https://artifact.bytedance.com/repository/AwemeOpenSDK' }
}

dependencies {
    implementation 'cn.authing:guard:+'
		implementation 'com.bytedance.ies.ugc.aweme:opensdk-china-external:0.1.9.6'
		implementation 'com.bytedance.ies.ugc.aweme:opensdk-common:0.1.9.6'
}

The Guard compileOnly relies on douyin sdk, which allows apps to import on demand, preventing the Guard aar package from getting bigger as more third party logins are supported. Therefore, every time a third-party identity source is added, the App needs to manually add the dependency of the identity source.

¶ Step 2:Initialization

To initialize Guard Android SDK when the application starts:

// context is application or initial activity
// ”AUTHING_APP_ID“ is obtained from the Authing console
Authing.init(context, "AUTHING_APP_ID");
Authing.setAuthProtocol(Authing.AuthProtocol.EOIDC)

¶ Step 3:Create DouYinEntryActivity

  1. Create a new ddauth folder in the directory corresponding to the package name and add DouYinEntryActivity. Suppose your package name is com.example.myapp and its contents only need to inherit from our implementation class:
package com.example.myapp.douyinapi;

import cn.authing.guard.social.callback.douyinapi.DouYinCallBackActivity;

public class DouYinEntryActivity extends DouYinCallBackActivity {
}
  1. Add a declaration to the project AndroidManifest.xml:

    <activity
      android:name=".douyinapi.DouYinEntryActivity"
      android:launchMode="singleTask"
      android:taskAffinity="you appliation packge name"
      android:exported="true">
    </activity>
    

¶ Step 4:Use in different scenarios

  • ¶ Use in different scenarios

    Start the managed page where login authentication is required:

// this is the activity context
AuthFlow.start(this);

By following the preceding steps, you can quickly and easily configure the Authing management console to automatically have the Douyin login function. The login entry is displayed in the social login button list on the built-in login interface of the Guard.

  • ¶ Use the Douyin sign In button

    If you use the Douyin login button we provide.

​ 1. Add the following code to the layout file:

 <cn.authing.guard.social.view.DouyinLoginButton
    android:id="@+id/btn_login"
    android:background="@drawable/authing_button_background"
    android:textColor="@color/white"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

​ 2. Then handle the event in the code:

DouyinLoginButton button = findViewById(R.id.btn_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
      	}
    }
});
  • ¶ Log in to the authorization class using Douyin

    If you don't want to use our built-in buttons and want to implement the UI entirely yourself, you can call the Douyin class authorization function inside the button click event, which integrates the business logic to pull up the Douyin authorization login:

Douyin.getInstance().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
      	}
    }
});

​ data contains idToken and user information (user name, nickname, name, etc.).

  • ¶ Log in to the API using Douyin

    If you want to fully implement the Douyin login UI and obtain the authorization code logic yourself, after obtaining the authorization code, you can call the following API in exchange for user information:

public static void loginByDouYin(String accessToken, @NotNull AuthCallback<UserInfo> callback)

param

authCode Douyin authCode

example

If you only need to get the user information (username, nickname, name, etc.) and idToken, call:

AuthClient.loginByDouYin(accessToken, 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 only need to get the user information (username, nickname, name, etc.) and idToken、accessToken 和 refreshToken,call:

OIDCClient oidcClient = new OIDCClient();
oidcClient.loginByDouYin(accessToken, 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: GitLab Next: Kuaishou
  • Preparatory work
  • Integrate steps

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.