小编jul*_*sti的帖子

PassportJs。调用passport.authenticate('facebook')后如何在不重定向用户的情况下获得facebook重定向uri

我有一个 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)

rest node.js angularjs restify passport.js

5
推荐指数
1
解决办法
1548
查看次数

标签 统计

angularjs ×1

node.js ×1

passport.js ×1

rest ×1

restify ×1