Expand description
DingTalk authentication plugin (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 a 401.
§Ported subset / deviations from APISIX
APISIX’s dingtalk-auth is a session plugin: on the first request it
reads a code, calls DingTalk, then stores the resolved userinfo in an
encrypted dingtalk_session cookie so later requests skip the callout, and
it 302-redirects to redirect_uri when no code and no session are present.
featherbit is stateless with no session store, so this port implements the
token-validation subset: every request must carry a code, which is
validated against DingTalk on each request. Consequently the session /
cookie / redirect machinery is dropped, along with the config keys that only
served it (secret, secret_fallbacks, redirect_uri, cookie_expires_in).
The app-level access token is cached in-process (7000s TTL, matching
APISIX’s lrucache) so only the userinfo call happens per request.
Structs§
- Dingtalk
Auth Plugin - Authenticates requests by resolving a DingTalk authorization code to a
DingTalk user via the OAuth
accessToken+getuserinfoAPIs.
Enums§
- Dingtalk
Error 🔒 - Outcome of resolving a DingTalk code into userinfo. Every failure maps to a
401(DINGTALK_AUTH_FAILED); the variants exist to keep the reason legible.
Constants§
- ACCESS_
TOKEN_ 🔒TTL - DingTalk access tokens live 7200s; cache slightly shorter to avoid using a token that expires mid-flight (matches APISIX’s cache TTL).
- DEFAULT_
TOKEN_ 🔒URL - DEFAULT_
USERINFO_ 🔒URL
Functions§
- append_
query 🔒 - Appends
key=valuetourl, choosing?or&as needed. - attach_
identity 🔒 - Copies the resolved identity into
context.messageand optionally theX-Userinforequest header. - parse_
access_ 🔒token - Parses the
accessTokenfrom DingTalk’s token-endpoint response. - parse_
userinfo 🔒 - Parses DingTalk’s
getuserinforesponse, returning theresultobject onerrcode == 0and anDingtalkError::Unauthorizedotherwise. - require_
string 🔒 - Extracts a required string config key.
- urlencode 🔒
- Minimal percent-encoding for query values (access tokens are URL-safe-ish
but may contain
+/=).