2017-02-03 15 views
0

Вот мой сценарий.Gatling Создать токен OAuth2.0 с использованием обратного вызова URL не работает

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 - 
>>>>>>>>>>>>>>>>>>>>>>>>>> 
+0

Таким образом, вы пытаетесь получить маркер доступа? – FrAn

ответ

0

Наконец, я полагаю, это, это answere помог мне здесь https://stackoverflow.com/a/41273020/1665592

То, что я изменился,

Заголовки

Да, заголовок так важны.

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")