[英]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.