Ti.GoogleSignIn is an open-source project to support the Google SignIn SDK in Appcelerator's Titanium.
- Titanium SDK 9.2.0+
- Ti.PlayServices (Android)
Add the following URL types to your plist section of the tiapp.xml:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>google</string>
<key>CFBundleURLSchemes</key>
<array>
<!-- Example: com.googleusercontent.apps.123456789-xxxxxxxx -->
<string>YOUR_REVERSE_CLIENT_ID</string>
</array>
</dict>
</array>
The Android setup is made possible by the excellent work from chmiiller and AppWerft in the Ti.GoogleSignIn repository. Thank you!
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
You will need to use the Web ClientID from Google instead of an Android one.
In order to use Google Sign In in your app you will need to provide an SHA-1 certificate fingerprint for Google Console.
You will need to provide a debug and a distribution SHA-1 fingerprint for your app. On Titanium, the debug SHA-1
has to be generated from the dev_keystore
file from your Titanium SDK android folder located at "mobilesdk//<sdk_version>/android/dev_keystore".
On macOS for example it would rely on: "~/Library/Application\ Support/Titanium/mobilesdk/osx/9.3.0.GA/android/dev_keystore".
And an command line example for it would be:
keytool -list -v -keystore ~/Library/Application\ Support/Titanium/mobilesdk/osx/9.3.0.GA/android/dev_keystore
You can follow same instructions used to configure a map in your Android app from Appcelerator Docs.
This repo also includes a video on how to create an Android app on Firebase and Google Developers Console to better explain the process.
As Appcelerator's documentation recommends, when submitting your app to Google Play Store you will need to create a production .keystore file, so don't forget to create another SHA-1 for this key and remember to add it also as another "fingerprint" on Firebase.
Note that some users have reported problems when submitting new apps to the Play Store, where the Google Login stop working on production. A solution found was to get another SHA-1 fingerprint from the Google Play app's dashboard and add this fingerprint to Firebase.
These fingerprints could be found on your Google Play Console, under the "Release Management" menu on the left and then on "App signing".
Here is an example on how it looks like:
Initialize the module by setting the Google SignIn API key you can get from the Google API Console.
import GoogleSignIn from 'ti.googlesignin';
GoogleSignIn.initialize({
// Required properties
clientID: '<client-id>',
// Optional properties:
serverClientID: '<server-client-id>',
scopes: ['https://www.googleapis.com/auth/plus.login'], // See https://developers.google.com/identity/protocols/googlescopes for more
loginHint: 'Titanium rocks!',
hostedDomain: 'https://my-hosted-domain.com',
openIDRealm: 'my-openID-realm',
});
-
signIn()
-
signInSilently()
-
signOut()
-
disconnect()
-
hasAuthInKeychain
-> Boolean -
currentUserImageURLWithSize(size)
-> String (iOS only)
-
language
(String,get|set
, iOS, only) -
currentUser
(Dictionary,get
)id
(String)scopes
(Array)serverAuthCode
(String)hostedDomain
(String)profile
(Dictionary)name
(String)givenName
(String)familyName
(String)email
(String)hasImage
(Boolean)
authentication
(Dictionary)clientID
(String)accessToken
(String)accessTokenExpirationDate
(Date)refreshToken
(String)idToken
(String)idTokenExpirationDate
(Date)
-
login
-
logout
The login event also includes the current user via the user
property.
If you want to build the module from the source, you need to check some things beforehand:
- Set the
TITANIUM_SDK_VERSION
inside theios/titanium.xcconfig
file to the Ti.SDK version you want to build with. - Build the project with
appc run -p ios --build-only
- Check the releases tab for stable pre-packaged versions of the module
For a basic example, check the demo in example/app.js
. For a full sample-app, check out the demo in example/sample-app
.
Hans Knoechel (@hansemannnn / Web)
Apache 2.0
Code contributions are greatly appreciated, please submit a new pull request!