Get access_token after login using gatling scala

54 views
Skip to first unread message

KARIMI KHADIJA

unread,
Feb 16, 2018, 9:22:04 AM2/16/18
to Gatling User Group

I have a web app protected with OAuth2 for authentification

When I login using Gatling I can't get the redirected URL with access_token but when I search in dataBase in find the access_token (Bearer) had generated

This is my code:

class PortailConnexionSimulation extends Simulation {

    val httpProtocol = http
        .baseURL("http://localhost:9900")
        .inferHtmlResources(BlackList(""".*\.js""", """.*\.css""", """.*\.gif""", """.*\.jpeg""", """.*\.jpg""", """.*\.ico""", """.*\.woff""", """.*\.(t|o)tf""", """.*\.png"""), WhiteList())
        .acceptHeader("application/json, text/plain, */*")
        .acceptEncodingHeader("gzip, deflate")
        .acceptLanguageHeader("fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7")
        .userAgentHeader("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36")
        .disableFollowRedirect

    val header_home = Map("Origin" -> "http://localhost")

    val header_login = Map(
        "Content-Type" -> "application/x-www-form-urlencoded",
        "Accept" -> "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "Origin" -> "http://localhost:8080",
        "Accept-Encoding"->"gzip, deflate, br",
        "Accept-Language"->"fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7",
        "Upgrade-Insecure-Requests" -> "1")

    val uri_home = "http://localhost"
    val scn = scenario("RecordedSimulation")

        .exec(http("Page_Accueil")
            .get("/api/administration/actualites?page=0&size=3")
            .headers(header_home))
        .pause(2)
        .exec(http("Page_Connexion")
            .post( uri_home +":8080/openid-connect-server-webapp/login")
            .headers(header_login)
            .formParam("username","Logan17")
            .formParam("password", "Password1$")        
            .formParam("submit", "Se connecter")
            .check(status.is(302))
            .check(header("Location").saveAs("url")))
    .exec(session => {
      val urlN = session.get("url").asOption[String]
      print(urlN.getOrElse("nothing"))
      session
    })

    setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}

But the result of urlN is only "http://localhost:8080/openid-connect-server-webapp/"

But when I use inspect mode in the browser i found the redirect page is "http://localhost:8080/openid-connect-server-webapp/authorize?clienid....." and this one give me another Url which contain the access_token

Please any idea about how to get the Url who contain the access_token.

marom sabag

unread,
Mar 12, 2018, 9:31:48 AM3/12/18
to Gatling User Group
I have the same issue, did you managed to overcome this issue?
Reply all
Reply to author
Forward
0 new messages