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

      • Authentication
      • OIDC
      • MFA
      • Scan to login
      • Device management
      • Event subscription
    • Third-party identity source

    • 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. APIs
  6. /
  7. OIDC

¶ OIDC API

Update Time: 2026-03-25 09:13:34
Edit

¶ build login URL

Use this API to generate login url, then pass this url to Webview

public static String buildAuthorizeUrl(Config config, AuthRequest authRequest)

Parameter

  • config application configuration, obtained by Authing.getPublicConfig
  • authRequest auth request object

example

AuthRequest authRequest = new AuthRequest();

Authing.getPublicConfig(config -> {
    String url = OIDCClient.buildAuthorizeUrl(config, authRequest);
    myWebView.loadUrl(url);
});

set scope

use this API to set OIDC scope. Default scope is: openid profile email phone username address offline_access role extended_fields

authRequest.setScope(String scope)

set redirect url

SDK will get the default redirect url from console. Use this API if you want to use a specific redirect url.

authRequest.setRedirectURL(String redirectURL)

¶ get token by auth code

This API returns token(s) by auth code. Note that in order to return refresh token make sure the scope includes offline_access, which is included by default.

public static void authByCode(String code, AuthRequest authRequest, @NotNull AuthCallback<UserInfo> callback)

Parameter

  • code OIDC auth code
  • authRequest auth request object

example

myWebView.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
        String url = request.getUrl().toString();
        if (url.startsWith(authRequest.getRedirectURL())) {
            try {
                String authCode = Util.getAuthCode(url);
                if (authCode != null) {
                    OIDCClient.authByCode(authCode, authRequest, (code, message, userInfo) -> {
                        // got user info
                    });
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return true;
        }
        return false;
    }
});

¶ Get user info

Get detailed user info by access token. The returned UserInfo object is the same as the UserInfo object in parameter.

public static void getUserInfoByAccessToken(UserInfo userInfo, @NotNull AuthCallback<UserInfo> callback)

Parameter

  • userInfo includes access token
  • callback returns detailed user info if succeeds

example

OIDCClient.getUserInfoByAccessToken(userInfo, (code, message, data)->{
    if (code == 200) {
        // data is the same object as the first parameter
    }
});

¶ Obtain new access token and id token by refresh token

the valid duration of an access token is usually short. After it expires, instead of pop up login dialog, which is not very user friendly, we should use refresh token to get new access token. Only show login page when refresh token is expired.

public static void getNewAccessTokenByRefreshToken(String refreshToken, @NotNull AuthCallback<UserInfo> callback)

Parameter

  • refreshToken refresh token
  • callback includes new access token and id token

example

OIDCClient.getNewAccessTokenByRefreshToken(rt, (code, message, data)->{
    if (code == 200) {
        Log.d(TAG, "new at:" + data.getAccessToken());
        Log.d(TAG, "new id token:" + data.getIdToken());
        Log.d(TAG, "new rt:" + data.getRefreshToken());
    }
});

Note: refresh token will also be refreshed


¶ Get Access Token、ID Token 和 Refresh Token

¶ Use email registration

Use the email registration, the mailbox is not case sensitive and the only userpool is unique. This interface does not require the user to verify the mailbox, after the user registration, the emailVerified field will be false.

public void registerByEmail(String email, String password, String context, @NotNull AuthCallback<UserInfo> callback)

Parameter

  • email email address
  • password password
  • context Request context, set here context you can get pipeline context (opens new window). This parameter can be passed to null if not required.

example

JSONObject context = new JSONObject();
context.put("userId", "userId");
new OIDCClient().registerByEmail("test@example.com", "xxxxxx", context.toString(), (code, message, userInfo)->{
    if (code == 200) {
        // userInfo
    }
});

Error Code

  • 2003 Illegal email address
  • 2026 Registered mailbox

¶ Use email code registration

Use the email registration, the mailbox is not case sensitive and the only userpool is unique. This interface does not require the user to verify the mailbox, after the user registration, the emailVerified field will be false. You need to use it first sendEmail sends a email verification code.(scene is VERIFY_CODE).

public void registerByEmailCode(String email, String vCode, String context, @NotNull AuthCallback<UserInfo> callback)

Parameter

  • email email address
  • vCode code
  • context Request context, set here context you can get pipeline context (opens new window). This parameter can be passed to null if not required.

example

JSONObject context = new JSONObject();
context.put("userId", "userId");
new OIDCClient().registerByEmailCode("test@example.com", "1234", context.toString(), (code, message, userInfo)->{
    if (code == 200) {
        // userInfo
    }
});

