Implementing client-side components for native iOS
We can implement client-side components for custom device provisioning in native iOS.
For more information about the prerequisites, see Implementing client-side components for custom device provisioning.
To implement client-side components for custom device provisioning, complete the following steps.
- Create a MobileFirst native API application for iOS.
- Configure the application for the Application Authenticity test. The authenticity test works only with MPF Consumer Edition and IBM MobileFirst Platform Foundation Enterprise Edition. For more information about application authenticity, see MobileFirst application authenticity overview.
- Create an iOS native application and use the wlConnectWithDelegate function to connect to the server.
- For the wlConnectWithDelegate function to trigger authentication, specify the MobileFirst native API application as a protected resource by adding a custom security test or mobile security test in the application descriptor.
<nativeIOSApp securityTest="MySecurityTest" version="1.0">
- Add a new class CustomChallengeHandlerand register it in the main using [[WLClient sharedInstance] registerChallengeHandler:[customChallengeHandler initWithRealm:@"wl_myCustomProvisioningRealm"]].
- Implement the following methods, required by the challenge handler for device provisioning.
- createCustomCsr(challenge)
- This method is responsible for returning custom properties that are added to the certificate signing request (CSR). Add a custom activationCode property, used in the adapter's validateCSR function.
- handleSuccess(identity)
- This method is called when certificate validation is successfully completed by the validateCertificate adapter function.
- handleFailure()
- This method is called when certificate validation fails. We must call clearDeviceProvisioningCertificate() from this method to delete the stored certificate on the device.
Here is a sample implementation of a challenge handler for custom device provisioning:
@interface CustomChallengeHandler : BaseProvisioningChallengeHandler <WLDelegate>{ @private ViewController *vc; } - (id)initWithController: (ViewController *)mainView; - (void) createCustomCsr : (NSDictionary *) challenge; @property (nonatomic, strong)NSString *passcode; @end @implementation CustomChallengeHandler - (id)initWithController: (ViewController *) mainView{ if ( self = [super init] ) { vc = mainView; } return self; } -(void) createCustomCsr : (NSDictionary *) challenge { [vc updateMessage:@"\nCreating custom Csr"]; [vc updateMessage:[NSString stringWithFormat:@"\t Passcode :: %@", self.passcode] NSMutableDictionary* answer =[[NSMutableDictionary alloc] init]; [answer setValue:self.passcode forKey:@"activationCode"]; [self submitCsr:answer :challenge]; } -(void)onSuccess:(WLResponse *)response { [vc updateMessage:@"Device authentication with custom device provisioning was successfully completed"]; [vc updateMessage:response.description]; } -(void)onFailure:(WLFailResponse *)response{ [vc updateMessage:@"Server has rejected the device. We must reinstall the application and perform device provisioning again."]; [vc updateMessage:response.description]; } @end
Results
We have implemented client-side components for custom device provisioning in native iOS.
What to do next
We can implement server-side components for custom device provisioning. See Implementing server-side components for custom device provisioning. For more information about custom device provisioning, see the tutorial on the Get Started page.
Parent topic: Implementing client-side components for custom device provisioning