Skip to content

Commit 2c3f4c5

Browse files
committed
Updates from testing with Firebase integration and README.
Includes changing to xml dependencies file format. Adding method to set debug logging flag in Java code via C#. Added catching exception when configuring and reporting error. Fixed typo in objective C source. Change-Id: I93b0beb612fe02ee53d8da6970395bdb713e3e8d
1 parent 6cb3cd1 commit 2c3f4c5

File tree

15 files changed

+304
-166
lines changed

15 files changed

+304
-166
lines changed

GoogleSignInPlugin/Assets/GoogleSignIn/Editor/GoogleSignInDependencies.cs

Lines changed: 0 additions & 90 deletions
This file was deleted.

GoogleSignInPlugin/Assets/GoogleSignIn/Editor/GoogleSignInDependencies.cs.meta

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<dependencies>
3+
<!-- See https://github.com/googlesamples/unity-jar-resolver#usage for
4+
how to configure dependencies -->
5+
<androidPackages>
6+
<!--- Auth THIS IS ALWAYS REQUIRED -->
7+
<!-- The dependency is actually on 10.2, but 10+ is close enough.
8+
If you have problems, please change this to a concrete value.
9+
-->
10+
<androidPackage spec="com.google.android.gms:play-services-auth:10+">
11+
<androidSdkPackageIds>
12+
<androidSdkPackageId>extra-google-m2repository</androidSdkPackageId>
13+
</androidSdkPackageIds>
14+
</androidPackage>
15+
16+
<!-- IF YOU ARE USING THE GAMES_CONFIG TO SIGN-IN, YOU NEED TO
17+
UNCOMMENT THIS DEPENDENCY!!
18+
19+
This is only used if you need to add play-services-games to your
20+
project.
21+
-->
22+
<!--
23+
<androidPackage spec="com.google.android.gms:play-services-games:10+">
24+
<androidSdkPackageIds>
25+
<androidSdkPackageId>extra-google-m2repository</androidSdkPackageId>
26+
</androidSdkPackageIds>
27+
</androidPackage>
28+
-->
29+
30+
</androidPackages>
31+
32+
<!-- iOS Cocoapod dependencies can be specified by each iosPod element. -->
33+
<iosPods>
34+
<iosPod name="GoogleSignIn" version=">= 4.0.2" bitcodeEnabled="false"
35+
minTargetSdk="6.0">
36+
</iosPod>
37+
</iosPods>
38+
</dependencies>

GoogleSignInPlugin/Assets/GoogleSignIn/Editor/GoogleSignInDependencies.xml.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GoogleSignInPlugin/Assets/GoogleSignIn/GoogleSignIn.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ internal GoogleSignIn(GoogleSignInImpl impl) {
104104
this.impl = impl;
105105
}
106106

107+
public void EnableDebugLogging(bool flag) {
108+
impl.EnableDebugLogging(flag);
109+
}
110+
107111
/// <summary>Starts the authentication process.</summary>
108112
/// <remarks>
109113
/// The authenication process is started and may display account picker
@@ -190,6 +194,7 @@ public GoogleSignInStatusCode Status {
190194
internal interface ISignInImpl {
191195
Future<GoogleSignInUser> SignIn();
192196
Future<GoogleSignInUser> SignInSilently();
197+
void EnableDebugLogging(bool flag);
193198
void SignOut();
194199
void Disconnect();
195200
}

GoogleSignInPlugin/Assets/GoogleSignIn/Impl/GoogleSignInImpl.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ internal GoogleSignInImpl(GoogleSignInConfiguration configuration)
4848
}
4949
}
5050

