diff --git a/packages/plugins/@tachybase/plugin-dingtalk/src/server/dingtalk-auth.ts b/packages/plugins/@tachybase/plugin-dingtalk/src/server/dingtalk-auth.ts index fb6f51165..d92d68c44 100644 --- a/packages/plugins/@tachybase/plugin-dingtalk/src/server/dingtalk-auth.ts +++ b/packages/plugins/@tachybase/plugin-dingtalk/src/server/dingtalk-auth.ts @@ -60,7 +60,10 @@ export class DingtalkAuth extends BaseAuth { async getAuthUrl(redirect) { const clientId = this.options?.dingtalk?.clientId; const app = this.ctx.app.name; - const redirectUrl = encodeURIComponent(`${this.ctx.origin}${process.env.API_BASE_PATH}dingtalk:redirect`); + const redirectUrl = encodeURIComponent( + `${this.ctx.protocol}://${this.ctx.host}${process.env.API_BASE_PATH}dingtalk:redirect`, + ); + // TODO: 如果后续有登录后绑定的场景,服务端需要校验 state const state = encodeURIComponent(`redirect=${redirect}&app=${app}&name=${this.ctx.headers['x-authenticator']}`); const url = `https://login.dingtalk.com/oauth2/auth?client_id=${clientId}&response_type=code&scope=openid&state=${state}&redirect_uri=${redirectUrl}&prompt=consent`; return url; diff --git a/packages/plugins/@tachybase/plugin-wechat-auth/src/server/wechat-auth.ts b/packages/plugins/@tachybase/plugin-wechat-auth/src/server/wechat-auth.ts index 6b78e578f..fe17c1bb9 100644 --- a/packages/plugins/@tachybase/plugin-wechat-auth/src/server/wechat-auth.ts +++ b/packages/plugins/@tachybase/plugin-wechat-auth/src/server/wechat-auth.ts @@ -56,7 +56,10 @@ export class WeChatAuth extends BaseAuth { async getAuthCfg(redirect) { const appID = this.options?.wechatAuth?.AppID; const app = this.ctx.app.name; - const redirectUrl = encodeURIComponent(`${this.ctx.host}${process.env.API_BASE_PATH}wechatAuth:redirect`); + const ctx = this.ctx; + const redirectUrl = encodeURIComponent( + `${this.ctx.protocol}://${this.ctx.host}${process.env.API_BASE_PATH}wechatAuth:redirect`, + ); // TODO: 如果后续有登录后绑定的场景,服务端需要校验 state const state = encodeURIComponent( encodeURIComponent(`redirect=${redirect}&app=${app}&name=${this.ctx.headers['x-authenticator']}`), diff --git a/packages/plugins/@tachybase/plugin-work-wechat/src/server/work-auth.ts b/packages/plugins/@tachybase/plugin-work-wechat/src/server/work-auth.ts index a0905f587..4b0b9fcfe 100644 --- a/packages/plugins/@tachybase/plugin-work-wechat/src/server/work-auth.ts +++ b/packages/plugins/@tachybase/plugin-work-wechat/src/server/work-auth.ts @@ -70,8 +70,9 @@ export class WorkAuth extends BaseAuth { const clientId = this.options?.workWeChat?.corpId; const agentId = this.options?.workWeChat?.agentId; const app = this.ctx.app.name; - // const redirectUrl = encodeURIComponent('https://hua.dev.daoyoucloud.com/api/workWeChat:redirect'); - const redirectUrl = encodeURIComponent(`${this.ctx.host}${process.env.API_BASE_PATH}workWeChat:redirect`); + const redirectUrl = encodeURIComponent( + `${this.ctx.protocol}://${this.ctx.host}${process.env.API_BASE_PATH}workWeChat:redirect`, + ); // TODO: 如果后续有登录后绑定的场景,服务端需要校验 state const state = encodeURIComponent( encodeURIComponent(`redirect=${redirect}&app=${app}&name=${this.ctx.headers['x-authenticator']}`),