iOS Initialization

Jump to: Swift, Objective-C

Initialize a FIDO2Client instance from the ZSM module by creating an instance of the ZSMConfig class with the necessary configuration parameters such as host_url, application_id, and consumer_id. Then, use the FIDO2Client constructor to initialize the instance, which is required for performing all FIDO2 Auth operations.

Custom logging can be defined when initializing a FIDO2Client object. If a custom logging function is not provided, a default logging method is used. This method uses iOS's built-in logging methods and maps to the LogLevel enum defined within the API.

Swift

Initialization

Usage

func initializeFIDO2Client() {
        let config = ZSMConfig(json: [
            "host_url": hostUrl,
            "application_id": applicationId,
            "application_environment": "TEST",
            "consumer_id": consumerId
        ])

        config.logLevel = .Debug
        config.logFunction = { level, message in
            print("[\(level)] \(message)")
        }
        let client = FIDO2Client(config)
    }

Returns The initialized FIDO2Client instance.

Configuration Parameters

Initialize the ZSMConfig object with the required configuration.

Parameters

Parameter NameData TypeDescriptionDefault Value
host_urlNSURLThe URL of the ZSM server.Required
application_idNSStringThe environment name (e.g., "TEST", "PROD").Required
consumer_idNSStringThe consumer identifier.Required
application_environmentNSStringThe environment name (e.g., "TEST", "PROD").Required, "TEST"
request_timeout_msNSUIntegerNetwork timeout while performing remote transactions (in milliseconds).30000
retry_countNSUIntegerNumber of retries for network transactions.0
perform_network_health_checkBOOLWhether to perform a health check prior to instantiation.YES
headersNSDictionaryHeaders used while performing remote transactions.nil
metadataNSDictionaryMetadata used while performing remote transactions.nil
keychain_groupNSString?Shared keychain group ID for multiple applications of the same vendor.nil
mpc_algorithmMPCAlgorithmThe encryption algorithm for transactions..ECDSAP256
requires_biometricsBOOLWhether to bypass biometrics (assuming implementation outside the API).NO
logLevelLogLevelThe logging level for the API..Info
log_function(LogLevel, NSString) -> VoidA callback function for custom log handling.nil

Configuring Logging

The ZSM SDK provides flexible logging configuration options. You can set the log level and provide a custom logging implementation to route log messages to your application's logging infrastructure.

Setting Log Level

You can set the log level either during initialization or after creating the ZSMConfig object:

// Option 1: During initialization via JSON
let config = ZSMConfig(json: [
    "host_url": hostUrl,
    "application_id": applicationId,
    "consumer_id": consumerId,
    "log_level": LogLevel.trace.rawValue // Set log level in the configuration
])

// Option 2: After initialization
config.logLevel = .trace

Custom Logging Implementation

You can provide a custom logging function to capture and process log messages in your application:

// Set custom logging function
config.logFunction = { level, message in
    // Format and route logs as needed
    let formattedMessage = "[\(level)] \(message)"
    
    switch level {
    case .trace:
        os_log("%{public}@", log: .default, type: .debug, formattedMessage)
    case .debug:
        os_log("%{public}@", log: .default, type: .debug, formattedMessage)
    case .info:
        os_log("%{public}@", log: .default, type: .info, formattedMessage)
    case .warn:
        os_log("%{public}@", log: .default, type: .error, formattedMessage)
    case .error, .fatal:
        os_log("%{public}@", log: .default, type: .fault, formattedMessage)
    @unknown default:
        os_log("%{public}@", log: .default, type: .default, formattedMessage)
    }
}

The logging function is called with two parameters:

  • level: A LogLevel enum value indicating the severity
  • message: The log message as a String

You can use this callback to integrate with various logging frameworks such as:

  • Apple's unified logging system (os_log)
  • CocoaLumberjack
  • Custom logging solutions

LogLevel Enum

enum LogLevel: Int {
    case trace = -1
    case debug = 0
    case info = 1
    case warn = 2
    case error = 3
    case fatal = 4
}

LogLevel Descriptions

LevelDescription
LogLevelTraceUsed for debugging purposes. Provides the most granular information at the lowest detailed level, including network round trips.
LogLevelDebugProvides general timing information for debugging purposes.
LogLevelInfoUsed for recording informational messages that highlight the application's progress at a high level.
LogLevelWarnIndicates potentially harmful situations.
LogLevelErrorUsed for recording error events that might still allow the application to continue running.
LogLevelFatalUsed for recording severe error events that will presumably lead the application to abort.

Returns
The initialized ZSMConfig object.

Objective-C

Initialization

Usage

NSURL *hostUrl = [NSURL URLWithString:@"https://zsm-host-server-address"];
NSString *applicationId = @"########-####-####-####-############"
NSString *consumerId = @"consumer123";

