How to use Firebase Auth with Alexa Account Linking

Daniel Morawetz
Chatbots Life
Published in
3 min readApr 2, 2019

--

More in-depth tutorial including code for refresh_token now available: Alexa Account Liking with Firebase Auth

If you are just interested in the time out problem within the AWS lambda function skip to 5. Use the custom token in the Alexa Skill .

I came up with an idea for a new app the other day, which also could use a nice custom Alexa Skill. Because of the superb developer support I chose to go with Firebase Authentication and Firestore for the database. The fact that I never wrote an Alexa Skill before and have never used Firebase in my life made it an interesting challenge. After hours debugging I wanna now share my finding and how it bugged me all day long.

Note: If you are a more experienced user and can think of a better way to do, what I will describe in this article, please reach out to me!

This is not a step-by-step guide but an overview of my setup. I will assume you can setup Firebase Authentication, Firestore and a custom Alexa Skill yourself.

1. Firebase Authentication in App

With an eye in the future (at Google’s new OS Fuchsia), I write my app using Flutter. The packages firebase_auth and flutter_firebase_ui cover login, registration and all things this entails like forgotten passwords.

2. Firebase Authentication via Firebase Hosting

Alexa Account Linking requires an Authorization URI and an Access Token URI . Because I found no way that Firebase would support this on its own I set it up myself.

Top 4 Bot Tutorials

1. AWS setup for Deep Learning

2. How to Integrate API.AI with Chatfuel

3. Build a working SMS chat-bot in 10 minutes

4. Chatbot Conference 2019 in NYC

I created a simple login page with FirebaseUI for Web:

3. Access_token API via Firebase Cloud Functions

Alexa will then take this random code we returned and ask our firebase cloud function for a valid access_token:

4. Configure Alexa Account Linking

Select Auth Code Grant and set the Authorization URI = https://<project_name>.firebaseapp.com and the Access Token URI = https://us-central1-<project_name>.cloudfunctions.net/auth_token.

5. Use the custom token in the Alexa Skill

Now comes the most important part. This took me hours of googling.

Please mind the firebase.auth().signOut(); at line 55. Without this, the AWS Lambda will not finish and thus you’ll get an error like Task timed out after 8.01 seconds .

Once you have set up this structure it’s very easy to develop the rest of the Alexa Skill. I am positively surprised how advanced the Alexa ecosystem is and I am happy to dive deeper. On my developing journey, I will add further articles about my findings and the quirks of Skill development.

Make sure to follow me so you won’t miss any future advancements.

Don’t forget to give us your 👏 !

--

--