ARTTokenRequest

Objective-C

@interface ARTTokenRequest : NSObject

Swift

class ARTTokenRequest : NSObject

Contains the properties of a request for a token to Ably. Tokens are generated using -[ARTAuthProtocol requestToken:].

  • The name of the key against which this request is made. The key name is public, whereas the key secret is private.

    Declaration

    Objective-C

    @property (nonatomic, copy, readonly) NSString *_Nonnull keyName;

    Swift

    var keyName: String { get }
  • The client ID to associate with the requested Ably Token. When provided, the Ably Token may only be used to perform operations on behalf of that client ID.

    Declaration

    Objective-C

    @property (nonatomic, copy, nullable) NSString *clientId;

    Swift

    var clientId: String? { get set }
  • A cryptographically secure random string of at least 16 characters, used to ensure the ARTTokenRequest cannot be reused.

    Declaration

    Objective-C

    @property (nonatomic, copy, readonly) NSString *_Nonnull nonce;

    Swift

    var nonce: String { get }
  • mac

    The Message Authentication Code for this request.

    Declaration

    Objective-C

    @property (nonatomic, copy, readonly) NSString *_Nonnull mac;

    Swift

    var mac: String { get }
  • Capability of the requested Ably Token. If the Ably ARTTokenRequest is successful, the capability of the returned Ably Token will be the intersection of this capability with the capability of the issuing key. The capabilities value is a JSON-encoded representation of the resource paths and associated operations. Read more about capabilities in the capabilities docs.

    Declaration

    Objective-C

    @property (nonatomic, copy, nullable) NSString *capability;

    Swift

    var capability: String? { get set }
  • ttl

    Requested time to live for the Ably Token in milliseconds. If the Ably ARTTokenRequest is successful, the TTL of the returned Ably Token is less than or equal to this value, depending on application settings and the attributes of the issuing key. The default is 60 minutes.

    Declaration

    Objective-C

    @property (nonatomic, nullable) NSNumber *ttl;

    Swift

    var ttl: NSNumber? { get set }
  • The timestamp of this request as NSDate object.

    Declaration

    Objective-C

    @property (nonatomic) NSDate *_Nonnull timestamp;

    Swift

    var timestamp: Date { get set }
  • A static factory method to create an ARTTokenRequest object from a deserialized TokenRequest-like object or a JSON stringified ARTTokenRequest object. This method is provided to minimize bugs as a result of differing types by platform for fields such as timestamp or ttl. For example, in Ruby ttl in the TokenRequest object is exposed in seconds as that is idiomatic for the language, yet when serialized to JSON using to_json it is automatically converted to the Ably standard which is milliseconds. By using the fromJson method when constructing a TokenRequest object, Ably ensures that all fields are consistently serialized and deserialized across platforms.

    Declaration

    Objective-C

    + (ARTTokenRequest *_Nullable)fromJson:(nonnull id<ARTJsonCompatible>)json
                                     error:(NSError *_Nullable *_Nullable)errorPtr;

    Swift

    class func fromJson(_ json: ARTJsonCompatible) throws -> ARTTokenRequest

    Parameters

    json

    A deserialized TokenRequest-like object or a JSON stringified TokenRequest object to create an ARTTokenRequest.

    errorPtr

    A reference to the NSError object where an error information will be saved in case of failure.

    Return Value

    An Ably token request object.