fix(plugin-dingtalk, plugin-wechat-auth, plugin-work-wechat): oauth redirect url (#1526)

Reviewed-on: daoyoucloud/tachybase#1526
Co-authored-by: TomyJan <TomyJan6@gmail.com>
Co-committed-by: TomyJan <TomyJan6@gmail.com>
This commit is contained in:
TomyJan 2024-09-11 13:29:38 +08:00 committed by TomyJan
parent 3a6c098899
commit d0bd4a9f92
3 changed files with 11 additions and 4 deletions

View File

@ -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;

View File

@ -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']}`),

View File

@ -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']}`),