Authentication with ReactiveCocoa

I am building an application on top of ReactiveCocoa and Octokit.objC (github library). As part of my efforts, I use Octokits ReactiveCocoa signals to access resources that require authentication. Previous question ' Retrying an asynchronous operation using ReactiveCocoa does a good job of when the user wants to "repeat the asynchronous operation" once . I am trying to figure out how to handle a case where you can repeat several times.

In my specific case, if authentication fails, I want to contact the user for their credentials. I will either ask the user for their credentials several times (2 or 3), and then stop if they fail, or I will just ask them for their credentials until they succeed.

Any help would be greatly appreciated. Thanks - AYAL

0
ios reactive-cocoa
source share
1 answer

There is a statement called -retry: that takes a count parameter. If you apply this operator to a signal, and this signal returns an error, it will re-subscribe to the signal (up to the specified number of times) when an error is received. So you need a signal that asks for user credentials when subscribing.

 @weakify(self); RACSignal *requestCredentials = [RACSignal defer:^{ @strongify(self); // (Prompt the user for credentials.) if (successful) { self.cachedCredentials = credentials; return [self authenticate:credentials]; } else { return [RACSignal error:[[MyError alloc] init]]; } }]; // We try to authenticate using the cached credentials (the // `-authenticate:` method returns a signal that attempts // authentication when it is subscribed to). If the initial // attempt to authenticate fails, we try 3 times to get the // user to enter the correct credentials. return [[self authenticate:self.cachedCredentials] catchTo:[requestCredentials retry:3]]; 
+2
source share

All Articles