Skip to main content

dingtalk-auth

dingtalk-auth

Validates a DingTalk authorization code by exchanging it — through DingTalk's OAuth API — for the calling user's identity, then attaches that identity to the request for downstream nodes. A request whose code cannot be resolved to a DingTalk user is rejected with 401.

The code is read from a request header (default X-DingTalk-Code), falling back to a query parameter (default code). The plugin fetches an app-level access token (cached in-process, ~7000s TTL) and calls DingTalk's getuserinfo endpoint with the code.

:::note Limitations — token validation only featherbit is stateless with no session store, so this plugin implements a token-validation flow: every request must carry a code, which is validated against DingTalk on each request. There is no session cookie caching the resolved userinfo between requests, and no 302 redirect when the code is absent — a missing code is simply rejected. Config keys that would only serve a session flow (secret, secret_fallbacks, redirect_uri, cookie_expires_in) are not supported. The app-level access token is cached in-process, so only the userinfo call happens per request. :::

Configuration

KeyTypeDefaultDescription
app_keystringRequired. DingTalk application key.
app_secretstringRequired. DingTalk application secret.
code_headerstringX-DingTalk-CodeHeader the authorization code is read from first (matched case-insensitively).
code_querystringcodeQuery parameter the code falls back to when the header is absent.
access_token_urlstringhttps://api.dingtalk.com/v1.0/oauth2/accessTokenDingTalk access-token endpoint.
userinfo_urlstringhttps://oapi.dingtalk.com/topapi/v2/user/getuserinfoDingTalk userinfo endpoint.
set_userinfo_headerbooleantrueBase64-encode the resolved userinfo into the X-Userinfo request header for the upstream.
timeoutinteger (ms)6000Per-callout timeout.
ssl_verifybooleantrueVerify DingTalk's TLS certificate.
- id: auth
type: dingtalk-auth
config:
app_key: ${DINGTALK_APP_KEY}
app_secret: ${DINGTALK_APP_SECRET}
code_header: X-DingTalk-Code

Behavior

The code is read from code_header, then code_query. With no code, the request is rejected. Otherwise the plugin obtains an access token (from cache or by calling access_token_url) and POSTs the code to userinfo_url; DingTalk's errcode: 0 with a result object indicates success.

Any client-supplied X-Userinfo header is stripped before authentication.

On success the context passes through the success port:

  • context.message["dingtalk_userinfo"] = the resolved DingTalk result object
  • context.message["user_id"] = userid (or unionid), when present
  • X-Userinfo request header = base64-encoded userinfo JSON (when set_userinfo_header)

On a missing code, a rejected code (errcode != 0), or a callout failure, the plugin rejects and routes through the error port:

  • context.response.status_code = 401
  • Body: {"error": "unauthorized", "message": "<reason>"} with content-type: application/json
  • Error code appended to context.errors: DINGTALK_AUTH_FAILED