SPA 应用中的令牌认证 [英] Token authentication in SPA app
问题描述
我开始了新项目.它是学习新概念的小型应用程序(游乐场).我将使用 Ruby on Rails 和单页应用程序使用 React 创建后端 API.我陷入了身份验证.我想创建自定义的基于令牌的授权/授权.我开始关注身份验证流程:
I started new project. It is small application (playground) to learn couple new concepts. I will create backend API using Ruby on Rails and Single Page Application using React. I stuck in Authentication. I would like to create custom Token-based Authorization/Authorization. I came to following auth flow:
- 用户填写密码/登录名,并使用 Ajax 并通过安全的 HTTPS 连接发送到后台.
- 支持检查用户是否存在于数据库中.如果用户存在后端创建令牌并使用用户 ID 保存到 Redis.
- 带有令牌的后端响应给客户端应用.
- 在客户端,我会将上述令牌保存到本地存储.
- 在每次请求之前,我都会从语言环境存储中获取令牌并传递给请求标头.
- 在后端,我将从标头中获取令牌并检查 Redis 数据库中是否存在.
这个流程是否正确?我应该在客户端解密令牌还是没有必要?这个项目只是游乐场,但我想正确地做它.如果以上流程不够好,请给我一些意见.
Is this flow correct? Should I decrypt token on client side or It is not necessary? This project is only playground but I would like to do It properly. Please give me some comments if above flow isn't good enough.
推荐答案
我认为您的方法是正确的.此链接可为您提供有关基于令牌的身份验证的更多详细信息:
I think that you have the right approach. This link could give you more details about token-based authentication:
- 使用 RESTful 应用程序的令牌实施身份验证 - https://templth.wordpress.com/2015/01/05/implementing-authentication-with-tokens-for-restful-applications/
希望对你有帮助蒂埃里
这篇关于SPA 应用中的令牌认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!