· 6 years ago · Oct 09, 2019, 10:04 AM
1Pusher(<PUSHER_API_KEY>,
2 PusherOptions().apply {
3 setCluster("ap2")
4 isEncrypted = true
5 authorizer = Authorizer { channelName, socketId ->
6 val secretKey = <PUSHER_SECRET_KEY>
7 val apiKey = <PUSHER_API_KEY>
8 val data = "$socketId:$channelName"
9
10 //Sign with HmacSHA256
11 val hmac = Mac.getInstance("HmacSHA256")
12 hmac.init(SecretKeySpec(secretKey.toByteArray(), "HmacSHA256"))
13
14 val signature = hmac.doFinal(data.toByteArray())
15
16 val auth = "$apiKey:${signature.toHex()}"
17 JSONObject().apply {
18 put("auth", auth)
19 }.toString()
20 }
21 }
22 )