如何从 access_token (Rails, Devise) 反向查找用户
How to reverse look up a user from an access_token (Rails, Devise)
我的 Rails 应用程序具有登录/注销功能,并在登录后返回有效的 access_token。
我正在使用这个gem
https://github.com/lynndylanhurley/devise_token_auth
但是如何在后续请求中使用这个 access_token?例如:
abc.com/action?access_token=123
我想在我的控制器和操作方法中,我应该能够从这个 access_token 中找到用户,但我不确定是否可以使用 Devise。
如果我还传入 :client 或 :uid 以及 :access_token,我可以通过执行以下操作来验证此令牌:
user = User.find_by_uid uid
user.valid_token? access_token, client
是否可以通过 his/her access_token 单独查找用户?
谢谢。
根据文档:
access-token This serves as the user's password for each request. A hashed version of this value is stored in the database for later comparison. This value should be changed on each request.
而且它似乎是使用 BCrypt 的标记化,并且每次都会更改以确保安全。
此外,它们不允许您仅从令牌中查找数据库中的用户,以解决安全漏洞。您可以选择以创造性的方式或在会话中存储 UID 以进行查找,并在 application_controller.rb
中编写一个方法,然后对该数据执行一些逻辑。
此处提到:
uid A unique value that is used to identify the user. This is necessary because searching the DB for users by their access token will make the API susceptible to timing attacks.
我的 Rails 应用程序具有登录/注销功能,并在登录后返回有效的 access_token。
我正在使用这个gem
https://github.com/lynndylanhurley/devise_token_auth
但是如何在后续请求中使用这个 access_token?例如:
abc.com/action?access_token=123
我想在我的控制器和操作方法中,我应该能够从这个 access_token 中找到用户,但我不确定是否可以使用 Devise。
如果我还传入 :client 或 :uid 以及 :access_token,我可以通过执行以下操作来验证此令牌:
user = User.find_by_uid uid
user.valid_token? access_token, client
是否可以通过 his/her access_token 单独查找用户?
谢谢。
根据文档:
access-token This serves as the user's password for each request. A hashed version of this value is stored in the database for later comparison. This value should be changed on each request.
而且它似乎是使用 BCrypt 的标记化,并且每次都会更改以确保安全。
此外,它们不允许您仅从令牌中查找数据库中的用户,以解决安全漏洞。您可以选择以创造性的方式或在会话中存储 UID 以进行查找,并在 application_controller.rb
中编写一个方法,然后对该数据执行一些逻辑。
此处提到:
uid A unique value that is used to identify the user. This is necessary because searching the DB for users by their access token will make the API susceptible to timing attacks.