如何在Karate API中实现Bearer Token授权类型?

问题描述 投票:0回答:1

我是空手道新手,想尝试一下。我当前正在开发的 Web 应用程序端点几乎包含所有需要身份验证的端点。

如何在 Karate 中设置 Bearer Token 身份验证类型? 我正在计划使用 VS Code。

在Postman中,我们这样设置: Postman variables

Authentication Type

Pre-request Script

karate bearer-token
1个回答
0
投票

请根据您的API请求进行更改:

Feature: Bearer Token Authentication Feature

  Background: Hitting the api that will generate token
    * url 'https://airportgap.com/api/tokens'
    * request {"email": "[email protected]","password": "password"}
    * method post
    * print 'response is:', response
    * def token = response.token
    * header Authorization = 'Bearer ' + token

  Scenario: Bearer Token Authentication Scenario
    Given url 'https://airportgap.com/api/favorites'
    When method get
    And print 'response is:', response
    Then status 200
© www.soinside.com 2019 - 2024. All rights reserved.