プライバシーポリシー
データ処理とセキュリティ契約
Podfile:pod 'ClientAttestation', :podspec => './SDK'
pod install
Info.Plist PermissionInfo.plist file to ensure the SDK can perform normal network communication:<key>NSAppTransportSecurity</key><dict><key>NSAllowsArbitraryLoads</key><true/></dict>If your application needs to access the Internet, please ensure this permission is declared.<key>NSInternetPermission</key><true/>
NSAllowsArbitraryLoads setting allows application loading of non-HTTPS resources. In a production environment, strongly recommend configuring ATS exceptions to only allow necessary domains via HTTPS to enhance security.AppDelegate or at application startup.import ClientAttestationfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {// SDK initializationlet baseUrl = "www.example.com" // set to business domainlet basOptions = TCBasOptions()basOptions.baseUrl = baseUrlbasOptions.logLevel = LOG_LEVEL_DEBUG // Optional, set log levelTCBas.initialize(with: basOptions)return true}
baseUrl: Your EdgeOne service domain name, such as www.example.com.logLevel: Optional parameter used to control the SDK log output level. Optional values include:LOG_LEVEL_NONE: Disable logs (default)LOG_LEVEL_DEBUG: Enable logs at debug level and aboveLOG_LEVEL_INFO: Enable logs at info level and aboveLOG_LEVEL_WARN: Enable logs at warning level and aboveLOG_LEVEL_ERROR: Enable logs at error level and above// Start the client attestation engine[[ClientAttestation sharedInstance] start];
WKWebView) as needed and compute the attestation token. This is done via the attestWithParams() method provided by the SDK.// attestId// Get from console when actively initiating a challenge// Retrieve from the 'EO-Attest-Challenge' header field in the http response when passively triggering a ChallengeNSString *attestId = @"your-attestId";AttestParams *params = [[AttestParams alloc] init];params.attestId = attestId;params.webView = webView; // WebView used for Captcha displayparams.reqTimeoutMillis = 60000; // Optional, request timeout[[ClientAttestation sharedInstance] attestWithParams:paramscallback:self];// Implement the AttestCallbackDelegate protocol#pragma mark - AttestCallbackDelegate- (void)onSuccess:(NSString *)token {// Return the risk invoice, place the invoice in the header field 'EO-Attest-Token' of the http request}- (void)onError:(NSError *)error {// Error message returned}
attestId: Configure the challenge ID, get from console or return in request result.webView: optional parameter, a WKWebView instance. When the authenticator requires user interaction (such as Captcha), you must provide this parameter. If UI interaction is not required, the WKWebView can be hidden.reqTimeoutMillis: Optional parameter to set request timeout in milliseconds. Default is 60 seconds.getAttestationToken() method provided by the SDK to readily obtain the current valid attestation token.attestWithParams(), the SDK generates or updates the attestation token. Before attaching the token to request headers, be sure to call getAttestationToken() again to get the latest token. Each time you need to use token data, please retrieve new token data. Do not save or reuse the token data returned by getAttestationToken().// Get client attestation invoiceNSString *attestToken = [[ClientAttestation sharedInstance] getAttestationToken];// Example: Add the token to your network request header// Assuming you are using URLSession or another network libraryif (attestToken) {// Your request objectNSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://your-backend-api.com/data"]];[request setValue:attestToken forHTTPHeaderField:@"EO-Attest-Token"];// Continue sending the request}
// Assume your network request processing 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 error: %@", error.localizedDescription);return;}NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;if (httpResponse.statusCode == 428) {// Received 428 challenge, extract challenge IDNSString *challengeId = httpResponse.allHeaderFields[@"EO-Attest-Challenge"];if (challengeId) {NSLog(@"Received 428 challenge, challenge ID: %@", challengeId);// Execute attestation challenge// Create or reuse a WKWebView instance as neededWKWebView *webView = [[WKWebView alloc] init];AttestParams *attestParams = [[AttestParams alloc] init];attestParams.attestId = challengeId;attestParams.webView = webView;[[ClientAttestation sharedInstance] attestWithParams:attestParams callback:self];// Note: Need to process the AttestCallbackDelegate callback and resend the request in onSuccess} else {NSLog(@"428 EO-Attest-Challenge header not found in response");}} else if (httpResponse.statusCode == 200) {NSLog(@"Request succeeded.");// Process business data} else {NSLog(@"Request failed, status code: %ld", (long)httpResponse.statusCode);// fix 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 Success, obtain new token: %@", token);// Resend the original request with the new token// Need to get the previous request object and resend// For example:// NSMutableURLRequest *retryRequest = [self.lastFailedRequest mutableCopy]; // Assume you saved the last failed request// [retryRequest setValue:token forHTTPHeaderField:@"EO-Attest-Token"];// [self sendAPIRequest:retryRequest];}- (void)onError:(NSError *)error {NSLog(@"attestation challenge failure: %@", error.localizedDescription);}
WKWebView for Interactive Attestation (And JS Attestation)WKWebView (iOS platform) is the key component to implement these features.WKWebView instance to be provided when calling the attestWithParams() method. This means developers must allocate a WKWebView instance in advance in the application and pass it as an argument to the SDK when calling the attestation API.WKWebView instance to render their interactive interface. The WKWebView instance will display the CAPTCHA page within the application, so it must be preset to ensure correct display.WKWebView instance as the JavaScript runtime environment, primarily for executing encrypted Proof of Work (PoW) challenges. In this case, the WKWebView instance provides only a JavaScript execution sandbox, with no need to visibly render any UI. Therefore, the passed-in WKWebView instance does not need to be visible, and the SDK will not use it for UI rendering.フィードバック