PubNub Logo Docs
Support Contact Sales Login Try Our APIs

›MODERATION

Collapse all
Dark mode

Back to Home

Overview

  • In-App Chat

Chat Components

  • Overview
  • REACT

    • React Components

    ANDROID

    • Getting Started
    • UI Components
    • UI Theming
    • Data Components
    • Chat Provider
    • Message Reactions
    • Message Menu

    IOS

    • Getting Started
    • UI Components
    • UI Theming
    • Data Components
    • Chat Provider

SDKs

  • Overview
  • USERS

    • Setup
    • Metadata
    • Permissions
    • Presence
    • Mentions

    CHANNELS

    • Types and Names
    • Metadata
    • Subscriptions
    • Memberships

    MESSAGES

    • Sending Messages
    • Message History
    • Unread Counts
    • File Upload
    • Typing Indicators
    • Read Receipts
    • Emoji Reactions
    • Update Messages
    • Delete Messages
    • External Storage

    PUSH NOTIFICATIONS

    • Overview

    MODERATION

    • Profanity Filters
    • Flag Messages
    • Ban Users
    • Mute Users
    • Spam Prevention

    INTEGRATIONS

    • Overview
    • Content Moderation
    • Image Moderation
    • Language Translation
    • Chatbots
    • GIFs
    • Stickers

Moderation Dashboard

  • Overview
  • Getting Started
  • FEATURES

    • Automatic Text Moderation
    • Automatic Image Moderation
    • Manual Message Moderation
    • Manual User Moderation
    • User Management
    • Channel Management
  • Required Configuration

Debug Console
Network Status

Banning users on channels

If you enable Access Manager on your keyset in the Admin Portal, you automatically disable default access to channels, channel groups, and other users' metadata until these are specifically granted. You can additionally restrict this access by authorizing only one user (authorized_uuid) to perform certain operations on selected resources.

Updating access level

Once a user is given read or write permissions, they will continue to have them until the ttl (time-to-live for the token) set in the grant token request expires or the token is revoked. You can override existing access to PubNub resources by requesting the server for a new token with changed permissions and using this token in all subsequent requests. Previous access will be removed once the original token expires. For this reason, it's recommended to use short-lived tokens with ttl between 10 and 60 minutes.

If you granted user-1 write access to channel-a and channel-b as seen in this example, you can use the code below to update their access level by, for example, removing the write permissions to both channels. Note that once the server returns the new token, you must update the token used by your client. For more information on setting tokens on the client, refer to Managing user permissions.

Node.js
Python
Java
Kotlin

Go to SDK

pubnub.grantToken(
{
ttl: 15,
authorized_uuid: "user-1",
resources: {
channels: {
"channel-a": {
read: true,
write: false
},
"channel-b": {
read: true,
write: false
}
}
}
}, function(status, token) {
console.log(token);
}
);

Go to SDK

channels = [
Channel.id("channel-a").read(),
Channel.id("channel-b").read()
envelope = pubnub.grant_token()
.channels(channels)
.ttl(15)
.authorized_uuid("user-1")
.sync()

Go to SDK

pubnub.grantToken()
.ttl(15)
.authorizedUUID("user-1")
.channels(Arrays.asList(
ChannelGrant.name("channel-a").read(),
ChannelGrant.name("channel-b").read()))
.async(new PNCallback<PNGrantTokenResult>() {
@Override
public void onResponse(@Nullable PNGrantTokenResult result, @NotNull PNStatus status) {
if (status.error()) {
// Handle error
}
else {
// Handle result
}
}
});

Go to SDK

pubnub.grantToken(
ttl = 15,
authorizedUUID = "user-1",
channels = listOf(
ChannelGrant.name(name = "channel-a", read = true, write = false),
ChannelGrant.name(name = "channel-b", read = true, write = false)
)
)
.async { result, status ->
if (status.error) {
// Handle error
} else {
// Handle result
}
}

Revoking all permissions

If you want to ban a user by removing all permissions associated with their token, you can revoke it entirely. This means that all calls to any PubNub API that use a revoked token will fail with a 403 Revoked Token error, effectively prohibiting the user from accessing any resources.

Enable token revoke

To revoke tokens, you must first enable this feature on the Admin Portal. To do that, navigate to your app's keyset and mark the Revoke v3 Token checkbox in the ACCESS MANAGER section.

Node.js
Python
Java
Kotlin

Go to SDK

try {
const token = await pubnub.revokeToken({
token: "p0AkFl043rhDdHRsple3KgQ3NwY6BDcENnctokenVzcqBDczaWdYIGOAeTyWGJI"
});
} catch (status) {
console.log(status);
}

Go to SDK

pubnub.revoke_token("p0thisAkFl043rhDdHRsCkNyZXisRGNoYW6hanNlY3JldAFDZ3Jwsample3KgQ3NwY6BDcGF0pERjaGFuoENnctokenV")

Go to SDK

pubnub.revokeToken()
.token("p0thisAkFl043rhDdHRsCkNyZXisRGNoYW6hanNlY3JldAFDZ3Jwsample3KgQ3NwY6BDcGF0pERjaGFuoENnctokenV")

Go to SDK

pubnub.revokeToken("p0thisAkFl043rhDdHRsCkNyZXisRGNoYW6hanNlY3JldAFDZ3Jwsample3KgQ3NwY6BDcGF0pERjaGFuoENnctokenV")

For more details about revoking tokens, refer to the Access Manager document.

←Flag MessagesMute Users→
© PubNub Inc. - Privacy Policy