Skip to main content

A month of Flutter: configure Firebase Auth for Sign in with Google on Android


Originally published on bendyworks.com.
Yesterday I added the sign-in button. Now let's make it do something.
First I'll create a new Firebase project that will be used in development. Once I get ready to publish the app I'll create a production project.

Once the project is created, I'm going to enable Google as a sign-in provider for Firebase Auth. Enabling Google requires an app name and an email address. The email address can be a Google Group mailing list. I made sure the group is configured so that anyone can post but nobody can join and only members can read.

There are a number of alternatives to Google if Twitter or email/password is more appropriate for the app's target user.

Within android/app/build.gradle I will replace the default com.example.<name> applicationId with app.birb. An application IDshould be a domain that you own with the parts in reverse order.
Sign in with Google requires that API clients be authenticated. This basically means that you must use a certificate when accessing some Google APIs. Since the Birb app is currently using the development Firebase project, I will use the Android Studio debug certificate now and generate a production certificate in the future.
To get the debug certificate fingerprint, the keytool program is used. This is installed with Android Studio but may not be available in your system path. I used flutter doctor -v to find where the Java bins were located.
$ /usr/local/android-studio/jre/bin/keytool -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore
Enter keystore password:  
Alias name: androiddebugkey
Creation date: Oct 22, 2018
Entry type: PrivateKeyEntry
Certificate chain length: 1
Certificate[1]:
Owner: C=US, O=Android, CN=Android Debug
Issuer: C=US, O=Android, CN=Android Debug
Serial number: 1
Valid from: Mon Oct 22 18:57:30 CDT 2018 until: Wed Oct 14 18:57:30 CDT 2048
Certificate fingerprints:
  MD5:  32:B6:A3:75:EA:76:C7:AB:4A:A5:D4:48:AD:F3:09:52
  SHA1: 0C:DC:5F:08:F0:45:EF:F0:7B:5C:CA:F2:76:52:CC:EA:16:3F:94:08
  SHA256: 36:33:30:07:40:12:A4:30:2A:DD:9F:8C:FD:BE:92:62:F2:FB:C3:37:09:6F:DB:62:C9:60:7C:5E:8A:F8:21:59
  Signature algorithm name: SHA1withRSA
  Version: 1
With the SHA-1 fingerprint, 0C:DC:5F:08:F0:45:EF:F0:7B:5C:CA:F2:76:52:CC:EA:16:3F:94:08, at the ready, it's back to Firebase. I'll add an Android app to the project I created earlier. In the future I will also create an iOS app.

With the package name and fingerprint configured, Firebase will now prompt to download a google-services.json file. This contains various Google Cloud and Firebase service details and should be put in the android/app directory. There isn't any sensitive information in the file but for an open source project it will need to be different for every developer so I'm adding it to .gitignore.

Now I'll add a couple of dependencies to the Android app and to Flutter.

com.google.gms:google-services gets added to android/build.gradle.
buildscript {
    dependencies {
        // Add this line
        classpath 'com.google.gms:google-services:4.2.0'
    }
}
In android/app/build.gradle there are two additions.
dependencies {
  // Add this line
  implementation 'com.google.firebase:firebase-core:16.0.6'
}

// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'
In pubspec.yaml require the google_sign_in package and the firebase_auth package.

Well the Sign in with Google button still doesn't do anything but maybe tomorrow it will.

Code changes

Comments

Popular posts from this blog

CloudSense: the Future of Advertising

With the whole cloud taking off and more and more services switching to a push it into the cloud, leave it there until you need it, and pull it out model. I can only imagine what will be switching to this model soon. Oh wait. I can imagine.



Advertising!


Reading an article about how Avril Lavigne is supposed to have a $2 million check "appear" in her mailbox because of the absurd number of streams her videos get from YouTube got me thinking about creator compensation. The problem Avril is having is, a) Google wants to keep the money, and b) Google is having trouble figuring out how to monetize video streams. But on a grander scale it is whoever puts the ads on the page that gets the money not the content creator.

Little known @Twitter and @TwitterAPI tips and tricks

Be sure to comeback as new tips and tricks get added. If you know of anything I missed be sure to let me know.

Static URL for profile images based on screen_name:

https://api.twitter.com/1/users/profile_image/abraham

* This performs a http redirect to the actual profile image URL. Currently https redirects to http. You can also add "?size={mini | bigger | normal}" to get specific sizes.

Redirect to profile based on user_id:

https://twitter.com/account/redirect_by_id?id=9436992

In_reply_to_status_id mentions:

https://api.twitter.com/1/statuses/update.json?status=reply+to+@abraham&in_reply_to_status_id=12410413197

* In the web interface new mentions are only replies if they start with @screen_name. By pushing @screen_name further along in the string your followers who do not follow @screen_name will still see the status.

Profile image sizes:

http://a3.twimg.com/profile_images/54160223/chart-black-small.png

* By default you get the original image size you can add _mini, _normal, and …

Installing Storytlr the lifestreaming platform

"Storytlr is an open source lifestreaming and micro blogging platform. You can use it for a single user or it can act as a host for many people all from the same installation."

I've been looking for something like Storytlr for a few months now or at least trying to do it with Drupal. While I love Drupal and FeedAPI I did not want to spend all that time building a lifestream website. So I've been playing around with Storytlr instead and found it very easy. Here is how I got it up and running on a Ubuntu EC2 server. You can also check out the official Storytlr install instructions.

Assumptions:
LAMP stack installed and running.Domain setup for a directory.MySQL database and user ready to go.Lets get started!
Get the code: wget http://storytlr.googlecode.com/files/storytlr-0.9.2.tgz tar -xvzf storytlr-0.9.2.tgzYou can find out the latest stable release on Storytlr's downloads page.

Import the database:
Within protected/install is database.sql. Import this into your empt…