---
source_url: https://www.pubnub.com/docs/sdks/ruby/api-reference/access-manager
title: Access Manager v3 API for Ruby SDK
updated_at: 2026-11-09T13:29:01.000Z
sdk_name: PubNub Ruby SDK
sdk_version: 6.2.0
description: Implement time-limited resource access control with Access Manager v3 for the PubNub Ruby SDK.
---

# Access Manager v3 API for Ruby SDK

PubNub Ruby SDK, use the latest version: 6.2.0

Install:

```bash
gem install pubnub -v 6.2.0
```

> For AI agents: documentation index at https://www.pubnub.com/llms-full.txt

:::warning Access Manager isn't enabled by default
Without it, PubNub resources on this keyset have no access controls and clients can reach channels and metadata without permission checks — including Publish, Subscribe, and all other operations. Enable Access Manager in [Admin Portal](https://admin.pubnub.com/) before deploying to production.
:::

Access Manager allows you to enforce security controls for client access to resources within the PubNub Platform. With Access Manager v3, your servers (that use a PubNub instance configured with a secret key) can grant their clients tokens with embedded permissions that provide access to individual PubNub resources:

* For a limited period of time.
* Through resource lists or patterns (regular expressions).
* In a single API request, even if permission levels differ (`read` to `channel1` and `write` to `channel2`).

You can add the [`authorizedUuid`](https://www.pubnub.com/docs/security/access-control/overview.md#authorized-uuid) parameter to the grant request to restrict the token usage to one client with a given `userId`. Once specified, only this `authorizedUuid` will be able to use the token to make API requests for the specified resources, according to permissions given in the grant request.

:::note User ID / UUID
User ID is also referred to as **UUID/uuid** in some APIs and server responses but **holds the value** of the **userId** parameter you [set during initialization](https://www.pubnub.com/docs/architecture/core-concepts.md).
:::

## Grant token

:::note Requires Access Manager add-on
This method requires that the *Access Manager* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). See [Enable the features your app calls](https://www.pubnub.com/docs/architecture/authentication/set-up-your-account.md#enable-the-features-your-app-calls).
:::

:::warning Requires Secret Key authentication
Granting permissions to resources should be done by administrators whose SDK instance has been [initialized](https://www.pubnub.com/docs/sdks/ruby/api-reference/configuration.md) with a **Secret Key** (available on the [Admin Portal](https://admin.pubnub.com/) on your app's keyset).
:::

The `grant_token()` method generates a time-limited authorization token with an embedded access control list. The token defines time to live (`ttl`), `authorized_user_id`, and a set of permissions giving access to one or more resources:

* For a limited time period.
* Through resource lists or regular expression (RegEx) patterns.
* In one API request, even when permissions differ.
* `channels`
* `channel_groups`
* `uuids` (other users' object metadata, such as their names or avatars)
* `categories` (list all channel or uuid metadata on the subscribe key, not one named resource)

Only this `authorized_user_id` will be able to use the token with the defined permissions. The authorized client will send the token to PubNub with each request until the token's `ttl` expires. Any unauthorized request or a request made with an invalid token will return a `403` with a respective error message.

### Grant token: Permissions

The grant request allows your server to securely grant your clients access to the resources within the PubNub Platform. There is a limited set of operations the clients can perform on every resource:

| Resource | Permissions |
| --- | --- |
| `channel` | `read`, `write`, `get`, `manage`, `update`, `join`, `delete` |
| `channel_group` | `read`, `manage` |
| `uuid` | `get`, `update`, `delete` |
| `category` (`channels`, `uuids`) | `get` only |

In `grant_token()`, the `categories` hash sets the `channels` and `uuids` categories. Create each value with `Pubnub::Permissions.cat`.

* A category permission lets a token list all metadata of one resource type on your subscribe key. Valid categories are `channels` and `uuids`. The only permission is `get` (`32`).
* A `get` permission on one named channel or user, or on a pattern, does not grant a category.
* A token can contain only categories. It needs no resource or pattern.
* When enumeration enforcement is enabled for a keyset, App Context list requests from a token or auth key without the matching category permission return a `403` error.

For permissions and API operations mapping, refer to [Manage Permissions with Access Manager v3](https://www.pubnub.com/docs/security/access-control/overview.md).

### Grant token: TTL (time to live)

The `ttl` (time to live) parameter defines how many minutes the permissions remain valid. After expiration, the client must get a new token to maintain access. `ttl` is required for every grant call. There is no default value. The maximum value is 43,200 (30 days).

For more details, see [TTL in Access Manager v3](https://www.pubnub.com/docs/security/access-control/overview.md#ttl).

### Grant token: RegEx patterns

Use regular expressions (RegEx) to specify permissions by pattern instead of listing each resource. Define RegEx permissions as `pattern` before making a grant request. Patterns are evaluated on the server using [RE2-style syntax](https://github.com/google/re2/wiki/Syntax); backreferences and lookaround assertions are not supported.

For more details, see [RegEx in Access Manager v3](https://www.pubnub.com/docs/security/access-control/overview.md).

### Grant token: Authorized UUID

Setting an `authorized_user_id` in the token specifies which client should use this token in every request to PubNub. If you do not set `authorized_user_id` during the grant request, the token can be used by any client with any UUID. Restrict tokens to a single `authorized_user_id` to prevent impersonation.

For more details, see [Authorized UUID in Access Manager v3](https://www.pubnub.com/docs/security/access-control/overview.md#authorized-uuid).

### Method(s)

```ruby
grant_token(
  ttl: ttl,
  authorized_user_id: authorized_user_id,
  uuids: uuids,
  channels: channels,
  channel_groups: channel_groups,
  categories: categories
)
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| ttl | Integer | Yes | n/a | Total number of minutes for which the token is valid. The minimum allowed value is 1., The maximum is 43,200 minutes (30 days). |
| authorized_user_id | String | Optional | n/a | Single `uuid` which is authorized to use the token to make API requests to PubNub. |
| uuids | Hash | Optional | n/a | Hash containing `uuid` metadata permissions provided either as a list or a RegEx pattern, for example: `{"uuid-1": Pubnub::Permissions.res(get: true, update: true, delete: true),"^uuid-2.$": Pubnub::Permissions.pat(...)}`. |
| channels | Hash | Optional | n/a | Hash containing channel permissions provided either as a list or a RegEx pattern, for example: `{"channel-1": Pubnub::Permissions.res(read: true, write: true, manage: true, delete: true, get: true, update: true, join: true),"^channel-2.$": Pubnub::Permissions.pat(...)}`. |
| channel_groups | Hash | Optional | n/a | Hash containing channel group permissions provided either as a list or a RegEx pattern, for example: `{"group-id-1": Pubnub::Permissions.res(read: true, manage: true),"^group-id-2.$": Pubnub::Permissions.pat(...)}`. |
| categories | Hash | Optional | n/a | Hash containing category permissions that let the token list all metadata of a type on the subscribe key. Keys are `:channels` (list all channel metadata) and `:uuids` (list all uuid metadata), for example: `{channels: Pubnub::Permissions.cat(get: true), uuids: Pubnub::Permissions.cat(get: true)}`. A `get` permission on a named channel or uuid, or on a pattern, doesn't imply this. Refer to [Category permissions](#category-permissions). |
| meta | Object | Optional | n/a | Extra metadata to be published with the request. Values must be scalar only; arrays or objects aren't supported. |

#### Category permissions

A category permission covers a whole resource type instead of individual resources. Listing all channels or uuids on a subscribe key needs one, because a `get` on a single resource doesn't allow it. Set `:channels` for the `channels` category and `:uuids` for the `uuids` category. A category carries only the `get` permission.

* A category permission lets a token list all metadata of one resource type on your subscribe key. Valid categories are `channels` and `uuids`. The only permission is `get` (`32`).
* A `get` permission on one named channel or user, or on a pattern, does not grant a category.
* A token can contain only categories. It needs no resource or pattern.
* When enumeration enforcement is enabled for a keyset, App Context list requests from a token or auth key without the matching category permission return a `403` error.

`Pubnub::Permissions.cat(get: false)` sends `0` for that category.

The SDK raises `Pubnub::ArgumentError` before sending the request in these cases:

| Cause | Error message |
| --- | --- |
| `categories` is not a `Hash`. | `:categories has to be kind of Hash for grant token event.` |
| A key is not `:channels` or `:uuids`. | `:categories supports only :channels and :uuids keys for grant token event.` |
| A value was not created with `Pubnub::Permissions.cat`. | `:categories values have to be created with Pubnub::Permissions.cat for grant token event.` |

:::note Required key/value mappings
For a successful grant request, you must specify permissions for at least one `uuid`, `channel`, or `channel_groups`, either as a resource list or as a pattern (RegEx), or set `categories`. A `categories` grant alone satisfies this requirement.
:::

### Sample code

```ruby
require 'pubnub'

def grant_token(pubnub)
  future_result = pubnub.grant_token(
    ttl: 15,
    authorized_user_id: "my-authorized-uuid",
    channels: {
      "my-channel" => Pubnub::Permissions.res(read: true)
    }
  )
  result = future_result.value
  result.result[:data]['token']
end

def main
  # Configuration for PubNub instance
  pubnub = Pubnub.new(
    subscribe_key: ENV.fetch('SUBSCRIBE_KEY', 'demo'),
    publish_key: ENV.fetch('PUBLISH_KEY', 'demo'),
    secret_key: ENV.fetch('SECRET_KEY', 'my_secret_key'),
    user_id: 'myUniqueUserId'
  )

  begin
    # Grant token
    token = grant_token(pubnub)
    puts "Token granted successfully: #{token}"
  rescue StandardError => e
    puts "Error: #{e.message}"
  end
end

if __FILE__ == $0
  main
end
```

### Returns

```ruby
#<Pubnub::Envelope
    @result = {
        :data => {
            "message" => "Success",
            "token" => "p0thisAkFl043rhDdHRsCkNyZXisRGNoYW6hanNlY3JldAFDZ3Jwsample3KgQ3NwY6BDcGF0pERjaGFuoENnctokenVzcqBDc3BjoERtZXRhoENzaWdYIGOAeTyWGJI"
        }
    },
    @status = {
        :code => 200
    }
>
```

### Other examples

#### Grant an authorized client access to list all channel and uuid metadata

The code below grants `my-authorized-uuid` the `get` category permission for both `channels` and `uuids`, so the client can list all channel and uuid metadata on the subscribe key.

```ruby
# Grants `my-authorized-user-id` permission to list all channel metadata and all uuid metadata.
# Category permissions support only the `get` operation.
envelope = pubnub.grant_token(
  ttl: 15,
  authorized_user_id: 'my-authorized-user-id',
  categories: {
    channels: Pubnub::Permissions.cat(get: true),
    uuids: Pubnub::Permissions.cat(get: true)
  },
  http_sync: true
)

puts envelope.result[:data][:token]
```

#### Grant an authorized client different levels of access to various resources in a single call

The code below grants `my-authorized-uuid`:

* Read access to `channel-a`, `channel-group-b`, and get to `uuid-c`.
* Read/write access to `channel-b`, `channel-c`, `channel-d`, and get/update to `uuid-d`.

```ruby
pubnub.grant_token(
      ttl: 15,
      authorized_user_id: "my-authorized-uuid",
      channels: {
            "channel-a": Pubnub::Permissions.res(
               read: true
            ),
            "channel-b": Pubnub::Permissions.res(
               read: true,
               write: true
            ),
            "channel-c": Pubnub::Permissions.res(
               read: true,
               write: true
            ),
            "channel-d": Pubnub::Permissions.res(
               read: true,
               write: true
            )
      },
      channel_groups: {
            "channel-group-b": Pubnub::Permissions.res(
               read: true
            )
      },
      uuids: {
            "uuid-c": Pubnub::Permissions.res(
               get: true
            ),
            "uuid-d": Pubnub::Permissions.res(
               get: true,
               update: true
            )
      }
   );
```

#### Grant an authorized client read access to multiple channels using RegEx

The code below grants `my-authorized-uuid` read access to all channels that match the `channel-[A-Za-z0-9]` RegEx pattern.

```ruby
pubnub.grant_token(
      ttl: 15,
      authorized_user_id: "my-authorized-uuid",
      channels: {
            "^channel-[A-Za-z0-9]$": Pubnub::Permission.pat(
               read: true
            )
      },
   );
```

#### Grant an authorized client different levels of access to various resources and read access to channels using RegEx in a single call

The code below grants the `my-authorized-uuid`:

* Read access to `channel-a`, `channel-group-b`, and get to `uuid-c`.
* Read/write access to `channel-b`, `channel-c`, `channel-d`, and get/update to `uuid-d`.
* Read access to all channels that match the `channel-[A-Za-z0-9]` RegEx pattern.

```ruby
pubnub.grant_token(
      ttl: 15,
      authorized_user_id: "my-authorized-uuid",
      channels: {
            "channel-a": Pubnub::Permissions.res(
               read: true
            ),
            "channel-b": Pubnub::Permissions.res(
               read: true,
               write: true
            ),
            "channel-c": Pubnub::Permissions.res(
               read: true,
               write: true
            ),
            "channel-d": Pubnub::Permissions.res(
               read: true,
               write: true
            ),
            "^channel-[A-Za-z0-9]$": Pubnub::Permission.pat(
               read: true
            )
      },
      channel_groups: {
            "channel-group-b": Pubnub::Permissions.res(
               read: true
            )
      },
      uuids: {
            "uuid-c": Pubnub::Permissions.res(
               get: true
            ),
            "uuid-d": Pubnub::Permissions.res(
               get: true,
               update: true
            )
      }
   );
```

### Error responses

If you submit an invalid request, the server returns HTTP 400 with a message that identifies the missing or incorrect argument. Causes can include a RegEx issue, an [invalid timestamp](https://www.pubnub.com/docs/faq/security.md#why-do-i-get-invalid-timestamp-when-i-grant-permissions), or incorrect permissions. The server returns error details in JSON.

## Grant token - spaces & users

:::note Requires Access Manager add-on
This method requires that the *Access Manager* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). See [Enable the features your app calls](https://www.pubnub.com/docs/architecture/authentication/set-up-your-account.md#enable-the-features-your-app-calls).
:::

The `grantToken()` method generates a time-limited authorization token with an embedded access control list. The token defines time to live (`ttl`), `authorizedUserId`, and a set of permissions giving access to one or more resources:

* `spaces`
* `users` (other users' metadata, such as their names or avatars)

Only this `authorizedUserId` will be able to use the token with the defined permissions. The authorized client will send the token to PubNub with each request until the token's `ttl` expires. Any unauthorized request or a request made with an invalid token will return a `403` with a respective error message.

### Grant token - spaces & users: Permissions

The grant request allows your server to securely grant your clients access to the resources within the PubNub Platform. There is a limited set of operations the clients can perform on every resource:

| Resource | Permissions |
| --- | --- |
| `space` | `read`, `write`, `get`, `manage`, `update`, `join`, `delete` |
| `user` | `get`, `update`, `delete` |

For permissions and API operations mapping, refer to [Manage Permissions with Access Manager v3](https://www.pubnub.com/docs/security/access-control/overview.md).

### Grant token - spaces & users: TTL (time to live)

The `ttl` (time to live) parameter defines how many minutes the permissions remain valid. After expiration, the client must get a new token to maintain access. `ttl` is required for every grant call. There is no default value. The maximum value is 43,200 (30 days).

For more details, see [TTL in Access Manager v3](https://www.pubnub.com/docs/security/access-control/overview.md#ttl).

### Grant token - spaces & users: RegEx patterns

Use regular expressions (RegEx) to specify permissions by pattern instead of listing each resource. Define RegEx permissions as `patterns` before making a grant request.

For more details, see [RegEx in Access Manager v3](https://www.pubnub.com/docs/security/access-control/overview.md).

### Grant token - spaces & users: Authorized user ID

Setting an `authorized_user_id` in the token specifies which client should use this token in every request to PubNub. If you do not set `authorized_user_id` during the grant request, the token can be used by any client with any `userId`. Restrict tokens to a single `authorized_user_id` to prevent impersonation.

For more details, see [Authorized UUID in Access Manager v3](https://www.pubnub.com/docs/security/access-control/overview.md#authorized-uuid).

### Method(s)

```ruby
grant_token(ttl: ttl, authorized_user_id: authorized_user_id, users_permissions: users, spaces_permissions: spaces)
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| ttl | Integer | Yes | n/a | Total number of minutes for which the token is valid. The minimum allowed value is 1., The maximum is 43,200 minutes (30 days). |
| authorized_user_id | String | Optional | n/a | Single `uuid` which is authorized to use the token to make API requests to PubNub. |
| users_permissions | Hash | Optional | n/a | Hash containing all User permissions provided as a list of individual permissions or RegEx patterns, for example: `{"user-1": Pubnub::Permissions.res(get: true, update: true, delete: true),"^user-2.$": Pubnub::Permissions.pat(...)}`. |
| spaces_permissions | Hash | Optional | n/a | Hash containing all Space permissions provided as a list of individual permissions or RegEx patterns, for example: `{"space-1": Pubnub::Permissions.res(read: true, write: true, manage: true, delete: true, get: true, update: true, join: true),"^space-2.$": Pubnub::Permissions.pat(...)}`. |
| meta | Object | Optional | n/a | Extra metadata to be published with the request. Values must be scalar only; arrays or objects aren't supported. |

:::note Required key/value mappings
For a successful request, you must specify permissions for at least one User or Space, either as a resource list or as a pattern (RegEx).
:::

### Sample code

```ruby
pubnub.grant_token(
    ttl: 15,
    authorized_user_id: "my-authorized-userId",
    spaces_permissions: {
      "my-space": Pubnub::Permissions.res(
        read: true
      )
    }
);
```

### Returns

```ruby
#<Pubnub::Envelope
    @result = {
        :data => {
            "message" => "Success",
            "token" => "p0thisAkFl043rhDdHRsCkNyZXisRGNoYW6han3Jwsample3KgQ3NwY6BDcGF0pERjaG3BjoERGOAeTyWGJI"
        }
    },
    @status = {
        :code => 200
    }
>
```

### Other examples

#### Grant an authorized client different levels of access to various resources in a single call

The code below grants `my-authorized-userId`:

* Read access to `space-a`, and get to `userId-c`.
* Read/write access to `space-b`, `space-c`, `space-d`, and get/update to `userId-d`.

```ruby
pubnub.grant_token(
      ttl: 15,
      authorized_user_id: "my-authorized-userId",
      spaces_permissions: {
            "space-a": Pubnub::Permissions.res(
               read: true
            ),
            "space-b": Pubnub::Permissions.res(
               read: true,
               write: true
            ),
            "space-c": Pubnub::Permissions.res(
               read: true,
               write: true
            ),
            "space-d": Pubnub::Permissions.res(
               read: true,
               write: true
            )
      },
      users_permissions: {
            "userId-c": Pubnub::Permissions.res(
               get: true
            ),
            "userId-d": Pubnub::Permissions.res(
               get: true,
               update: true
            )
      }
   );
```

#### Grant an authorized client read access to multiple spaces using RegEx

The code below grants `my-authorized-userId` read access to all channels that match the `space-[A-Za-z0-9]` RegEx pattern.

```ruby
pubnub.grant_token(
      ttl: 15,
      authorized_user_id: "my-authorized-userId",
      spaces_permissions: {
            "^space-[A-Za-z0-9]$": Pubnub::Permission.pat(
               read: true
            )
      },
   );
```

#### Grant an authorized client different levels of access to various resources and read access to spaces using RegEx in a single call

The code below grants the `my-authorized-userId`:

* Read access to `space-a` and `userId-c`.
* Read/write access to `space-b`, `space-c`, `space-d`, and get/update to `userId-d`.
* Read access to all channels that match the `space-[A-Za-z0-9]` RegEx pattern.

```ruby
pubnub.grant_token(
      ttl: 15,
      authorized_user_id: "my-authorized-userId",
      space_permissions: {
            "space-a": Pubnub::Permissions.res(
               read: true
            ),
            "space-b": Pubnub::Permissions.res(
               read: true,
               write: true
            ),
            "space-c": Pubnub::Permissions.res(
               read: true,
               write: true
            ),
            "space-d": Pubnub::Permissions.res(
               read: true,
               write: true
            ),
            "^space-[A-Za-z0-9]$": Pubnub::Permission.pat(
               read: true
            )
      },
      users_permissions: {
            "userId-c": Pubnub::Permissions.res(
               get: true
            ),
            "userId-d": Pubnub::Permissions.res(
               get: true,
               update: true
            )
      }
   );
```

### Error responses

If you submit an invalid request, the server returns HTTP 400 with a message that identifies the missing or incorrect argument. Causes can include a RegEx issue, an [invalid timestamp](https://www.pubnub.com/docs/faq/security.md#why-do-i-get-invalid-timestamp-when-i-grant-permissions), or incorrect permissions. The server returns error details in JSON.

## Revoke token

:::note Requires Access Manager add-on
This method requires that the *Access Manager* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). See [Enable the features your app calls](https://www.pubnub.com/docs/architecture/authentication/set-up-your-account.md#enable-the-features-your-app-calls).
:::

:::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.
:::

The `revoke_token()` method allows you to disable an existing token and revoke all permissions embedded within. You can only revoke a valid token previously obtained using the `grant_token()` method.

Use this method for tokens with `ttl` less than or equal to 30 days. If you need to revoke a token with a longer `ttl`, [contact support](mailto:support@pubnub.com).

For more information, refer to [Revoke permissions](https://www.pubnub.com/docs/security/access-control/overview.md).

### Method(s)

```ruby
revoke_token(
   token: token
)
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| token | String | Yes | n/a | Existing token with embedded permissions. |

### Sample code

```ruby
pubnub.revoke_token("p0thisAkFl043rhDXisRGNoYW6han3Jwsample3KgQ3NwY6BDcGF0pERjaG3BjoERGOAeTyWGJI")
```

### Returns

```ruby
<Pubnub::Envelope
    @result = {
        :data => {
            "message" => "Success"
        }
    },
    @status = {
        :code => 200
    }
>
```

### Error Responses

If you submit an invalid request, the server returns an error status code with a descriptive message informing which of the provided arguments is missing or incorrect. Depending on the root cause, this operation may return the following errors:

* `400 Bad Request`
* `403 Forbidden`
* `503 Service Unavailable`

## Parse token

The `parse_token()` method decodes an existing token and returns the object containing permissions embedded in that token. The client can use this method for debugging to check the permissions to the resources or find out the token's `ttl` details.

### Method(s)

```ruby
parse_token(
   token: token
)
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| token | String | Yes | n/a | Current token with embedded permissions. |

### Sample code

```ruby
pubnub.parse_token("p0thisAkFl043rhDdHRsCkNyZXisRGNoYW6hanNlY3JldAFDZ3Jwsample3KgQ3NwY6BDcGF0pERjaGFuoENnctokenVzcqBDc3BjoERtZXRhoENzaWdYIGOAeTyWGJI")
```

### Returns

```ruby
{
    "v"=>2,
    "t"=>1627968380,
    "ttl"=>15,
    "res"=>{
        "chan"=>{
            "channel-1"=>239
        },
        "grp"=>{
            "channel_group-1"=>5
        },
        "usr"=>{},
        "spc"=>{},
        "uuid"=>{
            "uuid-1"=>104}
        },
    "pat"=>{
        "chan"=>{
            "^channel-\\S*$"=>239
        },
        "grp"=>{
            "^:channel_group-\\S*$"=>5
        },
        "usr"=>{},
        "spc"=>{},
        "uuid"=>{
            "^uuid-\\S*$"=>104
        }
    },
    "meta"=>{},
    "uuid"=>"test-authorized-uuid",
    "sig"=>"\xFAT\xFA\xF0\x9E\xF6\xB9)b\xCF;aJ\xC55i26\xAF\x02V\xF9\x8A\xC0H\xD5\x8Ay\xC3\xAC\x92\\"
}
```

#### Category permissions in parsed tokens

A token granted with `categories` carries a `cat` key. `parse_token()` doesn't translate it, so the key uses the wire names `chan` (the `channels` category) and `uuid` (the `uuids` category). Each value is the permission bitmask, and `32` is the `get` permission:

```ruby
"cat"=>{
    "chan"=>32,
    "uuid"=>32
}
```

The `cat` key appears only when the token carries at least one category.

The code below parses a token and reads its category permissions.

```ruby
# Decodes a token that was granted with category permissions.
# The `cat` section holds the permission bitmask for each category: `chan` for channel
# metadata and `uuid` for uuid metadata. The `get` permission has the value 32.
parsed_token = pubnub.parse_token('use-token-string-generated-by-grant_token')

categories = parsed_token['cat']
puts "Channel metadata category: #{categories['chan']}"
puts "Uuid metadata category: #{categories['uuid']}"
```

### Error Responses

If you receive an error while parsing the token, it may suggest that the token is damaged. In that case, request the server to issue a new one.

## Set token

The `set_token()` method is used by the client devices to update the authentication token granted by the server.

### Method(s)

```ruby
set_token(token: token)
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| token | String | Yes | n/a | Current token with embedded permissions. |

### Sample code

```ruby
pubnub.set_token("p0thisAkFl043rhDdHRsCkNyZXisRGNoYW6hanNlY3JldAFDZ3Jwsample3KgQ3NwY6BDcGF0pERjaGFuoENnctokenVzcqBDc3BjoERtZXRhoENzaWdYIGOAeTyWGJI")
```

### Returns

This method doesn't return any response value.

Last updated at: 2026-11-09T13:29:01.000Z
