Swapnil Kotwal Swapnil Kotwal - 4 years ago 178
Scala Question

Gatling Generate OAuth2.0 token using callback URL not working

Here is my scenario.

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


But I'm getting error as

=========================
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 -
>>>>>>>>>>>>>>>>>>>>>>>>>>

Answer Source

Finally, I figure it out, this answere helped me here http://stackoverflow.com/a/41273020/1665592

What I changed,

Headers

Yes, headers are so much important.

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

This variable names are OAuth 2.0 standards client_secret, client_id, grant_type, scope while I was trying 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")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download