Podfile:pod 'ClientAttestation', :podspec => './SDK' // Configuration example, please replace with actual SDK podspec address
pod install
AppDelegate or during application launch.#import <TCBasCommon/TCBasCommon.h>#import <ClientAttestation/ClientAttestation.h>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// SDK initializationTCBasConfig *basConfig = [[TCBasConfig alloc] init];basConfig.baseUrl = @"www.example.com"; // Set to the business domainbasConfig.logLevel = TCBCLogLevelTypeWARN; // Optional. Set the log level[TCBas initializeWithOptions:basConfig];return YES;}
baseUrl: Your EdgeOne service domain, for example www.example.com.logLevel: Optional parameter used to control the log output level of the SDK. Optional values include:TCBCLogLevelTypeNONE: Disable logs (default)TCBCLogLevelTypeVERBOSE: Enable verbose and higher level logs.TCBCLogLevelTypeDEBUG: Enable debug and higher level logs.TCBCLogLevelTypeINFO: Enable info and higher level logs.TCBCLogLevelTypeWARN: Enable warning and higher level logs.TCBCLogLevelTypeERROR: Enable error and higher level logs.extraDataProvider: Optional parameter. Set IDFV to enhance risk identification capabilities.#import <ClientAttestation/ClientAttestation.h>// Start the client authentication engine.[[ClientAttestation sharedInstance] start];
WKWebView) and compute the authentication token. This is accomplished through the attestWithParams() method provided by the SDK.#import <ClientAttestation/ClientAttestation.h>// attestId// Obtain from the console when actively initiating a challenge.// Obtain from the 'EO-Attest-Challenge' header field in the http response when challenges are passively initiated.NSString *attestId = @"your-attestId";AttestParams *params = [[AttestParams alloc] init];params.attestId = attestId;params.webView = self.webView; // WebView used to display the Captcha pageparams.reqTimeoutMillis = 60000; // Optional request timeout[[ClientAttestation sharedInstance] attestWithParams:paramscallback:self];// Implement the AttestCallbackDelegate protocol#pragma mark - AttestCallbackDelegate- (void)onSuccess:(NSString *)token {// Return the risk token and place it in the 'EO-Attest-Token' header field of the http request.}- (void)onError:(NSError *)error {// Error message callback}
attestId: Configure challenge ID, obtain from the console or returned in the request result.webView: Optional parameter, a WKWebView instance. This parameter must be provided when the authenticator requires user interaction (such as Captcha). If no UI interaction is needed, the WKWebView can be hidden.vCodeDispType: Optional parameter, display mode for interactive Captcha UI. Use VCodeDispTypePopup for pop-up full-screen display, VCodeDispTypeFull for embedded display within the page. Default: VCodeDispTypePopup.reqTimeoutMillis: Optional parameter to set the request timeout period, unit: milliseconds, default 60000 milliseconds.getAttestationToken() method provided by the SDK to obtain the currently valid attestation token at any time.attestWithParams() is made, the SDK generates or updates the attestation token. Before the token is attached to the request header, you must call getAttestationToken() again to obtain the latest token. Each time you need to use the token data, retrieve it again. Do not save or reuse the token data returned by getAttestationToken().#import <ClientAttestation/ClientAttestation.h>// Obtain client authentication token[[ClientAttestation sharedInstance] getAttestationTokenWithCompletion:^(NSString *token) {// Example: Add the token to your network request header// Assume you are using URLSession or other networking librariesif (token) {// Your request objectNSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://your-backend-api.com/data"]];[request setValue:token forHTTPHeaderField:@"EO-Attest-Token"];// Continue sending the request}}];
#import <ClientAttestation/ClientAttestation.h>// Assume your network request handling logic- (void)sendAPIRequest:(NSMutableURLRequest *)request {NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {if (error) {NSLog(@"Network request error: %@", error.localizedDescription);return;}NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;if (httpResponse.statusCode == 428) {// Received a 428 challenge, extract the challenge IDNSString *challengeId = httpResponse.allHeaderFields[@"EO-Attest-Challenge"];if (challengeId) {NSLog(@"Received a 428 challenge, challenge ID: %@", challengeId);// Execute the authentication challengeAttestParams *attestParams = [[AttestParams alloc] init];attestParams.attestId = challengeId;attestParams.webView = self.webView;[[ClientAttestation sharedInstance] attestWithParams:attestParams callback:self];// Note: You need to handle the AttestCallbackDelegate callbacks and resend the request in onSuccess.} else {NSLog(@"EO-Attest-Challenge header not found in 428 response");}} else if (httpResponse.statusCode == 200) {NSLog(@"Request succeeded!");// Process business data} else {NSLog(@"Request failed, status code: %ld", (long)httpResponse.statusCode);// Handle other errors}}];[task resume];}// Example call// NSMutableURLRequest *initialRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://your-backend-api.com/protected-data"]];// [self sendAPIRequest:initialRequest];// Resend the request in the onSuccess method of AttestCallbackDelegate.#pragma mark - AttestCallbackDelegate- (void)onSuccess:(NSString *)token {NSLog(@"Challenge succeeded, obtained a new token: %@", token);// Resend the original request with the new token// Obtain the previous request object and resend it// For example:// NSMutableURLRequest *retryRequest = [self.lastFailedRequest mutableCopy]; // assuming you saved the last failed request// [retryRequest setValue:token forHTTPHeaderField:@"EO-Attest-Token"];// [self sendAPIRequest:retryRequest];}- (void)onError:(NSError *)error {NSLog(@"Authentication challenge failed: %@", error.localizedDescription);}
WKWebView for interactive authentication (and JS authentication)WKWebView (iOS platform) is a key component for implementing these features.WKWebView instance to be provided when the attestWithParams() method is called. This means developers must pre-allocate a WKWebView instance in the application and pass it as a parameter to the SDK when invoking the authentication API.WKWebView instance to render their interactive interface. This WKWebView instance will display the CAPTCHA page within the application, thus requiring pre-configuration to ensure proper rendering.WKWebView instance as a JavaScript runtime environment, primarily for executing cryptographic Proof-of-Work (PoW) challenges. In this scenario, the WKWebView instance only provides a JavaScript execution sandbox and does not visibly render any UI. Therefore, the passed WKWebView instance does not need to be visible, and the SDK will not use it for UI rendering.피드백