feishu-auth
Authenticates users with a Feishu (Lark) account through OAuth.
feishu-authPriority 2420What it does
feishu-auth lets staff sign in with their Feishu (Lark) account before their browser reaches the route's backend. The people live in Feishu, not on a consumer, and the gateway asks Feishu about them as the app under App ID and App secret. The Redirect URI is Feishu's own sign-in address, not an address of the gateway.
A browser without a session is answered 302 and sent to that sign-in address. Feishu sends it back with a code to a path the route serves, read from the query parameter under Code query or the header under Code header. Authentication explains callers who sign in at an identity provider.
When to use it
- Staff already sign in to Feishu at work, and an internal web application behind the gateway should accept the same account.
- A backend that has no sign-in of its own should be reached only by people who signed in with Feishu first.
- The backend needs to know who signed in, and reads the user's details from the header Set userinfo header adds.
Not for staff accounts kept in DingTalk — see dingtalk-auth (Authenticates users with a DingTalk account through OAuth), an OpenID Connect provider or bearer tokens on API calls — see openid-connect (Authenticates users against an OpenID Connect provider) or an API key a program sends on every call — see key-auth (Authenticates consumers with an API key sent in a header or query parameter).
Set it up
Let staff sign in with their Feishu account before they reach the service
A visitor without a session is sent to this address, Feishu's own sign-in page, which sends the browser back with the code to a path this route serves.
Under Basics set App ID to cli_a1b2c3d4e5f6, set App secret to <secret>, set Redirect URI to https://open.feishu.cn/open-apis/authen/v1/authorize?app_id=cli_a1b2c3d4e5f6&redirect_uri=https%3A%2F%2Fapi.example.com%2Forders, set Auth redirect URI to https://api.example.com/orders and set Secret to <secret>. Under Behavior set Cookie expires in to 28800 seconds.
{
"app_id": "cli_a1b2c3d4e5f6",
"app_secret": "<secret>",
"secret": "<secret>",
"auth_redirect_uri": "https://api.example.com/orders",
"redirect_uri": "https://open.feishu.cn/open-apis/authen/v1/authorize?app_id=cli_a1b2c3d4e5f6&redirect_uri=https%3A%2F%2Fapi.example.com%2Forders",
"cookie_expires_in": 28800
}
Things to know
- Redirect URI — A browser without a session is answered
302with this address as itsLocation, followed by a&state=the gateway adds. - Redirect URI — A request without an authorization code is redirected here, so write the provider's sign-in address. It never reaches the upstream.
- Auth redirect URI — Nothing is redirected here: this address only travels to the token endpoint, as the redirect the authorization code was issued for.
- Cookie expires in — Stored at zero, the session it opens has no lifetime limit at all and is closed only by its idling timeout.
- Secret — A secret shorter than
8characters is refused when you save. - Secret fallbacks — Each older secret follows the same lengths, and one longer than
32characters is refused when you save. - AdviceWhen you replace the Secret, keep the old one under Secret fallbacks until the sessions it signed have run out.
- On a consumer or a consumer group it runs only after the consumer has been identified by a credential; it does not identify the consumer itself.
Settings
The fields as the console shows them, section by section.
Basics
app_idstringRequiredapp_secretstringRequiredStored on the engine and shown only to roles that manage this object.
redirect_uristringRequiredauth_redirect_uristringRequiredThe redirect address registered in your Feishu app. It is sent with the code when the code is exchanged for a token.
secretstringRequiredThe secret the session keys are derived from: a random value, the same on every node. Stored on the engine and shown only to roles that manage this object.
Behavior
set_userinfo_headerbooleandefault trueAdds the signed-in user's details to the request as a header for the upstream.
cookie_expires_inintegerdefault 86400How long the authorization cookie stays valid after it was created.
code_headerstringdefault X-Feishu-CodeThe request header the authorization code is read from.
code_querystringdefault codeThe query parameter the authorization code is read from.
timeoutintegerdefault 6000ssl_verifybooleandefault trueAdvanced
access_token_urlstringdefault https://open.feishu.cn/open-apis/authen/v2/oauth/tokenuserinfo_urlstringdefault https://open.feishu.cn/open-apis/authen/v1/user_infosecret_fallbacksarray of stringsOlder secrets a cookie may still be signed with while a new one rolls out. Stored on the engine and shown only to roles that manage this object.