Skip to content
This repository has been archived by the owner on Aug 25, 2018. It is now read-only.

Commit

Permalink
Switched out Google+ login with generic Google login
Browse files Browse the repository at this point in the history
  • Loading branch information
asciimike committed Jul 7, 2015
1 parent fc528cc commit 2db4182
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 60 deletions.
2 changes: 2 additions & 0 deletions Login Demo/AppDelegate.h
Expand Up @@ -7,6 +7,8 @@
//

#import <UIKit/UIKit.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <Google/SignIn.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

Expand Down
16 changes: 10 additions & 6 deletions Login Demo/AppDelegate.m
Expand Up @@ -7,8 +7,6 @@
//

#import "AppDelegate.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <GooglePlus/GooglePlus.h>

@interface AppDelegate ()

Expand All @@ -19,6 +17,13 @@ @implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.

// Configure Google SignIn
NSError* configureError;
[[GGLContext sharedInstance] configureWithError: &configureError];
NSAssert(!configureError, @"Error configuring Google services: %@", configureError);

// Return successful Facebook SDK Install
return [[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
}
Expand Down Expand Up @@ -54,11 +59,10 @@ - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceAppl
sourceApplication:sourceApplication
annotation:annotation];
} else {
return [GPPURLHandler handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
return [[GIDSignIn sharedInstance] handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
}


@end
57 changes: 39 additions & 18 deletions Login Demo/Info.plist
Expand Up @@ -2,24 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Dummy</key>
<string>NOTE: Expand the URL types below and configure &quot;&lt;YOUR FACEBOOK APP ID&gt;&quot;</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.firebase.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.firebase.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>fb&lt;YOUR FACEBOOK APP ID&gt;</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>&lt;YOUR FACEBOOK APP ID&gt;</string>
<key>FacebookDisplayName</key>
<string>&lt;YOUR FACEBOOK APP DISPLAY NAME&gt;</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Expand All @@ -36,8 +18,47 @@
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>com.firebase.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.firebase.$(PRODUCT_NAME:rfc1034identifier)</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>FacebookURL</string>
<key>CFBundleURLSchemes</key>
<array>
<string>fb&lt;YOUR FACEBOOK APP ID&gt;</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>GoogleURL</string>
<key>CFBundleURLSchemes</key>
<array>
<string>&lt;YOUR GOOGLE REVERSE CLIENT ID&gt;</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>Dummy</key>
<string>NOTE: Expand the URL types below and configure &quot;&lt;YOUR FACEBOOK APP ID&gt;&quot;</string>
<key>FacebookAppID</key>
<string>&lt;YOUR FACEBOOK APP ID&gt;</string>
<key>FacebookDisplayName</key>
<string>&lt;YOUR FACEBOOK APP DISPLAY NAME&gt;</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
Expand Down
8 changes: 6 additions & 2 deletions Login Demo/ViewController.h
Expand Up @@ -7,9 +7,13 @@
//

#import <UIKit/UIKit.h>
#import <GooglePlus/GooglePlus.h>
#import <Google/SignIn.h>
#import <Accounts/Accounts.h>
#import <Firebase/Firebase.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>

@interface ViewController : UIViewController<GPPSignInDelegate, UIActionSheetDelegate>
@interface ViewController : UIViewController<UIActionSheetDelegate, GIDSignInDelegate, GIDSignInUIDelegate>

@end

60 changes: 27 additions & 33 deletions Login Demo/ViewController.m
Expand Up @@ -7,24 +7,18 @@
//

#import "ViewController.h"

#import <Accounts/Accounts.h>
#import <Firebase/Firebase.h>
#import <GoogleOpenSource/GoogleOpenSource.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>

#import "TwitterAuthHelper.h"

// The Firebase you want to use for this app
// You must setup Firebase Login for the various authentication providers in the Dashboard under Login & Auth.
static NSString * const kFirebaseURL = @"https://<your-firebase>.firebaseio.com";
static NSString * const kFirebaseURL = @"https://<your-firebase-database>.firebaseio.com";

// The twitter API key you setup in the Twitter developer console
static NSString * const kTwitterAPIKey = @"<your-twitter-app-id>";
static NSString * const kTwitterAPIKey = @"<your-twitter-api-key>";

// The Google client ID you setup in the Google developer console
static NSString * const kGoogleClientID = @"<your-google-client-id>";
// NOTE: You must configure Google by dragging "GoogleService-Info.plist" to "Supporting Files".
// You must also configure a URL Schemes to match to match the REVERSED_CLIENT_ID and Bundle Identifier.
// See https://developers.google.com/identity/sign-in/ios/start-integrating for more details.

// NOTE: You must configure Facebook in "Supporting Files/Info.plist".
// You need to set FacebookAppID, FacebookDisplayName, and configure a URL Scheme to match your App ID.
Expand Down Expand Up @@ -112,7 +106,7 @@ - (void)updateUIAndSetCurrentUser:(FAuthData *)currentUser
statusText = [NSString stringWithFormat:@"Logged in as %@ (Twitter)",
currentUser.providerData[@"username"]];
} else if ([currentUser.provider isEqualToString:@"google"]) {
statusText = [NSString stringWithFormat:@"Logged in as %@ (Google+)",
statusText = [NSString stringWithFormat:@"Logged in as %@ (Google)",
currentUser.providerData[@"displayName"]];
} else if ([currentUser.provider isEqualToString:@"anonymous"]) {
statusText = @"Logged in anonymously";
Expand Down Expand Up @@ -201,8 +195,15 @@ - (BOOL)facebookIsSetup

- (BOOL)googleIsSetup
{
if ([@"<your-google-client-id>" isEqualToString:kGoogleClientID]) {
[self showErrorAlertWithMessage:@"Please set kGoogleClientId to your Google Client ID in ViewController.m"];
NSString *path = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info" ofType:@"plist"];
NSDictionary *plist = [NSDictionary dictionaryWithContentsOfFile:path];
NSString *reversedClientId =[plist objectForKey:@"REVERSED_CLIENT_ID"];
BOOL clientIdExists = [plist objectForKey:@"CLIENT_ID"] != nil;
BOOL reversedClientIdExists = reversedClientId != nil;
BOOL canOpenGoogle =[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@://", reversedClientId]]];

if (!(clientIdExists && reversedClientIdExists && canOpenGoogle)) {
[self showErrorAlertWithMessage:@"Please add `GoogleService-Info.plist` to `Supporting Files` and\nURL types > Url Schemes in `Supporting Files/Info.plist`"];
return NO;
} else {
return YES;
Expand All @@ -221,7 +222,7 @@ - (BOOL)twitterIsSetup

- (BOOL)firebaseIsSetup
{
if ([@"https://<your-firebase>.firebaseio.com" isEqualToString:kFirebaseURL]) {
if ([@"https://<your-firebase-database>.firebaseio.com" isEqualToString:kFirebaseURL]) {
[self showErrorAlertWithMessage:@"Please set kFirebaseURL to your Firebase's URL in ViewController.m"];
return NO;
} else {
Expand Down Expand Up @@ -259,7 +260,7 @@ - (void)facebookLogin {
}

/*****************************
* GOOGLE+ *
* GOOGLE *
*****************************/
- (void)googleButtonPressed
{
Expand All @@ -270,31 +271,24 @@ - (void)googleButtonPressed

- (void)googleLogin
{
[self showProgressAlert];
// use the Google+ SDK to get an OAuth token
GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = YES;
signIn.clientID = kGoogleClientID;
signIn.scopes = @[];
signIn.delegate = self;
// authenticate will do a callback to finishedWithAuth:error:
[signIn authenticate];
GIDSignIn *googleSignIn = [GIDSignIn sharedInstance];
googleSignIn.delegate = self;
googleSignIn.uiDelegate = self;
[googleSignIn signIn];
}

- (void)finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error
{
NSLog(@"Received Googl+ authentication response! Error: %@", error);
- (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error {
NSLog(@"Received Google authentication response! Error: %@", error);
if (error != nil) {
// there was an error obtaining the Google+ OAuth token, display a dialog
[self.loginProgressAlert dismissWithClickedButtonIndex:0 animated:YES];
NSString *message = [NSString stringWithFormat:@"There was an error logging into Google+: %@",
// There was an error obtaining the Google OAuth token, display a dialog
NSString *message = [NSString stringWithFormat:@"There was an error logging into Google: %@",
[error localizedDescription]];
[self showErrorAlertWithMessage:message];
} else {
// We successfully obtained an OAuth token, authenticate on Firebase with it
[self.ref authWithOAuthProvider:@"google" token:auth.accessToken withCompletionBlock:[self loginBlockForProviderName:@"Google+"]];
[self.ref authWithOAuthProvider:@"google" token:user.authentication.accessToken withCompletionBlock:[self loginBlockForProviderName:@"Google"]];
}

}

/*****************************
Expand Down
2 changes: 1 addition & 1 deletion Podfile
@@ -1,6 +1,6 @@
# Uncomment this line to define a global platform for your project
platform :ios, '7.0'

pod 'google-plus-ios-sdk', '~> 1.7'
pod 'Google/SignIn', '~> 1.0.7'
pod 'FBSDKLoginKit', '~> 4.1'
pod 'Firebase', '~> 2.2'

0 comments on commit 2db4182

Please sign in to comment.