Skip to main content
When an app needs to call DingTalk OpenAPI on behalf of a signed-in user to operate on resources, follow the procedure in this topic to obtain the access credential for calling APIs.
The process for internal apps and third-party enterprise apps is similar. This topic uses an internal app as an example.

Step 1: Create an app

  1. Sign in to the DingTalk Developer Platform.
  2. Open the details page of the app you have created. On the Basic Information page, view the app’s SuiteKey/SuiteSecret (Third-party enterprise app) or AppKey/AppSecret (Internal app).
  3. On the app details page, click Development Configuration > Security Settings, and enter the redirect URI (callback domain).
    The redirect URI is the address you expect to be redirected to after sign-in authorization.

Step 2: OAuth sign-in authorization

To use DingTalk OpenAPI to read and write resources on behalf of a user, complete authorization through the OAuth 2.0 authorization flow. The OAuth 2.0 authorization flow is illustrated below.

Use the sign-in authorization page provided by DingTalk

Construct the sign-in authorization page. The page parameters are as follows:

Important

  • For readability, line breaks are added to the following parameter example. Line breaks are not required in actual use.
  • Parameter values must be URL-encoded. The following example has already been URL-encoded.
On success, redirects to: https://www.aaaaa.com/a/b?authCode=xxxx&state=dddd On failure, redirects to: https://www.aaaaa.com/a/b?error=yyyyyy&state=dddd

Embedded QR Code sign-in authorization

The page that embeds the QR Code must be “same-origin” with the page specified by the redirect_uri parameter. Otherwise, scanning the QR Code will have no effect. “Same-origin” means the same protocol, same second-level or third-level domain, same port number, and so on. For details, see Same-origin policy.
  1. Include the DingTalk Scan QR Code sign-in JSSDK in the page.
  2. Call the following method where the Scan QR Code sign-in is required.
    Parameter description (in TypeScript):

Step 3: Obtain the access credential

Use the returned auth_code and the app information to call the Get user token API to obtain the access_token. Sample code:

Step 4: Call APIs with the access credential

After obtaining the access_token, you can use this credential to call the Get user contact profile API.