使用JWT进行环回authentication
我想了解如何将自定义JWT路由安装到loopbacks安全模型中。 我的应用程序有一个涉及SMS的身份validation“跳舞”,这个身份validation会使用出色的描述来生成有效的JWT令牌。 我使用jsonwebtoken ,事情按预期工作。 在获得令牌后,我的angular.js客户端会发送带有Authorisation: JWT ..token..
标头中的每个请求的标识(发现有冲突的文档,一个说JWT,一个承载者,但是我可以弄清楚)。
现在我想在循环应用程序中使用令牌。 我想使用ACL系统环回提供的。 我读过以下资源:
- 使用JSON Web令牌validationNode.js API
- 环回,在用户login
- 第三方login(护照)
- 环回,进行authentication的请求
- 智威汤逊的护照策略
- 环回OAuth2.0源
- 环回卫星
我不清楚我的下一步是什么。 我有工作:
- 用户“login” – 生成JWT
- 用户login使用用户名/密码(将退休)
- 在环回中使用ACL实现(当我访问ACL受保护的资源时,正如我们所期望的那样,发生4xx错误)
- 我的JWT令牌正确(?)在请求的头部
我需要:
- 基于JWT令牌的angular色兼容环回ACL的有效用户
非常感谢帮助
尽pipe如此,解决scheme变得简单得多。 对于初学者,loopback会使用自己的jwt webtokens来保持(无状态)用户会话。 build立身份(在我的情况下,从我的JWT令牌提取手机号码)我只需要查找成员,并生成回送本机JWT令牌。 我的端点定义是这样的:
Member.remoteMethod( 'provideSMSToken', { accepts: [{ arg: 'mobilenumber', type: 'string', description: 'Phone number including +65 and no spaces' }, { arg: 'token', type: 'string', description: 'the token received through SMS' }], returns: { arg: 'token', type: 'string' }, description: 'provide SMS token to confirm login', http: { path: '/smsauthenticate', verb: 'post' }, isStatic: true } );
和像这样的provideSMSToken
函数:
// Exchange the SMS Token with a login token Member.provideSMSToken = function(mobilenumber, token, cb) { var app = Member.app; // CHeck if the token does exist for the given phone number // if yes, check for the respective memeber if (!app.smsVerificationToken || !app.smsVerificationToken[mobilenumber] || app.smsVerificationToken[mobilenumber] !== token) { var wrongToken = new Error("Wrong or missing token"); cb(wrongToken, "Wrong or missing token"); } else { var timetolive = 86400; Member.lookupByPhone(mobilenumber, function(err, theOne) { if (err) { cb(err, "Sorry, no such member here!"); } else { // We can provide a token now for authentication // using the default createAccessToken method theOne.createAccessToken(timetolive, function(err, accesstoken) { cb(err, accesstoken); }) } }); } }
奇迹般有效
- 未知的身份validation策略“本地”(错误护照)
- 尝试访问节点js中的req.user属性时,无法读取未定义的属性“用户名”
- 谷歌oauth不返回电子邮件通行证authentication
- 什么是passport.initialize()? (nodejs express)
- Passport Google OAuth2login前需要注销
- passport-facebook Strategy.parseErrorResponse
- React-native iOS如何获取用户Steam ID
- Node.js,express,护照authentication“Bad Request”
- 在Node.js上使用passport-ldapauth进行LDAPauthentication