Titanium Google Signin Save

Use the native Google Sign In SDK in Appcelerator Titanium.

Project README

Google SignIn SDK in Appcelerator Titanium

Google SignIn

Summary

Ti.GoogleSignIn is an open-source project to support the Google SignIn SDK in Appcelerator's Titanium.

Requirements

  • Titanium SDK 9.2.0+
  • Ti.PlayServices (Android)

Download

Releases page

Setup

iOS Setup

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>

Android Setup

The Android setup is made possible by the excellent work from chmiiller and AppWerft in the Ti.GoogleSignIn repository. Thank you!

Permissions in manifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
⚠️ PLEASE NOTE!

You will need to use the Web ClientID from Google instead of an Android one.

Google Play Console
Obtaining a SHA-1 with Titanium

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:
Google Play Console

Example

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',
});

Methods

  • signIn()
  • signInSilently()
  • signOut()
  • disconnect()
  • hasAuthInKeychain -> Boolean
  • currentUserImageURLWithSize(size) -> String (iOS only)

Properties

  • language (String, get|set, iOS, only)
  • currentUser (Dictionary, get)
    • id (String) 
    • scopes (Array<String>) 
    • 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)

Events

  • login
  • logout

The login event also includes the current user via the user property.

Build

If you want to build the module from the source, you need to check some things beforehand:

  • Set the TITANIUM_SDK_VERSION inside the ios/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

Example

For a basic example, check the demo in example/app.js. For a full sample-app, check out the demo in example/sample-app.

Author

Hans Knoechel (@hansemannnn / Web)

License

Apache 2.0

Contributing

Code contributions are greatly appreciated, please submit a new pull request!

Open Source Agenda is not affiliated with "Titanium Google Signin" Project. README Source: hansemannn/titanium-google-signin
Stars
30
Open Issues
2
Last Commit
3 months ago

Open Source Agenda Badge

Open Source Agenda Rating