简体   繁体   English

如何使用 postman 请求受 devise 保护的 API?

[英]How to use postman to request an API that is protected with devise?

I have a rails app using devise, in the beggining it was just using rails.我有一个使用 devise 的 rails 应用程序,起初它只是使用 rails。 Now i am adding some react using the gem react-rails.. To make the story short i have an API controller like this现在我正在使用 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 ....

and i want to access that info or test my API using POSTMAN.. Of course when i try the app just redirect me to the login page because of the "before_action:authenticate_user.".: Now the question is?我想访问该信息或使用 POSTMAN 测试我的 API .. 当然,当我尝试应用程序时,只需将我重定向到登录页面,因为“before_action:authenticate_user.”。:现在问题是? Can i access to that API URL using postman?我可以使用 postman 访问该 API URL 吗? how?如何?

Thanks in advance提前致谢

This isn't related to devise mainly.这主要与devise

You'll need to generate an auth_token for each user (and of course, create a db migration for it with uniqueness) and authenticate your user using Authorization header.您需要为每个user生成一个auth_token (当然,为它创建一个具有唯一性的数据库迁移)并使用Authorization header 对您的用户进行身份验证。

Otherwise, you can check the devise tokens solutions from here: https://github.com/plataformatec/devise/wiki/How-To:-Simple-Token-Authentication-Example否则,您可以从此处查看devise令牌解决方案: https://github.com/plataformatec/devise/wiki/How-To:-Simple-Token-Authentication-Example

could you use any of these two gems are interesting to work with devise and a verification token你能用这两个宝石中的任何一个来使用 devise 和一个验证令牌吗?

devise_token_auth documentation devise_token_auth文档

devise-jwt documentation设计-jwt文档

Plain simple solution is to copy the browser session cookie (after logging in) into insomnia cookie.简单的解决方案是将浏览器 session cookie(登录后)复制到失眠 cookie 中。 Look for cookie value in browser dev tools, it needs to be copied into insomnia cookie value for the same page.在浏览器开发工具中查找 cookie 值,需要将其复制到同一页面的 insomnia cookie 值中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM