Hello! I am using Ktor as common library for platf...
# ktor
h
Hello! I am using Ktor as common library for platforms iOS and Android our backend services are session and cookie based, where I first do authorization call, as response I get token, using that token as cookie header I need to make next consecutive requests for which ktor client is adding encoded value instead of actually passed value for which my backend is not providing valid response, can anyone help me in resolving this, upon verifying using proxy tools, if my backend is expecting token = LYJxQGo1pgmP_Eu-tAMmcA..|1636367566|ckC8hI-v1vj1KIz_4CDKupRDUhk., ktor is passing LYJxQGo1pgmP_Eu-tAMmcA..%2%2%21636367566|ckC8hI-v1vj1KIz_4CDKupRDU
a
Could you please describe how exactly do you get a token and how do you send it to a server? Also, please share a code snippet.
h
Thanks for the reply, please see my code snippet below
Copy code
suspend fun ssoAuth(userName: String, password: String): HttpResponse {
    val httpResponse: HttpResponse = <http://client.post|client.post> {
        url("<https://ssgosghop.emc.com/NGSSOauthRest/service/v1/amisauth.json>")
        body = TextContent(
            text = "<?xml version='1.0' encoding='UTF-8' standalone='yes'?><user><username>$userName</username><password>$password</password><authmode>0</authmode></user>",
            contentType = ContentType.Text.Plain
        )
        headers {
            append("apikey", "l7xxf97e3b26235f4f7585256ba489e78d37")
        }
    }

    /* token =
         Json.parseToJsonElement(httpResponse.readText()).jsonObject["object"]?.jsonObject?.get("authResult")?.jsonObject?.get(
             "token"
         ).toString()*/
    return httpResponse
}
above code is to get token
Copy code
suspend fun getVersion(token: String): VersionResponse? {
    return try {
        val response: VersionResponse? = client.get {
            url("<https://cloudiq.emc.com/api/version>")
            val session = "ngssosession=$token"
            println("fafa session - $session")
            headers {
                append("Cookie", session)
                append("content-type", "application/json; charset=UTF-8")
                append("Accept", "*/*")
                append("Accept-Charset", "UTF-8")
                append("accept-encoding", "deflate, gzip, br, zstd")
            }
        }
        response
    } catch (exception: Exception) {
        exception.printStackTrace()
        null
    }
}
a
Please try to use the
cookie
function for sending data for a session instead of manually adding the
Cookie
header:
Copy code
cookie("ngssosession", token)
h
@Aleksei Tirman [JB] I have also tried that approach but no luck
{ "object": { "authResult": { "status": "SUCCESS", "token": "_dLm9NyZzfQXcizn4v2BAA..|1636376938|HTY8w-rSOfYnH7i3fxQCy4GrEYs.", "operation": "VALID_USER", "userProps": [{ "propName": "LAST_NAME", "propValue": "H S" }, { "propName": "GIVEN_NAME", "propValue": "Yogesh" }, { "propName": "UID", "propValue": "1311262" }, { "propName": "EMC_IDENTITY", "propValue": "E" }, { "propName": "EMAIL", "propValue": "Yogesh_H_s@Dell.com" }] }, "serviceFault": null } }
Screenshot (27).png
if u notice in above screen shot, its replacing with encoded characters for special symbols for which our server is not responding with valid response
@Aleksei Tirman [JB] I also cross checked by adding breakpoints in proxy tools and correcting the cookie value, upon correcting cookie value i get valid response
a
The problem was KTOR-993.