Error Code

  • 2003 Illegal email address
  • 2026 Registered mailbox

¶ Use mobile phone number registration

Use your mobile phone number to register, you can set the initial password of the account at the same time. You can pass sendSmsCode method sends SMS verification code.

public void registerByPhoneCode(String phoneCountryCode, String phone, String code, String password, String context, @NotNull AuthCallback<UserInfo> callback)

Parameter

  • phoneCountryCode Telephone country code, If null, the default value is +86.
  • phone The phone number
  • code SMS verification code
  • password initial password, it can be null
  • context Request context, set here context you can get pipeline context (opens new window). This parameter can be passed to null if not required.

example

JSONObject context = new JSONObject();
context.put("userId", "userId");
new OIDCClient().registerByPhoneCode("+86", "188xxxx8888", "1234", "strong", false, context.toString(), (code, message, userInfo)->{
    if (code == 200) {
        // userInfo
    }
});

Error Code

  • 2001 SMS verification code error
  • 2026 Cell phone number registered

¶ Custom field registration

You can directly log in to an account registered with a user-defined field using the account password.

public static void registerByExtendField(String fieldName, String account, String password, String context, @NotNull AuthCallback<UserInfo> callback)

Parameter

  • fieldName custom field name
  • account account
  • password initial password, it can be null
  • context Request context, set here context you can get pipeline context (opens new window). This parameter can be passed to null if not required.

Example

JSONObject context = new JSONObject();
context.put("userId", "userId");
new OIDCClient().registerByExtendField("extendId", "188xxxx8888", "xxxxxx", context.toString(), (code, message, userInfo)->{
    if (code == 200) {
        // userInfo
    }
});

Error Code

  • 2026 The user name already exists

¶ Use the username to login

public void loginByAccount(String account, String password, boolean autoRegister, String context, @NotNull AuthCallback<UserInfo> callback)

Parameter

  • account The phone number / email address / username
  • password password
  • autoRegister Whether it is automatically registered. If the user does not exist, an account is automatically created according to the login book.
  • context Request context, set here context you can get pipeline context (opens new window). This parameter can be passed to null if not required.

Example

JSONObject context = new JSONObject();
context.put("userId", "userId");
new OIDCClient().loginByAccount("account", "xxxxxx", false, context.toString(), (code, message, userInfo)->{
    if (code == 200) {
        // userInfo
    }
});

Error Code

  • 2333 The account or password is incorrect

¶ Use email code to login

Use the email verification code to log in. You need to use it first sendEmail sends a email verification code.(scene isVERIFY_CODE)。

public void loginByEmailCode(String email, String vCode, boolean autoRegister, String context, @NotNull AuthCallback<UserInfo> callback)

Parameter

  • email email address
  • vCode code
  • autoRegister Whether it is automatically registered. If the user does not exist, an account is automatically created according to the login book.
  • context Request context, set here context you can get pipeline context (opens new window). This parameter can be passed to null if not required.

Example

JSONObject context = new JSONObject();
context.put("userId", "userId");
new OIDCClient().loginByEmailCode("test@example.com", "1234", false, context.toString(), (code, message, userInfo)->{
    if (code == 200) {
        // userInfo
    }
});

Error Code

  • 2001 email verification code error

¶ Use the mobile phone number verification code to login

Use the mobile phone number verification code to log in. You need to use it first sendSmsCode sends a SMS verification code.

public void loginByPhoneCode(String phoneCountryCode, String phone, String code, boolean autoRegister, String context, @NotNull AuthCallback<UserInfo> callback)

Parameter

  • phoneCountryCode Telephone country code, If null, the default value is +86
  • phone The phone number
  • code SMS verification code
  • autoRegister Whether it is automatically registered. If the user does not exist, an account is automatically created according to the login book.
  • context Request context, set here context you can get pipeline context (opens new window). This parameter can be passed to null if not required.

Example

JSONObject context = new JSONObject();
context.put("userId", "userId");
new OIDCClient().loginByPhoneCode("+86", "188xxxx8888", "1234", false, context.toString(), (code, message, userInfo)->{
    if (code == 200) {
        // userInfo
    }
});

Error Code

  • 2001 SMS verification code error

Prev: Authentication Next: MFA
  • build login URL
  • get token by auth code
  • Get user info
  • Obtain new access token and id token by refresh token
  • Get Access Token、ID Token 和 Refresh Token
  • Custom field registration

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.