如何使用邮递员请求受设计保护的API?

时间:2019-11-20 15:28:26

标签: ruby-on-rails postman

我有一个使用devise的rails应用程序,开始时只是使用rails。现在,我使用gem react-rails添加一些反应。为了简单起见,我有一个像这样的API控制器

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!”而将我重定向到登录页面。.现在的问题是:我可以吗?使用邮递员访问该API URL?怎么样?

预先感谢

2 个答案:

答案 0 :(得分:0)

这主要与filter_map无关。

您需要为每个devise生成一个auth_token(当然,还要为其创建唯一的数据库迁移),并使用user标头对用户进行身份验证。

否则,您可以从以下位置检查Authorization令牌解决方案:https://github.com/plataformatec/devise/wiki/How-To:-Simple-Token-Authentication-Example

答案 1 :(得分:0)

您能否使用这两个gem中的任何一个与devise和验证令牌一起使用都很有趣

  

devise_token_auth documentation

     

devise-jwt documentation