我有一个 NodeJs REST 服务,我们称之为 -后端的NodeRest和前端的 AngularJs。
NodeRest应该与移动应用程序以及 Web 应用程序一起使用,在我的情况下它是 AngularJs 应用程序。
NodeRest 的架构在使用 PassportJs 时应该解决以下问题:
服务器不应将用户重定向到 Facebook 以在何时进行授权
app.get('/auth/facebook', passport.authenticate('facebook'));
Run Code Online (Sandbox Code Playgroud)
已被调用。
如果它要重定向它,客户端将不会得到任何东西,因为回调 url 链接到NodeRest httpL//noderest/facebook/callback。相反,它应该提供重定向 uri,以便我可以将其发送回客户端(angularJs、mobile 等...)。像这样:
app.get('/auth/facebook', passport.authenticate('facebook', function(redirectUri){
//emit socket event to the client with redirect uri as a response data. }));
Run Code Online (Sandbox Code Playgroud)
我决定在授权过程中使用 socket.io 作为通信渠道。
客户:
var socket = io.connect(baseUrl);
socket.on('auth:facebook:callback:getCalled', function (data) {
// callback get called on server side.
// user has been authenicated.
// so now, user can talk with our …Run Code Online (Sandbox Code Playgroud)