ZSMConfig *config = [[ZSMConfig alloc] initWithJSON:@{@"host_url": hostUrl, @"application_id":applicationId,
@"consumer_id":consumerId}];

config.logLevel = LogLevelDebug;
config.logFunction = ^(LogLevel level, NSString *message) {
    NSLog(@"[%ld] %@", (long)level, message);
};

FIDO2Client *client = [[FIDO2Client alloc] initWithConfig:config];

Returns The initialized FIDO2Client instance.

Configuration Parameters

Initialize the ZSMConfig object with the required configuration.

Parameters

Parameter NameData TypeDescriptionDefault Value
host_urlNSURL *The URL of the ZSM server.Required
application_idNSString *Unique application identifier.Required
consumer_idNSString *The consumer identifier.Required
application_environmentNSString *The environment name (e.g., "TEST", "PROD").Required, "TEST"
request_timeout_msNSUIntegerNetwork timeout while performing remote transactions (in milliseconds).30000 (30s)
retry_countNSUIntegerNumber of retries for network transactions.0
perform_network_health_checkBOOLWhether to perform a health check prior to instantiation.YES
headersNSDictionary *Headers used while performing remote transactions.nil
metadataNSDictionary *Metadata used while performing remote transactions.nil
keychain_groupNSString *Shared keychain group ID for multiple applications of the same vendor.nil
mpc_algorithmMPCAlgorithmThe encryption algorithm for transactions..MPCAlgorithmECDSAP256
requires_biometricsBOOLWhether to bypass biometrics (assuming implementation outside the API).NO
log_levelLogLevelThe logging level for the API..LogLevelInfo
log_functionZSMLoggingCallbackA callback function for custom log handling.nil

LogLevel Enum

typedef NS_ENUM(NSInteger, LogLevel) {
    LogLevelTrace = -1,
    LogLevelDebug = 0,
    LogLevelInfo,
    LogLevelWarn,
    LogLevelError,
    LogLevelFatal
};

Configuring Logging

The ZSM SDK provides flexible logging configuration options for Objective-C applications. You can set the log level and provide a custom logging implementation to route log messages to your application's logging infrastructure.

Setting Log Level

You can set the log level either during initialization or after creating the ZSMConfig object:

// Option 1: During initialization via JSON dictionary
NSDictionary *configDict = @{
    @"host_url": hostUrlString,
    @"application_id": applicationId,
    @"consumer_id": consumerId,
    @"log_level": @(LogLevelTrace)  // Set log level in the configuration
};
ZSMConfig *config = [[ZSMConfig alloc] initWithJSON:configDict];

// Option 2: After initialization
config.logLevel = LogLevelTrace;

Custom Logging Implementation

You can provide a custom logging function to capture and process log messages in your application:

// Set custom logging function with a block
config.logFunction = ^(LogLevel level, NSString *message) {
    // Format and route logs as needed
    NSString *levelString;
    switch (level) {
        case LogLevelTrace:
            levelString = @"TRACE";
            break;
        case LogLevelDebug:
            levelString = @"DEBUG";
            break;
        case LogLevelInfo:
            levelString = @"INFO";
            break;
        case LogLevelWarn:
            levelString = @"WARN";
            break;
        case LogLevelError:
            levelString = @"ERROR";
            break;
        case LogLevelFatal:
            levelString = @"FATAL";
            break;
        default:
            levelString = @"UNKNOWN";
            break;
    }
    
    NSString *formattedMessage = [NSString stringWithFormat:@"[%@] %@", levelString, message];
    
    // Route to your logging system
    NSLog(@"%@", formattedMessage);
    
    // Or use os_log if targeting iOS 10+
    if (@available(iOS 10.0, *)) {
        os_log_with_type(OS_LOG_DEFAULT, OS_LOG_TYPE_INFO, "%{public}@", formattedMessage);
    }
};

The logging function is called with two parameters:

  • level: A LogLevel enum value indicating the severity
  • message: The log message as an NSString

You can use this callback to integrate with various logging frameworks such as:

  • NSLog (basic logging)
  • Apple's unified logging system (os_log)
  • CocoaLumberjack
  • Custom logging solutions

LogLevel Enum

typedef NS_ENUM(NSInteger, LogLevel) {
    LogLevelTrace = -1,
    LogLevelDebug = 0,
    LogLevelInfo,
    LogLevelWarn,
    LogLevelError,
    LogLevelFatal
};

LogLevel Descriptions

LevelDescription
LogLevelTraceUsed for debugging purposes. Provides the most granular information at the lowest detailed level, including network round trips.
LogLevelDebugProvides general timing information for debugging purposes.
LogLevelInfoUsed for recording informational messages that highlight the application's progress at a high level.
LogLevelWarnIndicates potentially harmful situations.
LogLevelErrorUsed for recording error events that might still allow the application to continue running.
LogLevelFatalUsed for recording severe error events that will presumably lead the application to abort.

Returns
The initialized ZSMConfig object.