Express vue js axios打开新窗口并观察回调
我的目标是调用我的ExpressJS后端,它将打开一个用于openid身份验证的窗口。在我成功认证之后。我想关闭该窗口并从vue js应用程序中查看回调 这就是我到目前为止所做的。我想要的只是前端的jwt令牌,而不仅仅是后端 这是我的vuex存储功能:Express vue js axios打开新窗口并观察回调,express,vue.js,axios,vuex,steam-web-api,Express,Vue.js,Axios,Vuex,Steam Web Api,我的目标是调用我的ExpressJS后端,它将打开一个用于openid身份验证的窗口。在我成功认证之后。我想关闭该窗口并从vue js应用程序中查看回调 这就是我到目前为止所做的。我想要的只是前端的jwt令牌,而不仅仅是后端 这是我的vuex存储功能: login({ commit } = {}) { var loginWindow = window.open('http://localhost:3000/auth/steam', '_blank', 'width=800, height=60
login({ commit } = {}) {
var loginWindow = window.open('http://localhost:3000/auth/steam', '_blank', 'width=800, height=600');
if (window.focus) {
loginWindow.focus();
}
// return axios.get('http://localhost:3000/auth/steam', { crossdomain: true }).then((authResponse) => {
// console.log(authResponse)
// return;
// }).catch((error) => {
// console.log(error)
// return null;
// });
},
这是我的exprss js函数:
app.get('/auth/steam', passport.authenticate('steam', { failureRedirect: '/' }), (req, res) => {
res.redirect('/');
});
app.get('/auth/steam/return', passport.authenticate('steam', { failureRedirect: '/' }), (req, res) => {
let token = jwt.sign({ user: req.user }, 'secret', { expiresIn: '2h' });
console.log(jwt.decode(token));
res.send(`
<script>
// window.opener.steamCallback({
// ok: true,
// token: '${token}'
// });
window.close();
</script>
`)
});
app.get('/auth/steam',passport.authenticate('steam',{failureRedirect:'/'}),(req,res)=>{
res.redirect('/');
});
app.get('/auth/steam/return',passport.authenticate('steam',{failureRedirect:'/'}),(req,res)=>{
让token=jwt.sign({user:req.user},'secret',{expiresIn:'2h'});
console.log(jwt.decode(token));
res.send(`
//window.opener.streamcallback({
//好的,没错,
//令牌:“${token}”
// });
window.close();
`)
});
欢迎来到StackOverflow!你对目标的解释对我来说很有意义。你遇到了吗?@kurbo,问题是我可以关闭我打开的认证窗口。但我不知道如何将该窗口中生成的令牌返回到vue前端应用程序。我认为这是注释掉的行的预期用途,从window.opener.streamcallback({
)开始,将一些数据传递到父窗口(或“opener”)中提供的函数中。