51+
/// <summary>Enables/Disables verbose logging to help troubleshooting</summary>
52+
public void EnableDebugLogging(bool flag) {
53+
GoogleSignIn_EnableDebugLogging(SelfPtr(), flag);
54+
}
55+
5156
/// <summary>
5257
/// Starts the authentication process.
5358
/// </summary>
@@ -100,6 +105,9 @@ public void Disconnect() {
100105
[DllImport(DllName)]
101106
static extern IntPtr GoogleSignIn_Create(IntPtr data);
102107

108+
[DllImport(DllName)]
109+
static extern void GoogleSignIn_EnableDebugLogging(HandleRef self, bool flag);
110+
103111
[DllImport(DllName)]
104112
static extern bool GoogleSignIn_Configure(HandleRef self,
105113
bool useGameSignIn, string webClientId,

GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignInAppController.mm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ - (void)signIn:(GIDSignIn *)signIn
199199
return NULL;
200200
}
201201

202+
void GoogleSignIn_EnableDebugLogging(void* unused, bool flag) {
203+
if (flag) NSLog(@"GoogleSignIn: No optional logging available on iOS");
204+
}
205+
202206
/**
203207
* Configures the GIDSignIn instance. The first parameter is unused in iOS.
204208
* It is here to make the API between Android and iOS uniform.
@@ -265,7 +269,7 @@ bool GoogleSignIn_Configure(void* unused, bool useGameSignIn,
265269
/**
266270
* Attempt a silent sign-in. Return value is the pointer to the currentResult object.
267271
*/
268-
void *GoogleSignInSilently() {
272+
void *GoogleSignIn_SignInSilently() {
269273
bool busy = false;
270274
[resultLock lock];
271275
if (!currentResult_ || currentResult_->finished) {

README.md

Lines changed: 127 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ This plugin exposes the Google Sign-In API within Unity. This is specifically
88
intended to be used by Unity projects that require OAuth ID tokens or server
99
auth codes.
1010

11+
It is cross-platform, supporting both Android and iOS.
12+
1113
See [Google Sign-In for Android](https://developers.google.com/identity/sign-in/android/start)
1214
for more information.
1315

@@ -20,12 +22,136 @@ or as part of Firebase configuration.
2022
In order to access ID tokens or server auth codes, you also need to configure
2123
a web client ID.
2224

25+
## How to build the sample
26+
27+
28+
### Get a Google Sign-In configuration file
29+
This file contains the client-side information needed to use Google Sign-in.
30+
The details on how to do this are documented on the [Developer website](https://developers.google.com/identity/sign-in/android/start-integrating#get-config).
31+
32+
Once you have the configuration file, open it in a text editor. In the middle
33+
of the file you should see the __oauth_client__ section:
34+
```
35+
"oauth_client": [
36+
{
37+
"client_id": "411000067631-hmh4e210xxxxxxxxxx373t3icpju8ooi.apps.googleusercontent.com",
38+
"client_type": 3
39+
},
40+
{
41+
"client_id": "411000067631-udra361txxxxxxxxxx561o9u9hc0java.apps.googleusercontent.com",
42+
"client_type": 1,
43+
"android_info": {
44+
"package_name": "com.your.package.name.",
45+
"certificate_hash": "7ada045cccccccccc677a38c91474628d6c55d03"
46+
}
47+
}
48+
]
49+
```
50+
51+
There are 3 values you need for configuring your Unity project:
52+
1. The __Web client ID__. This is needed for generating a server auth code for
53+
your backend server, or for generating an ID token. This is the `client_id`
54+
value for the oauth client with client_type == 3.
55+
2. The __package_name__. The client entry with client_type == 1 is the
56+
Android client. The package_name must be entered in the Unity player settings.
57+
3. The keystore used to sign your application. This is configured in the publishing settings of the Android Player properties in
58+
the Unity editor. This must be the same keystore used to generate
59+
the SHA1 fingerprint when creating the application on the console. __NOTE:__
60+
The configutation file does not reference the keystore, you need to keep track of
61+
this yourself.
62+
63+
64+
### Create a new project and import the plugin
65+
Create a new Unity project and import the `GoogleSignIn-1.0.0.unitypackage` (or the latest version).
66+
This contains native code, C# Unity code needed to call the Google Sign-In API for both Android and iOS.
67+
68+
### Import the sample scene
69+
Import the `GoogleSignIn-sample.unitypackage` which contains the sample scene and
70+
scripts. This package is not needed if you are integrating Google Sign-in into
71+
your own application.
72+
73+
### Configure the web client id
74+
1. Open the sample scene in `Assets/SignInSample/MainScene`.
75+
2. Select the Canvas object in the hierarchy and enter the web client id
76+
in the __SignInSampleScript__ component.
77+
78+
## Building for Android
79+
1. Under Build Settings, select Android as the target platform.
80+
2. Set the package name in the player settings to the package_name you found in
81+
the configuration file.
82+
3. Select the keystore file, the key alias, and passwords.
83+
4. Resolve the Google Play Services SDK dependencies by selecting from the menu:
84+
__Assets/Play Services Resolver/Android Resolver/Resolve__. This will add
85+
the required .aar files to your project in `Assets/Plugins/Android`.
86+
87+
## Building for iOS
88+
For iOS, follow the instructions for creating a GoogleService-Info.plist file on
89+
https://developers.google.com/identity/sign-in/ios/start-integrating.
90+
91+
In Unity, after switching to the iOS player, make sure to run the Play Services
92+
Resolver. This will add the required frameworks and libraries to the XCode
93+
project via CocoPods.
94+
95+
After generating the XCode project from Unity, download the GoogleService-Info.plist file
96+
from the Google Developers website and add it to your XCode project.
97+
98+
## Using the Games Profile to sign in on Android
99+
To use the Play Games Services Gamer profile when signing in, you need to edit the
100+
dependencies in `Assets/GoogleSignIn/Editor/GoogleSignInDependencies.xml`.
101+
102+
Uncomment the play-services-games dependency and re-run the resolution.
103+
104+
105+
## Using this plugin with Firebase Auth
106+
Follow the instructions to use Firebase Auth with Credentials on the [Firebase developer website]( https://firebase.google.com/docs/unity/setup).
107+
108+
Make sure to copy the google-services.json and/or GoogleService-Info.plist to your Unity project.
109+
110+
Then to use Google SignIn with Firebase Auth, you need to request an ID token when authenticating.
111+
The steps are:
112+
1. Configure Google SignIn to request an id token and set the web client id as described above.
113+
2. Call __SignIn()__ (or __SignInSilently()__).
114+
3. When handling the response, use the ID token to create a Firebase Credential.
115+
4. Call Firebase Auth method __SignInWithCredential()__.
116+
117+
```
118+
GoogleSignIn.Configuration = new GoogleSignInConfiguration {
119+
RequestIdToken = true,
120+
// Copy this value from the google-service.json file.
121+
// oauth_client with type == 3
122+
WebClientId = "1072123000000-iacvb7489h55760s3o2nf1xxxxxxxx.apps.googleusercontent.com"
123+
};
124+
125+
Task<GoogleSignInUser> signIn = GoogleSignIn.DefaultInstance.SignIn ();
126+
127+
TaskCompletionSource<FirebaseUser> signInCompleted = new TaskCompletionSource<FirebaseUser> ();
128+
signIn.ContinueWith (task => {
129+
if (task.IsCanceled) {
130+
signInCompleted.SetCanceled ();
131+
} else if (task.IsFaulted) {
132+
signInCompleted.SetException (task.Exception);
133+
} else {
134+
135+
Credential credential = Firebase.Auth.GoogleAuthProvider.GetCredential (((Task<GoogleSignInUser>)task).Result.IdToken, null);
136+
auth.SignInWithCredentialAsync (credential).ContinueWith (authTask => {
137+
if (authTask.IsCanceled) {
138+
signInCompleted.SetCanceled();
139+
} else if (authTask.IsFaulted) {
140+
signInCompleted.SetException(authTask.Exception);
141+
} else {
142+
signInCompleted.SetResult(((Task<FirebaseUser>)authTask).Result);
143+
}
144+
});
145+
}
146+
});
147+
```
148+
149+
23150
## Building the Plugin
24151
To build the plugin run `./gradlew build_all`. This builds the support aar
25152
library, and packages the plugin into a .unitypackage file. It also packages the
26153
sample scene and script in a separate package.
27154

28-
__TODO:__ How to use this plugin with Firebase Auth.
29155

30156
## Questions? Problems?
31157
Post questions to this [Github project](https://github.com/googlesamples/google-signin-unity).

native-googlesignin/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ android {
1818
compileSdkVersion 26
1919
buildToolsVersion "25.0.3"
2020
defaultConfig {
21-
minSdkVersion 18
21+
minSdkVersion 14
2222
targetSdkVersion 26
2323
versionCode 1
2424
versionName "1.0"

0 commit comments

Comments
 (0)