---
source_url: https://www.pubnub.com/docs/sdks/swift/api-reference/access-manager
title: Access Manager v3 API for Swift SDK
updated_at: 2026-06-16T12:52:35.243Z
sdk_name: PubNub Swift SDK
sdk_version: 10.1.7
---

> 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


# Access Manager v3 API for Swift SDK

PubNub Swift SDK, use the latest version: 10.1.7

Install:

```bash
Add PubNub via Swift Package Manager or CocoaPods@10.1.7
```

:::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. 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 can grant their clients tokens with embedded permissions that provide access to individual PubNub resources, such as channels, channel groups, and UUID metadata:

* For a limited period of time.
* Through resource lists or patterns (regular expressions; the server uses [RE2-style syntax](https://github.com/google/re2/wiki/Syntax), without backreferences or lookaround assertions).
* In a single API request, even if permission levels differ (`read` to `channel1` and `write` to `channel2`).

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

For more information about Access Manager v3, refer to [Manage Permissions with Access Manager v3](https://www.pubnub.com/docs/general/security/access-control).

:::note Client device support only
The Swift SDK supports only client implementation of Access Manager functionality. This means that you cannot use it to grant permissions, but rather to parse and set tokens received from a server SDK.
:::

## Parse token

The `parse()` 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` (time to live) details.

### Method(s)

```swift
func parse(token: String)
```

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

### Sample code

:::tip Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
:::

```swift
import PubNubSDK

// Initializes a PubNub object with the configuration
let pubnub = PubNub(
  configuration: PubNubConfiguration(
    publishKey: "demo",
    subscribeKey: "demo",
    userId: "myUniqueUserId"
  )
)

// Parse an existing token
pubnub.parse(token: "#yourAuthToken")
```

### Returns

This method responds with a struct of `PAMToken`:

```swift
struct PAMToken {
  
  /// Token version
  public let version: Int { get }
  
  /// Token generation date and time
  public let timestamp: Int { get }
  
  /// Maximum amount of time (in minutes) during which the token will be valid
  public let ttl: Int { get }
  
  /// The uuid that is exclusively authorized to use this token to make API requests
  public let authorizedUUID: String? { get }
  
  /// Permissions granted to specific resources
  public let resources: PAMTokenResource { get }
  
  /// Permissions granted to resources which match a specified regular expression
  public let patterns: PAMTokenResource { get }

  /// Additional information which has been added to the token
  public let meta: [String: AnyJSON] { get }

  /// The computed signature
  public let signature: String { get }
}
```

See the resource and pattern permissions stored in the `PAMTokenResource` structure:

```swift
struct PAMTokenResource {

  /// Permissions granted to specific / regexp matching channels
  public let channels: [String: PAMPermission] { get }
  
  /// Permissions granted to specific / regexp matching channel groups
  public let groups: [String: PAMPermission] { get }
  
  /// Permissions granted to specific / regexp matching uuids
  public let uuids: [String: PAMPermission] { get }
}
```

### 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()` method is used by the client devices to update the authentication token granted by the server.

### Method(s)

```swift
func set(token: String)
```

| Parameter | Description |
| --- | --- |
| `token` *Type: `String`Default: n/a | Current token with embedded permissions. |

### Sample code

```swift
import PubNubSDK

// Initializes a PubNub object with the configuration
let pubnub = PubNub(
  configuration: PubNubConfiguration(
    publishKey: "demo",
    subscribeKey: "demo",
    userId: "myUniqueUserId"
  )
)

// Update the authentication token granted by the server
pubnub.set(token: "#yourAuthToken")
```

### Returns

This method doesn't return any response value.

## Terms in this document

* **Channel** - A pathway for sending and receiving messages between devices, created automatically when you first use it, that can handle any number of users and messages for different communication needs, like 1-1 text chats, group conversations, and other data streaming.