Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.

Commit 8d86501

Browse files
Added getSigningCertificateFingerprint
1 parent 1b58ba1 commit 8d86501

File tree

6 files changed

+62
-18
lines changed

6 files changed

+62
-18
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ As stated before, this plugin is all about user authentication and identity, so
274274
- A: Make sure you are using a Virtual Device running with a **Google APIs target and/or a Google APIs CPU**!
275275

276276
## 10. Changelog
277+
- 5.0.3: Added the convenience method `getSigningCertificateFingerprint` to retrieve the Android cert fingerprint which is required in the Google Developer Console.
277278
- 5.0.2: Require linking against `SafariServices` and `CoreText` frameworks on iOS as per Google's recommendation. Added `loginHint` on iOS.
278279
- 5.0.0: Android GoogleSignIn SDK (See #193), iOS SDK 4.0.0, iOS compatibility with Facebook authentication plugins, added `familyName` and `givenName`.
279280
- 4.0.8: Fix for Android 6 where it would crash while asking for permission. Thx #166!

Diff for: demo/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ <h1>Google+</h1>
2929
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
3030
<button onclick="disconnect()">Disconnect</button>
3131
<br/><br/>
32+
<button onclick="window.plugins.googleplus.getSigningCertificateFingerprint(function(res){alert(res)}, function(res){alert(res)})">get cert fingerprint (Android)</button>
3233
</div>
3334
</div>
3435
<script type="text/javascript" src="cordova.js"></script>

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "5.0.2",
2+
"version": "5.0.3",
33
"name": "cordova-plugin-googleplus",
44
"cordova_name": "Google SignIn",
55
"description": "Use your Google account to authenticate with the app.",

Diff for: plugin.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
id="cordova-plugin-googleplus"
5-
version="5.0.2">
5+
version="5.0.3">
66

77
<name>Google SignIn</name>
88

Diff for: src/android/GooglePlus.java

+54-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package nl.xservices.plugins;
22

33
import android.content.Intent;
4+
import android.content.pm.PackageInfo;
5+
import android.content.pm.PackageManager;
46
import android.util.Log;
57

68
import com.google.android.gms.auth.api.Auth;
@@ -17,6 +19,9 @@
1719
import org.json.JSONException;
1820
import org.json.JSONObject;
1921

22+
import java.security.MessageDigest;
23+
import android.content.pm.Signature;
24+
2025
/**
2126
* Originally written by Eddy Verbruggen (http://github.com/EddyVerbruggen/cordova-plugin-googleplus)
2227
* Forked/Duplicated and Modified by PointSource, LLC, 2016.
@@ -28,6 +33,7 @@ public class GooglePlus extends CordovaPlugin implements GoogleApiClient.OnConne
2833
public static final String ACTION_TRY_SILENT_LOGIN = "trySilentLogin";
2934
public static final String ACTION_LOGOUT = "logout";
3035
public static final String ACTION_DISCONNECT = "disconnect";
36+
public static final String ACTION_GET_SIGNING_CERTIFICATE_FINGERPRINT = "getSigningCertificateFingerprint";
3137

3238
//String options/config object names passed in to login and trySilentLogin
3339
public static final String ARGUMENT_WEB_CLIENT_ID = "webClientId";
@@ -50,22 +56,23 @@ public void initialize(CordovaInterface cordova, CordovaWebView webView) {
5056
public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext) throws JSONException {
5157
this.savedCallbackContext = callbackContext;
5258

53-
//pass args into api client build
54-
buildGoogleApiClient(args.optJSONObject(0));
55-
56-
Log.i(TAG, "Determining command to execute");
57-
5859
if (ACTION_IS_AVAILABLE.equals(action)) {
5960
final boolean avail = true;
6061
savedCallbackContext.success("" + avail);
6162

6263
} else if (ACTION_LOGIN.equals(action)) {
64+
//pass args into api client build
65+
buildGoogleApiClient(args.optJSONObject(0));
66+
6367
// Tries to Log the user in
6468
Log.i(TAG, "Trying to Log in!");
6569
cordova.setActivityResultCallback(this); //sets this class instance to be an activity result listener
6670
signIn();
6771

6872
} else if (ACTION_TRY_SILENT_LOGIN.equals(action)) {
73+
//pass args into api client build
74+
buildGoogleApiClient(args.optJSONObject(0));
75+
6976
Log.i(TAG, "Trying to do silent login!");
7077
trySilentLogin();
7178

@@ -77,6 +84,9 @@ public boolean execute(String action, CordovaArgs args, CallbackContext callback
7784
Log.i(TAG, "Trying to disconnect the user");
7885
disconnect();
7986

87+
} else if (ACTION_GET_SIGNING_CERTIFICATE_FINGERPRINT.equals(action)) {
88+
getSigningCertificateFingerprint();
89+
8090
} else {
8191
Log.i(TAG, "This action doesn't exist");
8292
return false;
@@ -90,20 +100,16 @@ public boolean execute(String action, CordovaArgs args, CallbackContext callback
90100
* @param clientOptions - the options object passed in the login function
91101
*/
92102
private synchronized void buildGoogleApiClient(JSONObject clientOptions) throws JSONException {
93-
//If options have been passed in, they could be different, so force a rebuild of the client
94-
if (clientOptions != null) {
95-
// disconnect old client iff it exists
96-
if (this.mGoogleApiClient != null) this.mGoogleApiClient.disconnect();
97-
// nullify
98-
this.mGoogleApiClient = null;
99-
}
100-
101-
//determine the state of the GoogleApiClient
102-
if (this.mGoogleApiClient != null) {
103-
//don't go any further. client is already built.
103+
if (clientOptions == null) {
104104
return;
105105
}
106106

107+
//If options have been passed in, they could be different, so force a rebuild of the client
108+
// disconnect old client iff it exists
109+
if (this.mGoogleApiClient != null) this.mGoogleApiClient.disconnect();
110+
// nullify
111+
this.mGoogleApiClient = null;
112+
107113
Log.i(TAG, "Building Google options");
108114

109115
// Make our SignIn Options builder.
@@ -316,4 +322,36 @@ private void handleSignInResult(GoogleSignInResult signInResult) {
316322
}
317323
}
318324
}
325+
326+
private void getSigningCertificateFingerprint() {
327+
String packageName = webView.getContext().getPackageName();
328+
int flags = PackageManager.GET_SIGNATURES;
329+
PackageManager pm = webView.getContext().getPackageManager();
330+
try {
331+
PackageInfo packageInfo = pm.getPackageInfo(packageName, flags);
332+
Signature[] signatures = packageInfo.signatures;
333+
byte[] cert = signatures[0].toByteArray();
334+
335+
String strResult = "";
336+
MessageDigest md;
337+
md = MessageDigest.getInstance("SHA1");
338+
md.update(cert);
339+
for (byte b : md.digest()) {
340+
String strAppend = Integer.toString(b & 0xff, 16);
341+
if (strAppend.length() == 1) {
342+
strResult += "0";
343+
}
344+
strResult += strAppend;
345+
strResult += ":";
346+
}
347+
// strip the last ':'
348+
strResult = strResult.substring(0, strResult.length()-1);
349+
strResult = strResult.toUpperCase();
350+
this.savedCallbackContext.success(strResult);
351+
352+
} catch (Exception e) {
353+
e.printStackTrace();
354+
savedCallbackContext.error(e.getMessage());
355+
}
356+
}
319357
}

Diff for: www/GooglePlus.js

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ GooglePlus.prototype.disconnect = function (successCallback, errorCallback) {
2121
cordova.exec(successCallback, errorCallback, "GooglePlus", "disconnect", []);
2222
};
2323

24+
GooglePlus.prototype.getSigningCertificateFingerprint = function (successCallback, errorCallback) {
25+
cordova.exec(successCallback, errorCallback, "GooglePlus", "getSigningCertificateFingerprint", []);
26+
};
27+
2428
GooglePlus.install = function () {
2529
if (!window.plugins) {
2630
window.plugins = {};

0 commit comments

Comments
 (0)