如何在 JMeter 中进行 OAuth 2.0 身份验证? [英] How to do a OAuth 2.0 authentication in JMeter?

查看:109
本文介绍了如何在 JMeter 中进行 OAuth 2.0 身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对一些需要进行身份验证 (OAuth 2.0) 的 API 进行功能测试,并在 JMeter 中进行模拟.

I'm trying to Functional test a few APIs that need to be authenticated (OAuth 2.0) and simulate this in JMeter.

我正在尝试验证 Azure 云的 OAuth 服务.有没有人能够成功创建 JMeter HTTP 请求以针对 OAuth 2.0 进行身份验证?

I'm trying to authenticate the OAuth service for Azure cloud. Has anyone out there been able to successfully create JMeter HTTP requests to authenticate against OAuth 2.0?

推荐答案

基本上需要添加 HTTP Header Manager 发送带有 Bearer ${ACCESS_TOKEN} 值的 Authorization 标头,以便进行经过身份验证的 OAuth API 调用.

Basically you need to add HTTP Header Manager to send Authorization header with the value of Bearer ${ACCESS_TOKEN} in order to make authenticated OAuth API calls.

访问令牌可以通过两种主要方式获得:

Access token can be obtained in 2 major ways:

  1. 以某种方式获取它(请求它,使用需要模拟的嗅探器工具和应用程序捕获它等),但请注意 OAuth 访问令牌具有 有限寿命(默认为 1 小时,这也适用于第 2 点)
  2. 在您的测试中实施 OAuth2 流程,即:

  1. Get it somehow (ask for it, capture it using sniffer tool and application which you need to simulate, etc), but be aware that OAuth access tokens have limited life span (1 hour by default, this applies to point 2 as well)
  2. Implement OAuth2 flow in your test, i.e. :

  • 身份验证(提供客户端 ID 和租户 ID)
  • 授权(使用客户端 ID 和上一步中的代码)
  • 获取访问令牌(提供上一步的授权代码、第一步的代码和客户端 ID

关于实现选项 2 - 它需要 3 个单独的 JMeter 采样器(或者,您可以通过 JSR223 采样器)

In regards to implementing option 2 - it will require 3 separate JMeter samplers (or alternatively you can get the access token programmatically via JSR223 Sampler)

参考文献:

这篇关于如何在 JMeter 中进行 OAuth 2.0 身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