小编Ank*_*rob的帖子

使用Passport和OAuth2 +社交网络进行NodeJS REST身份验证

我正在REST使用api NodeJS.对于身份验证我决定使用Passport.我想要真正的RESTful api.所以这意味着我必须使用令牌而不是会话.

我想让用户使用用户名和密码登录,或者使用Facebook,Google和Twitter等社交网络.

我创建自己的OAuth2.0服务器来发布AccessRefresh tokens使用oauth2orize模块.所以现在我可以注册新用户,然后发出令牌.我按照本教程:

http://aleksandrov.ws/2013/09/12/restful-api-with-nodejs-plus-mongodb/

验证用户的路由:

// api ------------------------------------------------------------------------------------
    app.get('/api/userInfo',
        passport.authenticate('bearer', { session: false }),
        function(req, res) {
            // req.authInfo is set using the `info` argument supplied by
            // `BearerStrategy`.  It is typically used to indicate scope of the token,
            // and used in access control checks.  For illustrative purposes, this
            // example simply returns the scope in the response.
            res.json({ user_id: req.user.userId, name: req.user.username, …
Run Code Online (Sandbox Code Playgroud)

node.js access-token express facebook-access-token passport.js

21
推荐指数
1
解决办法
9298
查看次数

处理Apache中的CORS预检请求

我使用Yeoman部署了一个AngularJS应用程序.Cakephp RESTful后端.

Angular应用程序发送OPTIONS预检请求,后端响应禁止(403),在nginx中解决了我使用过的这个问题:

if ($request_method = 'OPTIONS') {
     add_header 'Access-Control-Allow-Origin' '*'; 
     add_header 'Access-Control-Allow-Credentials' 'true';
     add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE'; 
     add_header 'Access-Control-Allow-Headers' 'X-AuthTokenHeader,Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,X-Requested-With,If-Modified-Since';   
     add_header 'Access-Control-Max-Age' 1728000;
     add_header 'Content-Type' 'text/plain charset=UTF-8';
     add_header 'Content-Length' 0;
     return 204; 
}
Run Code Online (Sandbox Code Playgroud)

我如何在Apache中执行此操作?请提供一些初步指导/意见,我会在此之后弄清楚细节并用细化的细节改进问题.

apache http-headers

6
推荐指数
2
解决办法
1万
查看次数

Trello如何准确地向用户显示在线/离线/空闲状态?

正如我个人所见,Trello非常准确地显示了在线/离线/闲置状态的信息.有几种解决方案可以跟踪用户的在线状态,准确地说这需要一个严重的开销.还存在不知道用户是否关闭浏览器,断开连接等导致显示离线/空闲状态不准确的传统问题.对于没有聊天功能的平台(我相信,这会占用跟踪用户状态的开销,从而使任务最终变得容易)Trello如何实现这一目标,虽然没有太大的开销?

此外,Trello能够检测到断开连接并恢复连接(尽管不是很顺利).

这里描述了Trello的推送和轮询层

coffeescript backbone.js trello

4
推荐指数
1
解决办法
1003
查看次数