iosfacebooktwitterscringo

Scringo and Parse: how to perform simultaneous Facebook login?


My app allows typical registration (e-mail,username,password, etc), but also enables Facebook/Twitter signup/singin via Parse. If at all possible, I'd like to avoid forcing a user to sign in twice if they sign in with Facebook or Twitter. Currently, I've added "Scringo's" programmatic signup capability to sign users into "scringo" with the same credentials they use for my app; however. What if they sign up with Facebook? It seems very confusing for a user to sign in with say, Facebook, and then slide a bar over, and to access the messaging component to be forced to login with Facebook again.

Here's what I have currently, is there anyway to link the Facebook/Twitter signin process so that both Parse gets the information along with Scringo in the press of one button?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary       *)launchOptions
{

[Parse setApplicationId:@"...gzPI7Omoxc..."
              clientKey:@"...s22ZqIbM7n..."];

[PFTwitterUtils
 initializeWithConsumerKey:@"...W4XjjpHz..."
            consumerSecret:@"...Czjtht7v5..."];

[PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
[PFFacebookUtils initializeFacebook];

[self configureNavigationBar];

[Scringo initWithAppId:@"...N2cCMhW1Bv..." completion:^{
    [Scringo addSidebar:self.window toLeft:YES];
     PFUser *currentUser = [PFUser currentUser];
    if (! [ScringoUser currentUser].isAuthenticated) {
        [ScringoUser signUpWithEmail:currentUser.email userName:currentUser.username password:@"notforyou" completion:^(ScringoUser *aUser, BOOL isSuccess) {
            if (isSuccess) {
                [currentUser setObject:aUser.userId forKey:@"ScringoUserId"];
                [currentUser saveInBackground];
            }
        }];
    }
     }];

return YES;
}

Solution

  • Turns out there is a method in the SDK (I simply overlooked it)

    [Scringo connectFacebook]
    

    If the app has successfully logged into facebook already, calling this authenticates Scringo as well.

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    
    [Parse setApplicationId:@"gzPI7OmoxcSYqQGWASjzVd8lP5q8FVJqh2ZLsXnp"
                  clientKey:@"s22ZqIbM7n8SN1End57vmTmmeL55YnIen7dmMhIR"];
    
    [PFTwitterUtils
     initializeWithConsumerKey:@"W4XjjpHzG03bWK8R0iPvs27Yy"
                consumerSecret:@"Czjtht7v58yfZ00QV5Gkumfdy8RauCyPllYh5SPm00I3M6fkPP"];
    
    [PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
    [PFFacebookUtils initializeFacebook];
    
    [self configureNavigationBar];
    
    [Scringo initWithAppId:@"cvOV3lLwQN2cCMhW1BvnW2eWnyoiLNgA" completion:^{
        [Scringo addSidebar:self.window toLeft:YES];
         PFUser *currentUser = [PFUser currentUser];
        if (! [ScringoUser currentUser].isAuthenticated) {
            if (currentUser) {
                if (currentUser.email) [Scringo connectFacebook];
            else
            [ScringoUser signUpWithEmail:currentUser.email userName:currentUser.username password:@"notforyou" completion:^(ScringoUser *aUser, BOOL isSuccess) {
                if (isSuccess) {
                    [currentUser setObject:aUser.userId forKey:@"ScringoUserId"];
                    [currentUser saveInBackground];
                }
            }];
            }
        }
         }];
    
    return YES;
    }
    

    That's assuming a PFUser already exists, so I also added the same call to the login page for users logging in with facebook for the first time

    - (void)logInViewController:(PFLogInViewController *)logInController didLogInUser:(PFUser *)user {
    [self dismissViewControllerAnimated:YES completion:^{
        if (!self.currentUser.email) [Scringo connectFacebook];
    }];
    }
    

    Tested and working.