起因是我想在前后端分离项目中实现一个后端鉴权的功能 client: localhost:8000 server: localhost:7000 oauth: https://example.gitlab.com/oauth/authorize
利用egg-passport和egg-passport-oauth2插件来实现鉴权
期望结果:当没有权限时,跳转到https://example.gitlab.com/oauth/authorize 现实结果: 跳转到outh服务时会出现跨域问题,Origin为null.我有按照egg-security设置domain白名单,仍然无效。
我查到是redirect的问题,于是我在controller里使用
ctx.redirect('https://example.gitlab.com/oauth/authorize')直接进行跳转(没设置状态码),发现也会存在这样的跨域问题。
如果我设置了状态码
// controller.js
getTest() {
this.ctx.unsafeRedirect('http://localhost:8000/spartan_dashboard/miniprogram/template')
this.ctx.status = 200
}
此时可以前端来操作跳转,但是与我的想法相悖
请问我这样使用ctx.redirect是否有误?在这种前后端分离的场景应该怎么使用?