我正在REST
使用api NodeJS
.对于身份验证我决定使用Passport
.我想要真正的RESTful api.所以这意味着我必须使用令牌而不是会话.
我想让用户使用用户名和密码登录,或者使用Facebook,Google和Twitter等社交网络.
我创建自己的OAuth2.0
服务器来发布Access
和Refresh 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
我使用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中执行此操作?请提供一些初步指导/意见,我会在此之后弄清楚细节并用细化的细节改进问题.
正如我个人所见,Trello非常准确地显示了在线/离线/闲置状态的信息.有几种解决方案可以跟踪用户的在线状态,准确地说这需要一个严重的开销.还存在不知道用户是否关闭浏览器,断开连接等导致显示离线/空闲状态不准确的传统问题.对于没有聊天功能的平台(我相信,这会占用跟踪用户状态的开销,从而使任务最终变得容易)Trello如何实现这一目标,虽然没有太大的开销?
此外,Trello能够检测到断开连接并恢复连接(尽管不是很顺利).
这里描述了Trello的推送和轮询层
access-token ×1
apache ×1
backbone.js ×1
coffeescript ×1
express ×1
http-headers ×1
node.js ×1
passport.js ×1
trello ×1