mean.septenary.cn 搭建之登录逻辑梳理
1.通常登录方式都有哪些?
2.restful API 形式的 登录服务 passport-jwt
- 什么是 JWT – JSON WEB TOKEN
- OAuth 2和JWT - 如何设计安全的API
- Angular authentication revisited
- angular2-jwt-auth-example
- express-jwt-server
- 使用Json Web Token设计Passport系统
- Creating a Simple Node/Express API Authentication System with Passport and JWT
- Building a Basic RESTful API for a Chat System
jwt 如何保证在浏览器中的安全存储
- Set-Cookie (http only)
- LocalStorage: JWT 在浏览器中以加密方式存储在 localStorage 中,但 localStorage 无法防范 XSS 攻击,好在 Angular2 有”跨站脚本安全模型”, 可按照文档
服务端实现
需要用到的库
- jwt-simple (jwt encode decode)
- moment
- passport
- passport-jwt
1.验证用户名密码后,响应生成的 jwt
1 |
|
2.受限 API 的访问
route:
1 |
|
authenticate:
1 |
|
get token
1 |
|
request with token
1 |
|