[英]How to use postman to request an API that is protected with devise?
我有一个使用 devise 的 rails 应用程序,起初它只是使用 rails。 现在我正在使用 gem react-rails 添加一些反应.. 简而言之,我有一个 API controller 像这样
class Api::CustomersController < ApplicationController
skip_before_action :verify_authenticity_token
before_action :authenticate_user!
def index
customers = Customer.all
render json: customers, status: :ok
end ....
我想访问该信息或使用 POSTMAN 测试我的 API .. 当然,当我尝试应用程序时,只需将我重定向到登录页面,因为“before_action:authenticate_user.”。:现在问题是? 我可以使用 postman 访问该 API URL 吗? 如何?
提前致谢
这主要与devise
。
您需要为每个user
生成一个auth_token
(当然,为它创建一个具有唯一性的数据库迁移)并使用Authorization
header 对您的用户进行身份验证。
否则,您可以从此处查看devise
令牌解决方案: https://github.com/plataformatec/devise/wiki/How-To:-Simple-Token-Authentication-Example
简单的解决方案是将浏览器 session cookie(登录后)复制到失眠 cookie 中。 在浏览器开发工具中查找 cookie 值,需要将其复制到同一页面的 insomnia cookie 值中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.