Access Manager v3 API for PubNub Objective-C SDK

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).
  • In a single API request, even if permission levels differ (read to channel1 and write to channel2).

You can add the 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.

Client device support only

The Objective-C 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 parseAuthToken: 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)

- (PNPAMToken *)parseAuthToken:(NSString *)token
ParameterTypeRequiredDefaultDescription
tokenStringYesn/aCurrent token with embedded permissions.

Basic Usage

PNPAMToken *token = [self.client parseAuthToken:@"p0thisAkFl043rhDdHRsCkNyZXisRGNoYW6hanNlY3JldAFDZ3Jwsample3KgQ3NwY6BDcGF0pERjaGFuoENnctokenVzcqBDc3BjoERtZXRhoENzaWdYIGOAeTyWGJI"];
NSLog(@"Token permissions: %@", token);

Returns

This method will respond with a PNPAMToken instance:

@interface PNPAMToken : NSObject

// Token version
@property (nonatomic, readonly, assign) NSUInteger version;

// Token generation date and time
@property (nonatomic, readonly, assign) NSUInteger timestamp;

// Maximum amount of time (in minutes) during which the token will be valid
@property (nonatomic, readonly, assign) NSUInteger ttl;

// The uuid that is exclusively authorized to use this token to make API requests
@property (nonatomic, nullable, readonly, strong) NSString *authorizedUUID;

// Permissions granted to specific resources
show all 53 lines

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 setAuthToken: method is used by the client devices to update the authentication token granted by the server.

Method(s)

- (void)setAuthToken:(NSString *)token;
ParameterTypeRequiredDefaultDescription
tokenStringYesn/aCurrent token with embedded permissions.

Basic Usage

[self.client setAuthToken:@"p0thisAkFl043rhDdHRsCkNyZXisRGNoYW6hanNlY3JldAFDZ3Jwsample3KgQ3NwY6BDcGF0pERjaGFuoENnctokenVzcqBDc3BjoERtZXRhoENzaWdYIGOAeTyWGJI"];

Returns

This method doesn't return any response value.

Last updated on