diff --git a/GoogleSignInPlugin/Assets/GoogleSignIn/Editor/GoogleSignInDependencies.xml b/GoogleSignInPlugin/Assets/GoogleSignIn/Editor/GoogleSignInDependencies.xml
index 625d2e51..821e7dc9 100644
--- a/GoogleSignInPlugin/Assets/GoogleSignIn/Editor/GoogleSignInDependencies.xml
+++ b/GoogleSignInPlugin/Assets/GoogleSignIn/Editor/GoogleSignInDependencies.xml
@@ -12,7 +12,7 @@
-
diff --git a/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignIn.h b/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignIn.h
deleted file mode 100644
index 5e77bc10..00000000
--- a/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignIn.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/**
- * Copyright 2017 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#import
-@interface GoogleSignInHandler
- : NSObject
-
-@end
diff --git a/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignIn.h.meta b/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignIn.h.meta
deleted file mode 100644
index 25735784..00000000
--- a/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignIn.h.meta
+++ /dev/null
@@ -1,35 +0,0 @@
-fileFormatVersion: 2
-guid: 62c129704e1ec48179ba285e1af154b8
-labels:
-- gvh
-timeCreated: 1510357716
-licenseType: Pro
-PluginImporter:
- serializedVersion: 2
- iconMap: {}
- executionOrder: {}
- isPreloaded: 0
- isOverridable: 0
- platformData:
- data:
- first:
- Any:
- second:
- enabled: 0
- settings: {}
- data:
- first:
- Editor: Editor
- second:
- enabled: 0
- settings:
- DefaultValueInitialized: true
- data:
- first:
- iPhone: iOS
- second:
- enabled: 1
- settings: {}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignIn.mm b/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignIn.mm
index 9b82a370..e82393a1 100644
--- a/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignIn.mm
+++ b/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignIn.mm
@@ -14,10 +14,11 @@
* limitations under the License.
*/
#import "GoogleSignIn.h"
-#import
#import
#import
#import
+#import
+#import
#import
@@ -35,6 +36,9 @@
static const int kStatusCodeNetworkError = 8;
static const int kStatusCodeError = 9;
+static NSString *cachedLoginHint = nil;
+static NSArray *cachedAdditionalScopes = nil;
+
/**
* Helper method to pause the Unity player. This is done when showing any UI.
*/
@@ -51,96 +55,14 @@ void UnpauseUnityPlayer() {
struct SignInResult {
int result_code;
bool finished;
+ GIDGoogleUser *user;
+ NSString *serverAuthCode;
};
std::unique_ptr currentResult_;
NSRecursiveLock *resultLock = [NSRecursiveLock alloc];
-@implementation GoogleSignInHandler
-
-/**
- * Overload the presenting of the UI so we can pause the Unity player.
- */
-- (void)signIn:(GIDSignIn *)signIn
- presentViewController:(UIViewController *)viewController {
- UnityPause(true);
- [UnityGetGLViewController() presentViewController:viewController
- animated:YES
- completion:nil];
-}
-
-/**
- * Overload the dismissing so we can resume the Unity player.
- */
-- (void)signIn:(GIDSignIn *)signIn
- dismissViewController:(UIViewController *)viewController {
- UnityPause(false);
- [UnityGetGLViewController() dismissViewControllerAnimated:YES completion:nil];
-}
-
-/**
- * The sign-in flow has finished and was successful if |error| is |nil|.
- * Map the errors from the iOS SDK back to the Android values for consistency's
- * sake in the Unity layer.
- */
-- (void)signIn:(GIDSignIn *)signIn
- didSignInForUser:(GIDGoogleUser *)user
- withError:(NSError *)_error {
- if (_error == nil) {
- if (currentResult_) {
- currentResult_->result_code = kStatusCodeSuccess;
- currentResult_->finished = true;
- } else {
- NSLog(@"No currentResult to set status on!");
- }
- NSLog(@"didSignInForUser: SUCCESS");
- } else {
- NSLog(@"didSignInForUser: %@", _error.localizedDescription);
- if (currentResult_) {
- switch (_error.code) {
- case kGIDSignInErrorCodeUnknown:
- currentResult_->result_code = kStatusCodeError;
- break;
- case kGIDSignInErrorCodeKeychain:
- currentResult_->result_code = kStatusCodeInternalError;
- break;
- case kGIDSignInErrorCodeNoSignInHandlersInstalled:
- currentResult_->result_code = kStatusCodeDeveloperError;
- break;
- case kGIDSignInErrorCodeHasNoAuthInKeychain:
- currentResult_->result_code = kStatusCodeError;
- break;
- case kGIDSignInErrorCodeCanceled:
- currentResult_->result_code = kStatusCodeCanceled;
- break;
- default:
- NSLog(@"Unmapped error code: %ld, returning Error",
- static_cast(_error.code));
- currentResult_->result_code = kStatusCodeError;
- }
-
- currentResult_->finished = true;
- UnpauseUnityPlayer();
- } else {
- NSLog(@"No currentResult to set status on!");
- }
- }
-}
-
-// Finished disconnecting |user| from the app successfully if |error| is |nil|.
-- (void)signIn:(GIDSignIn *)signIn
- didDisconnectWithUser:(GIDGoogleUser *)user
- withError:(NSError *)_error {
- if (_error == nil) {
- NSLog(@"didDisconnectWithUser: SUCCESS");
- } else {
- NSLog(@"didDisconnectWithUser: %@", _error);
- }
-}
-
-@end
-
/**
* These are the external "C" methods that are imported by the Unity C# code.
* The parameters are intended to be primative, easy to marshall.
@@ -168,12 +90,6 @@ bool GoogleSignIn_Configure(void *unused, bool useGameSignIn,
bool requestIdToken, bool hidePopups,
const char **additionalScopes, int scopeCount,
const char *accountName) {
- if (webClientId) {
- [GIDSignIn sharedInstance].serverClientID =
- [NSString stringWithUTF8String:webClientId];
- }
-
- [GIDSignIn sharedInstance].shouldFetchBasicProfile = true;
int scopeSize = scopeCount;
@@ -184,12 +100,11 @@ bool GoogleSignIn_Configure(void *unused, bool useGameSignIn,
[tmpary addObject:[NSString stringWithUTF8String:additionalScopes[i]]];
}
- [GIDSignIn sharedInstance].scopes = tmpary;
+ cachedAdditionalScopes = tmpary;
}
if (accountName) {
- [GIDSignIn sharedInstance].loginHint =
- [NSString stringWithUTF8String:accountName];
+ cachedLoginHint = [NSString stringWithUTF8String:accountName];
}
return !useGameSignIn;
@@ -205,6 +120,8 @@ bool GoogleSignIn_Configure(void *unused, bool useGameSignIn,
currentResult_.reset(new SignInResult());
currentResult_->result_code = 0;
currentResult_->finished = false;
+ currentResult_->user = nil;
+ currentResult_->serverAuthCode = nil;
} else {
busy = true;
}
@@ -220,13 +137,60 @@ bool GoogleSignIn_Configure(void *unused, bool useGameSignIn,
return nullptr;
}
+/**
+* The sign-in flow has finished and was successful if |error| is |nil|.
+* Map the errors from the iOS SDK back to the Android values for consistency's
+* sake in the Unity layer.
+*/
+void HandleSignInError(NSError * _Nullable _error) {
+ NSLog(@"didSignInForUser: %@", _error.localizedDescription);
+ if (currentResult_) {
+ switch (_error.code) {
+ case kGIDSignInErrorCodeUnknown:
+ currentResult_->result_code = kStatusCodeError;
+ break;
+ case kGIDSignInErrorCodeKeychain:
+ currentResult_->result_code = kStatusCodeInternalError;
+ break;
+ case kGIDSignInErrorCodeHasNoAuthInKeychain:
+ currentResult_->result_code = kStatusCodeError;
+ break;
+ case kGIDSignInErrorCodeCanceled:
+ currentResult_->result_code = kStatusCodeCanceled;
+ break;
+ default:
+ NSLog(@"Unmapped error code: %ld, returning Error", static_cast(_error.code));
+ currentResult_->result_code = kStatusCodeError;
+ }
+
+ currentResult_->finished = true;
+ UnpauseUnityPlayer();
+ } else {
+ NSLog(@"No currentResult to set status on!");
+ }
+}
+
/**
* Sign-In. The return value is a pointer to the currentResult object.
*/
void *GoogleSignIn_SignIn() {
SignInResult *result = startSignIn();
if (!result) {
- [[GIDSignIn sharedInstance] signIn];
+ [GIDSignIn.sharedInstance signInWithPresentingViewController:UnityGetGLViewController() hint:cachedLoginHint additionalScopes:cachedAdditionalScopes completion:^(GIDSignInResult * _Nullable _result, NSError * _Nullable _error) {
+ if (_error == nil) {
+ if (currentResult_) {
+ currentResult_->result_code = kStatusCodeSuccess;
+ currentResult_->finished = true;
+ currentResult_->user = _result.user;
+ currentResult_->serverAuthCode = _result.serverAuthCode;
+ } else {
+ NSLog(@"No currentResult to set status on!");
+ }
+ NSLog(@"didSignInForUser: SUCCESS");
+ } else {
+ HandleSignInError(_error);
+ }
+ }];
result = currentResult_.get();
}
return result;
@@ -239,20 +203,40 @@ bool GoogleSignIn_Configure(void *unused, bool useGameSignIn,
void *GoogleSignIn_SignInSilently() {
SignInResult *result = startSignIn();
if (!result) {
- [[GIDSignIn sharedInstance] signInSilently];
+ [GIDSignIn.sharedInstance restorePreviousSignInWithCompletion:^(GIDGoogleUser * _Nullable _user, NSError * _Nullable _error) {
+ if (_error == nil) {
+ if (currentResult_) {
+ currentResult_->result_code = kStatusCodeSuccess;
+ currentResult_->finished = true;
+ currentResult_->user = _user;
+ } else {
+ NSLog(@"No currentResult to set status on!");
+ }
+ NSLog(@"didSignInForUser: SUCCESS");
+ } else {
+ HandleSignInError(_error);
+ }
+ }];
result = currentResult_.get();
}
return result;
}
void GoogleSignIn_Signout() {
- GIDSignIn *signIn = [GIDSignIn sharedInstance];
+ GIDSignIn *signIn = GIDSignIn.sharedInstance;
[signIn signOut];
}
void GoogleSignIn_Disconnect() {
- GIDSignIn *signIn = [GIDSignIn sharedInstance];
- [signIn disconnect];
+ GIDSignIn *signIn = GIDSignIn.sharedInstance;
+ // Finished disconnecting |user| from the app successfully if |error| is |nil|.
+ [signIn disconnectWithCompletion:^(NSError *_Nullable _error) {
+ if (_error == nil) {
+ NSLog(@"didDisconnectWithUser: SUCCESS");
+ } else {
+ NSLog(@"didDisconnectWithUser: %@", _error);
+ }
+ }];
}
bool GoogleSignIn_Pending(SignInResult *result) {
@@ -263,10 +247,9 @@ bool GoogleSignIn_Pending(SignInResult *result) {
return ret;
}
-GIDGoogleUser *GoogleSignIn_Result(SignInResult *result) {
+SignInResult *GoogleSignIn_Result(SignInResult *result) {
if (result && result->finished) {
- GIDGoogleUser *guser = [GIDSignIn sharedInstance].currentUser;
- return guser;
+ return result;
}
return nullptr;
}
@@ -300,46 +283,46 @@ static size_t CopyNSString(NSString *src, char *dest, size_t len) {
return src ? src.length + 1 : 0;
}
-size_t GoogleSignIn_GetServerAuthCode(GIDGoogleUser *guser, char *buf,
+size_t GoogleSignIn_GetServerAuthCode(SignInResult *gresult, char *buf,
size_t len) {
- NSString *val = [guser serverAuthCode];
+ NSString *val = gresult->serverAuthCode;
return CopyNSString(val, buf, len);
}
-size_t GoogleSignIn_GetDisplayName(GIDGoogleUser *guser, char *buf,
+size_t GoogleSignIn_GetDisplayName(SignInResult *gresult, char *buf,
size_t len) {
- NSString *val = [guser.profile name];
+ NSString *val = [gresult->user.profile name];
return CopyNSString(val, buf, len);
}
-size_t GoogleSignIn_GetEmail(GIDGoogleUser *guser, char *buf, size_t len) {
- NSString *val = [guser.profile email];
+size_t GoogleSignIn_GetEmail(SignInResult *gresult, char *buf, size_t len) {
+ NSString *val = [gresult->user.profile email];
return CopyNSString(val, buf, len);
}
-size_t GoogleSignIn_GetFamilyName(GIDGoogleUser *guser, char *buf, size_t len) {
- NSString *val = [guser.profile familyName];
+size_t GoogleSignIn_GetFamilyName(SignInResult *gresult, char *buf, size_t len) {
+ NSString *val = [gresult->user.profile familyName];
return CopyNSString(val, buf, len);
}
-size_t GoogleSignIn_GetGivenName(GIDGoogleUser *guser, char *buf, size_t len) {
- NSString *val = [guser.profile givenName];
+size_t GoogleSignIn_GetGivenName(SignInResult *gresult, char *buf, size_t len) {
+ NSString *val = [gresult->user.profile givenName];
return CopyNSString(val, buf, len);
}
-size_t GoogleSignIn_GetIdToken(GIDGoogleUser *guser, char *buf, size_t len) {
- NSString *val = [guser.authentication idToken];
+size_t GoogleSignIn_GetIdToken(SignInResult *gresult, char *buf, size_t len) {
+ NSString *val = [gresult->user.idToken tokenString];
return CopyNSString(val, buf, len);
}
-size_t GoogleSignIn_GetImageUrl(GIDGoogleUser *guser, char *buf, size_t len) {
- NSURL *url = [guser.profile imageURLWithDimension:128];
+size_t GoogleSignIn_GetImageUrl(SignInResult *gresult, char *buf, size_t len) {
+ NSURL *url = [gresult->user.profile imageURLWithDimension:128];
NSString *val = url ? [url absoluteString] : nullptr;
return CopyNSString(val, buf, len);
}
-size_t GoogleSignIn_GetUserId(GIDGoogleUser *guser, char *buf, size_t len) {
- NSString *val = [guser userID];
+size_t GoogleSignIn_GetUserId(SignInResult *gresult, char *buf, size_t len) {
+ NSString *val = [gresult->user userID];
return CopyNSString(val, buf, len);
}
} // extern "C"
diff --git a/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignInAppController.mm b/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignInAppController.mm
index 33631489..cd56042f 100644
--- a/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignInAppController.mm
+++ b/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignInAppController.mm
@@ -15,11 +15,10 @@
*/
#import "GoogleSignInAppController.h"
+#import
+#import
#import
-// Handles Google SignIn UI and events.
-GoogleSignInHandler *gsiHandler;
-
/*
* Create a category to customize the application. When this is loaded the
* method for the existing application and GoogleSignIn are swizzled into the
@@ -69,14 +68,11 @@ - (BOOL)GoogleSignInAppController:(UIApplication *)application
ofType:@"plist"];
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
NSString *clientId = [dict objectForKey:@"CLIENT_ID"];
-
- gsiHandler = [GoogleSignInHandler alloc];
+ NSString *serverClientID = [dict objectForKey:@"SERVER_CLIENT_ID"];
// Setup the Sign-In instance.
- GIDSignIn *signIn = [GIDSignIn sharedInstance];
- signIn.clientID = clientId;
- signIn.uiDelegate = gsiHandler;
- signIn.delegate = gsiHandler;
+ GIDConfiguration *config = [[GIDConfiguration alloc] initWithClientID:clientId serverClientID:serverClientID];
+ [GIDSignIn.sharedInstance setConfiguration:config];
// looks like it's just calling itself, but the implementations were swapped
// so we're actually calling the original once we're done
@@ -96,9 +92,7 @@ - (BOOL)GoogleSignInAppController:(UIApplication *)application
sourceApplication:sourceApplication
annotation:annotation];
- return [[GIDSignIn sharedInstance] handleURL:url
- sourceApplication:sourceApplication
- annotation:annotation] ||
+ return [GIDSignIn.sharedInstance handleURL:url] ||
handled;
}
@@ -112,12 +106,7 @@ - (BOOL)GoogleSignInAppController:(UIApplication *)app
BOOL handled =
[self GoogleSignInAppController:app openURL:url options:options];
- return [[GIDSignIn sharedInstance]
- handleURL:url
- sourceApplication:
- options[UIApplicationOpenURLOptionsSourceApplicationKey]
- annotation:
- options[UIApplicationOpenURLOptionsAnnotationKey]] ||
+ return [GIDSignIn.sharedInstance handleURL:url] ||
handled;
}