![JAR search and dependency download from the Maven repository](/logo.png)
com.pubnub.internal.endpoints.access.GrantTokenEndpoint.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pubnub-kotlin-impl Show documentation
Show all versions of pubnub-kotlin-impl Show documentation
PubNub is a cross-platform client-to-client (1:1 and 1:many) push service in the cloud, capable of broadcasting real-time messages to millions of web and mobile clients simultaneously, in less than a quarter second!
package com.pubnub.internal.endpoints.access
import com.pubnub.api.PubNubError
import com.pubnub.api.PubNubException
import com.pubnub.api.endpoints.access.GrantToken
import com.pubnub.api.enums.PNOperationType
import com.pubnub.api.models.consumer.access_manager.v3.ChannelGrant
import com.pubnub.api.models.consumer.access_manager.v3.ChannelGroupGrant
import com.pubnub.api.models.consumer.access_manager.v3.PNGrantTokenResult
import com.pubnub.api.models.consumer.access_manager.v3.UUIDGrant
import com.pubnub.api.retry.RetryableEndpointGroup
import com.pubnub.api.v2.PNConfiguration.Companion.isValid
import com.pubnub.internal.EndpointCore
import com.pubnub.internal.PubNubImpl
import com.pubnub.internal.models.server.access_manager.v3.GrantTokenRequestBody
import com.pubnub.internal.models.server.access_manager.v3.GrantTokenResponse
import retrofit2.Call
import retrofit2.Response
class GrantTokenEndpoint(
pubnub: PubNubImpl,
override val ttl: Int,
private val meta: Any?,
private val authorizedUUID: String?,
private val channels: List,
private val channelGroups: List,
private val uuids: List,
) : EndpointCore(pubnub), GrantToken {
override fun getAffectedChannels(): List = channels.map { it.id }
override fun getAffectedChannelGroups(): List = channelGroups.map { it.id }
override fun validateParams() {
if (!pubnub.configuration.secretKey.isValid()) {
throw PubNubException(PubNubError.SECRET_KEY_MISSING)
}
if (!configuration.subscribeKey.isValid()) {
throw PubNubException(PubNubError.SUBSCRIBE_KEY_MISSING)
}
if ((channels + channelGroups + uuids).isEmpty()) {
throw PubNubException(
pubnubError = PubNubError.RESOURCES_MISSING,
errorMessage = "At least one grant required",
)
}
}
override fun doWork(queryParams: HashMap): Call {
val requestBody: GrantTokenRequestBody =
GrantTokenRequestBody.of(
ttl = ttl,
channels = channels,
groups = channelGroups,
uuids = uuids,
meta = meta,
uuid = authorizedUUID,
)
return retrofitManager
.accessManagerService
.grantToken(configuration.subscribeKey, requestBody, queryParams)
}
override fun createResponse(input: Response): PNGrantTokenResult {
return input.body()!!.data.token.let { PNGrantTokenResult(it) }
}
override fun operationType(): PNOperationType = PNOperationType.PNAccessManagerGrantToken
override fun isAuthRequired(): Boolean = false
override fun getEndpointGroupName(): RetryableEndpointGroup = RetryableEndpointGroup.ACCESS_MANAGER
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy