Add a way to cancel an authorization request
Hi Caleb,
With @kornifex we are facing another issue when our user wants to cancel the authorize request.
Sorry but we don't have time at the moment to fix this issue.
Maybe a simple Block_release on the completion block in the main thread could do the job.
Let me know if you have better idea to handle this. We may come back with a fix later this week.
Thanks for the hard work. Antoine
Hi again,
We have "solved" the issue with the simple trick explained above.
static SimpleAuthProvider *__currentProvider = nil;
static SimpleAuthRequestHandler __currentCompletion = nil;
...
// Keep reference to current completion
__currentCompletion = completion;
// Create the provider and run authorization
__currentProvider = [(SimpleAuthProvider *)[klass alloc] initWithOptions:resolvedOptions];
[__currentProvider authorizeWithCompletion:^(id responseObject, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (__currentCompletion) {
__currentCompletion(responseObject, error);
}
});
}];
...
+ (void)cancelPreviousAuthorizationRequest
{
#warning TODO: cancel current provider
if ([NSThread isMainThread]) {
__currentCompletion = nil;
} else {
dispatch_async(dispatch_get_main_queue(), ^{
__currentCompletion = nil;
});
}
}
I'm not a big fan of that solution, because it doesn't handle provider cancellation, I don't know if RAC allow cancellation.
Let me know what you think and I will open a PR if you're OK with that.
Antoine
This really should be supported at the provider level. Simply clearing the main completion block will only prevent your completion from being called. It will not stop network operations or presentation of UI, both of which would be inappropriate after a user has indicated that they want to cancel. RAC does support cancellation, but just as true without RAC, we are talking about canceling multistep processes, sometimes involving 4 or 5 network requests. Let me think about this a bit.