Gatling 使用回调 URL 生成 OAuth2.0 令牌无效

Gatling Generate OAuth2.0 token using callback URL not working

这是我的场景。

val header = Map(
    "Accept" -> """application/json""",
    "Content-Type" -> """application/x-www-form-urlencoded, charset=UTF-8""")

val auth_token = scenario("POST Authentication")
        .exec(
            http("POST OAuth Req")
            .post("/validate/activationURL")
            .formParam("oauth.token.client.secret", "*******")
            .formParam("oauth.token.url", "https://myweb.com/as/token.oauth2")
            .formParam("oauth.token.client.id", "my-test-user")
            .formParam("oauth.token.grant.type", "client_credentials")
            .formParam("oauth.token.scope", "my:test:activation")
            .headers(header)
    )

但我收到错误消息

=========================
HTTP request:
POST https://my-validation.net/validate/activationURL
headers=
Accept: application/json
Content-Type: application/x-www-form-urlencoded
Content-Length: 305
Host: https://my-validation.net/
params=
oauth.token.client.secret: *******
oauth.token.url: https://myweb.com/as/token.oauth2
oauth.token.client.id: my-test-user
oauth.token.grant.type: client_credentials
oauth.token.scope: my:test:activation
=========================
HTTP response:
status=
401 Unauthorized
headers= 
Cache-Control: no-store
Content-Type: application/json;charset=UTF-8
Date: Fri, 03 Feb 2017 03:30:40 GMT
Pragma: no-cache
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
Www-Authenticate: Bearer realm="oauth2-resource", error="unauthorized", error_description="Full authentication is required to access this resource"
X-Cf-Requestid: 4681a3da-a747-40f7-4801-b6b972b07cf6
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-Xss-Protection: 1; mode=block
Content-Length: 102

body=
{"error":"unauthorized","error_description":"Full authentication is required to access this resource"}
<<<<<<<<<<<<<<<<<<<<<<<<<
20:30:40.972 [DEBUG] i.g.h.a.ResponseProcessor - 
>>>>>>>>>>>>>>>>>>>>>>>>>>

终于,我弄明白了,这个回答对我有帮助https://whosebug.com/a/41273020/1665592

我改变了什么,

Headers

是的,headers非常重要。

val header = Map(
    "Content-Type" -> """application/x-www-form-urlencoded""")

这个变量名称是 OAuth 2.0 标准 client_secret, client_id, grant_type, scope 而我正在尝试 oauth.token.client.secret

val auth_token = scenario("POST Authentication")
        .exec(
            http("POST OAuth Req")
            .post("https://myweb.com/as/token.oauth2")
            .formParam("client_secret", "*******")
            .formParam("client_id", "my-test-user")
            .formParam("grant_type", "client_credentials")
            .formParam("scope", "my:test:activation")
            .headers(header)
            .check(status.is(200)).check(jsonPath("$.access_token").exists.saveAs("access_token")