We have an "iPhone" environment in our Worklight project that we use for our native iOS client development in XCode 5. We are getting an authentication error, despite having App Authentication disabled in the Worklight console.
The steps we're following are:
- Call
wlConnectWithDelegate:
method onWLClient sharedInstance
- On success from
wlConnectWithDelegate
, we invoke our adapter procedure withinvokeProcedure:withDelegate:
The code looks like this:
#import <BlocksKit/A2DynamicDelegate.h>
+ (void) connectToWorklightOnSuccess: (SuccessBlock) success onFailure: (FailureBlock) failure {
WLClient *client = [WLClient sharedInstance];
A2DynamicDelegate *dd = [client dynamicDelegateForProtocol: @protocol(WLDelegate) ];
[dd implementMethod: @selector(onSuccess:) withBlock: success];
[dd implementMethod: @selector(onFailure:) withBlock: failure];
[client wlConnectWithDelegate:(id <WLDelegate>)dd];
}
+ (void) invokeProcedure: (WLProcedureInvocationData *) proc onSuccess: (SuccessBlock) success onFailure: (FailureBlock) failure {
[WJServiceGateway connectToWorklightOnSuccess:^(WLResponse *response) {
NSLog(@"WLClient connect succeeded");
WLClient *client = [WLClient sharedInstance];
A2DynamicDelegate *dd = [client dynamicDelegateForProtocol: @protocol(WLDelegate) ];
[dd implementMethod: @selector(onSuccess:) withBlock: success];
[dd implementMethod: @selector(onFailure:) withBlock: failure];
[client invokeProcedure:proc withDelegate:(id<WLDelegate>) dd];
} onFailure:^(WLFailResponse *failResponse) {
NSLog(@"WLClient connect failed: %@", failResponse);
[failure invoke];
}];
}
The first time we our invokeProcedure:onSuccess:onFailure:
method, we get an error response:
Status: 403
InvocationResult: (null)
InvocationContext: (null)
Response text: /*-secure-
{"WL-Authentication-Failure":{"wl_antiXSRFRealm":{"reason":"illegal state"}}}*/
Error code: 0
Error message: (null)
Subsequent calls succeed without error until the App is killed and restarted.
This issue may be related to these issues (in fact, this is a problem happening in the same project):
- IBM Worklight - How to enable App Authenticity in a native iOS app?
- https://stackoverflow.com/questions/18879189/wl-5-0-6-1-js-vs-ios-native-handlechallenge-queued-in-waitlist-and-only-cal
What seems peculiar though, is that we have App Authentication disabled (with the drop-down option in the Worklight console) and are still seeing an authentication error. Is there some other source for this WL-Authentication-Failure/"illegal state" response?
Are we implementing something with our connect and invoke incorrectly here? Is there a solution such that our first adapter invoke after the app starts up doesn't fail?
As mentioned in the comments, this is not related to Application Authenticity Protection.
You need to first invoke a connect to the Worklight Server, and in its success callback to invoke the adapter procedure
You could also only connect to the Worklight Server on application launch, and later on when required to perform the adapter procedure invocation.
For a working example of connect and invoke in a native iOS app, see the following tutorial and sample: https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-6-3/server-side-development/invoking-adapter-procedures-native-ios-applications/