SPA 应用中的令牌认证 [英] Token authentication in SPA app

查看:37
本文介绍了SPA 应用中的令牌认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始了新项目.它是学习新概念的小型应用程序(游乐场).我将使用 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:

  1. 用户填写密码/登录名,并使用 Ajax 并通过安全的 HTTPS 连接发送到后台.
  2. 支持检查用户是否存在于数据库中.如果用户存在后端创建令牌并使用用户 ID 保存到 Redis.
  3. 带有令牌的后端响应给客户端应用.
  4. 在客户端,我会将上述令牌保存到本地存储.
  5. 在每次请求之前,我都会从语言环境存储中获取令牌并传递给请求标头.
  6. 在后端,我将从标头中获取令牌并检查 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:

希望对你有帮助蒂埃里

这篇关于SPA 应用中的令牌认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