---
source_url: https://www.pubnub.com/docs/chat/sdks/moderation/ban
title: Banning users on channels (deprecated)
updated_at: 2026-06-29T11:46:14.189Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Banning users on channels (deprecated)

:::warning Use Chat SDKs
This documentation is deprecated. Use any of our dedicated [Chat SDKs](https://www.pubnub.com/docs/chat/overview) to quickly implement chat functionality in your application.
:::

If you enable [Access Manager](https://www.pubnub.com/docs/general/security/access-control) on your keyset in the [Admin Portal](https://admin.pubnub.com/), 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 (`authorizedUserId`) 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](https://www.pubnub.com/docs/chat/sdks/users/authorization#granting-permissions), 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](https://www.pubnub.com/docs/chat/sdks/users/authorization#client-side-operations).

#### JavaScript

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

#### Python

```python
spaces = [
    Space.id("channel-a").read(),
    Space.id("channel-b").read()
envelope = pubnub.grantToken()
    .spaces(spaces)
    .ttl(15)
    .authorized_user("user-1")
    .sync()
```

#### Java

```java
pubnub.grantToken()
    .ttl(15)
    .authorizedUserId("user-1")
        .spacesPermissions(Arrays.asList(
                SpacePermissions.id(SpaceId("channel-a")).read(),
                SpacePermissions.id(SpaceId("channel-b")).read()))
        .async(result -> { /* check result */ });
```

#### Kotlin

```kotlin
pubnub.grantToken(
    ttl = 15,
    authorizedUserId = "user-1",
    spacesPermissions = listOf(
        SpacePermissions.name(name = "channel-a", read = true, write = false),
        SpacePermissions.name(name = "channel-b", read = true, write = false)
    )
)
    .async { result ->  /* check 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.

:::note Enable token revoke
To revoke tokens, you must first enable this feature on the [Admin Portal](https://admin.pubnub.com/). To do that, navigate to your app's keyset and mark the *Revoke v3 Token* checkbox in the *ACCESS MANAGER* section.
:::

###### Node.js

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

###### Python

```python
pubnub.revoke_token("p0thisAkFl043rhDdHRsCkNyZXisRGNoYW6hanNlY3JldAFDZ3Jwsample3KgQ3NwY6BDcGF0pERjaGFuoENnctokenV")
```

###### Java

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

###### Kotlin

```kotlin
pubnub.revokeToken("p0thisAkFl043rhDdHRsCkNyZXisRGNoYW6hanNlY3JldAFDZ3Jwsample3KgQ3NwY6BDcGF0pERjaGFuoENnctokenV")
```

For more details about revoking tokens, refer to the [Access Manager](https://www.pubnub.com/docs/general/security/access-control#revoke-permissions) document.