如何在没有会话的情况下集成passport facebook和jwt?

如何在没有会话的情况下集成passport facebook和jwt?,jwt,passport.js,passport-facebook,express-jwt,Jwt,Passport.js,Passport Facebook,Express Jwt,我想使用passport github或facebook登录jwt令牌,而不使用服务器上的保存会话。 但我们有两个来自前端的请求: app.get('/auth/facebook', passport.authenticate('facebook')); app.get('/auth/facebook/callback', passport.authenticate('facebook', { failureRedirect: '/login' }), function(req,

我想使用passport github或facebook登录jwt令牌,而不使用服务器上的保存会话。 但我们有两个来自前端的请求:

app.get('/auth/facebook',
  passport.authenticate('facebook'));

app.get('/auth/facebook/callback',
  passport.authenticate('facebook', { failureRedirect: '/login' }),
  function(req, res) {
    // Successful authentication, redirect home.
    res.redirect('/');
  });
如何处理前端代码

在正常情况下,我们只有一个请求

axios.post(`${API_URL}/auth/login`, { email, password })
.then(response => {
  cookie.save('token', response.data.token, { path: '/' });
  dispatch({ type: AUTH_USER });
  window.location.href = CLIENT_ROOT_URL + '/dashboard';
})
.catch((error) => {
  errorHandler(dispatch, error.response, AUTH_ERROR)
});
}

因此,我们可以在本地保存令牌。但是对于passport facebook,我们有两个请求(“/auth/facebook”和“/auth/facebook/callback”)。那么如何在本地保存令牌呢?

首先,我认为GET请求将不起作用。您需要使用a链接来触发/auth/login

<a href="http://localhost:5150/auth/facebook">
在客户端登录页提取jwt并将其保存到本地存储

class SocialAuthRedirect extends Component {
  componentWillMount() {
    this.props.dispatch(
      fbAuthUser(getCookie("auth"), () => {
        document.cookie =
          "auth=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
        this.props.history.push("/profile");
      })
    );
  }

  render() {
    return <div />;
  }
}
类SocialAuthRedirect扩展组件{
组件willmount(){
这是我的道具(
fbAuthUser(getCookie(“auth”),()=>{
document.cookie=
“auth=;expires=Thu,1970年1月1日00:00:00 UTC;path=/;”;
this.props.history.push(“/profile”);
})
);
}
render(){
返回;
}
}

首先,我认为GET请求不起作用。您需要使用a链接来触发/auth/login

<a href="http://localhost:5150/auth/facebook">
在客户端登录页提取jwt并将其保存到本地存储

class SocialAuthRedirect extends Component {
  componentWillMount() {
    this.props.dispatch(
      fbAuthUser(getCookie("auth"), () => {
        document.cookie =
          "auth=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
        this.props.history.push("/profile");
      })
    );
  }

  render() {
    return <div />;
  }
}
类SocialAuthRedirect扩展组件{
组件willmount(){
这是我的道具(
fbAuthUser(getCookie(“auth”),()=>{
document.cookie=
“auth=;expires=Thu,1970年1月1日00:00:00 UTC;path=/;”;
this.props.history.push(“/profile”);
})
);
}
render(){
返回;
}
}

如何向客户端发送jwt令牌?如何向客户端发送jwt令牌?