mirror of
https://github.com/woodchen-ink/Q58Connect.git
synced 2025-07-18 05:51:55 +08:00
feat: Conditionally set OAuth return URL based on OAuth state
This commit is contained in:
parent
4fe8f1cb11
commit
3b6117dc61
@ -11,7 +11,13 @@ const clientSecret = process.env.DISCOURSE_SECRET as string;
|
|||||||
|
|
||||||
export async function POST(_req: Request) {
|
export async function POST(_req: Request) {
|
||||||
const nonce = WordArray.random(16).toString();
|
const nonce = WordArray.random(16).toString();
|
||||||
const return_url = `${hostUrl}/authorize`;
|
|
||||||
|
// 检查是否存在 OAuth 状态
|
||||||
|
const oauthState = cookies().get("oauth_state");
|
||||||
|
const return_url = oauthState
|
||||||
|
? `${hostUrl}/authorize` // 如果存在 OAuth 状态,重定向到 authorize 页面
|
||||||
|
: `${hostUrl}/dashboard`; // 否则重定向到仪表板
|
||||||
|
|
||||||
const sso = btoa(`nonce=${nonce}&return_sso_url=${return_url}`);
|
const sso = btoa(`nonce=${nonce}&return_sso_url=${return_url}`);
|
||||||
const sig = hmacSHA256(sso, clientSecret).toString(Hex);
|
const sig = hmacSHA256(sso, clientSecret).toString(Hex);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user