grantToken

expect abstract fun grantToken(ttl: Int, meta: CustomObject? = null, authorizedUUID: String? = null, channels: List<ChannelGrant> = emptyList(), channelGroups: List<ChannelGroupGrant> = emptyList(), uuids: List<UUIDGrant> = emptyList(), getAllChannels: Boolean = false, getAllUUIDs: Boolean = false): GrantToken

Legacy grantToken overload having the uuids bucket (App Context v2 UUID metadata). New code should prefer the flat-list overload taking grants: List<TokenGrant>.

Parameters

ttl

Time in minutes for which granted permissions are valid.

meta

Additional metadata.

authorizedUUID

Single uuid which is authorized to use the token to make API requests to PubNub.

channels

List of all channel grants.

channelGroups

List of all channel group grants.

uuids

List of all uuid grants.

getAllChannels

Set to true to allow listing all channel metadata on the keyset (getAllChannelMetadata). A get on a named channel or a channel pattern doesn't imply this.

getAllUUIDs

Set to true to allow listing all uuid metadata on the keyset (getAllUUIDMetadata). A get on a named uuid or a uuid pattern doesn't imply this.


expect abstract fun grantToken(ttl: Int, authorizedUserId: UserId? = null, meta: CustomObject? = null, grants: List<TokenGrant>): GrantToken

The modern grantToken: mint a token from a single flat list of grants. Every grant carries its own resource type (ChannelGrant, ChannelGroupGrant or a DataSyncGrantType from DataSyncGrant), so a pub/sub-only customer, an App Context customer and a DataSync customer all use the same product-neutral method. DataSync realtime subscribe is granted with DataSyncGrant.subscribe / DataSyncGrant.subscribePattern, which return a ChannelGrant on the resolved ref-channel.

pubnub.grantToken(
ttl = 60,
grants = listOf(ChannelGrant.name("chat", read = true, write = true)),
).sync().token

Parameters

ttl

Time in minutes for which granted permissions are valid.

authorizedUserId

Single userId which is authorized to use the token, or null for an unbound token.

meta

Additional metadata. Must be null or a map when any grant carries a projection. Must not contain pn-projections: the SDK builds that key from the grants' projection.

grants

Flat list of grants; each grant's type selects its wire bucket.

actual abstract fun grantToken(ttl: Int, meta: Any?, authorizedUUID: String?, channels: List<ChannelGrant>, channelGroups: List<ChannelGroupGrant>, uuids: List<UUIDGrant>, getAllChannels: Boolean, getAllUUIDs: Boolean): GrantToken

This function generates a grant token for PubNub Access Manager (PAM).

Permissions can be applied to any of the three type of resources:

  • channels

  • channel groups

  • uuid - metadata associated with particular UUID

Each type of resource have different set of permissions. To know what's possible for each of them check ChannelGrant, ChannelGroupGrant and UUIDGrant.

Legacy grantToken overload having the uuids bucket (App Context v2 UUID metadata). New code should prefer the flat-list overload taking grants: List<TokenGrant>.

Parameters

ttl

Time in minutes for which granted permissions are valid.

meta

Additional metadata. Must not contain pn-projections.

authorizedUUID

Single uuid which is authorized to use the token to make API requests to PubNub

channels

List of all channel grants

channelGroups

List of all channel group grants

uuids

List of all uuid grants

getAllChannels

Set to true to allow listing all channel metadata on the keyset (getAllChannelMetadata). A get on a named channel or a channel pattern doesn't imply this.

getAllUUIDs

Set to true to allow listing all uuid metadata on the keyset (getAllUUIDMetadata). A get on a named uuid or a uuid pattern doesn't imply this.


actual abstract fun grantToken(ttl: Int, authorizedUserId: UserId?, meta: Any?, grants: List<TokenGrant>): GrantToken

The modern grantToken: mint a token from a single flat list of grants for PubNub Access Manager (PAM).

Every grant carries its own resource type (ChannelGrant, ChannelGroupGrant or a DataSyncGrantType from DataSyncGrant), so a pub/sub-only customer, an App Context customer and a DataSync customer all use the same product-neutral method. Each grant type exposes only the permissions relevant to it. DataSync realtime subscribe is granted with DataSyncGrant.subscribe / DataSyncGrant.subscribePattern, which return a ChannelGrant on the resolved ref-channel.

The legacy uuids bucket is intentionally not reachable here — UUIDGrant does not implement TokenGrant. Use the legacy overload for uuids.

Parameters

ttl

Time in minutes for which granted permissions are valid.

authorizedUserId

Single userId which is authorized to use the token to make API requests to PubNub. Pass null to mint a token not bound to a specific authorized userId.

meta

Additional metadata. Must be null or a map when any grant carries a projection. Must not contain pn-projections: the SDK builds that key from the grants' projection.

grants

Flat list of grants; each grant's type selects its wire bucket.

actual abstract fun grantToken(ttl: Int, meta: CustomObject?, authorizedUUID: String?, channels: List<ChannelGrant>, channelGroups: List<ChannelGroupGrant>, uuids: List<UUIDGrant>, getAllChannels: Boolean, getAllUUIDs: Boolean): GrantToken

Legacy grantToken overload having the uuids bucket (App Context v2 UUID metadata). New code should prefer the flat-list overload taking grants: List<TokenGrant>.


actual abstract fun grantToken(ttl: Int, authorizedUserId: UserId?, meta: CustomObject?, grants: List<TokenGrant>): GrantToken