2

I am trying to join conference call using sinch's callout rest api but getting response 40102 invalid signature when call using retrofit.

My code is..

        val instant: Instant = Instant.now()

        val mainObject = JsonObject()
        mainObject.addProperty("method", "conferenceCallout")
        val jsonConferenc = JsonObject()
        val jsonDestination = JsonObject()
        jsonDestination.addProperty("type", "username")
        jsonDestination.addProperty("endpoint", getUserInfo().id)
        jsonConferenc.add("destination", jsonDestination)

        jsonConferenc.addProperty("domain", "mxp")
        jsonConferenc.addProperty("conferenceId", "4495")
        jsonConferenc.addProperty("enableDice", false)
        mainObject.add("conferenceCallout", jsonConferenc)

        val contentMd5 = Base64.encodeToString(getMd5(mainObject.toString())?.toByteArray(), Base64.NO_WRAP)
        val stringToSign = "POST\n" +
                "$contentMd5\n" +
                "application/json; charset=UTF-8\n" +
                "x-timestamp:$instant\n" +
                "/v1/callouts"

        val key = Base64.decode(SinchServiceNew.APP_SECRET, Base64.DEFAULT)
        val secret_key = SecretKeySpec(SinchServiceNew.APP_SECRET.toByteArray(Charsets.UTF_8), "HmacSHA256")
        val sha256_HMAC = Mac.getInstance("HmacSHA256")
        sha256_HMAC.init(secret_key)
        val signature = Base64.encodeToString(sha256_HMAC.doFinal(stringToSign.toByteArray(Charsets.UTF_8)), Base64.NO_WRAP)

        val headers = HashMap<String, String>()
        headers["content-type"] = "application/json; charset=UTF-8"
        headers["x-timestamp"] = instant.toString()
        headers["authorization"] = "Application ${SinchServiceNew.APP_KEY}:$signature"


Olance
  • 87
  • 1
  • 7
  • Hi, jus to basic auth way easier, username applicaiton\key password your secret. if you want to sigh, i think you need to get bytes on mainObject in stead of string. but its for sure super tricky to debug – cjensen May 11 '20 at 04:29

0 Answers0