1

I have the sample (https://github.com/actions-on-google/smart-home-nodejs/blob/master/src/auth-provider.ts) of GoogleHome running 100% on GCP, only lacking 0Auth2 authentication and the Auth0 offered service seemed like a good solution, but there is no example in TypeScript.

Actions on Google is configured correctly and I can log in through Auth0, but I can not integrate into the example.

After much research, I keep walking in circles. At least importing from the library does not fail.

import * as express from 'express'
import * as util from 'util'
import { Headers } from 'actions-on-google'
import createAuth0Client from '@auth0/auth0-spa-js';

import * as Firestore from './firestore'

/**
 * A function that gets the user id from an access token.
 * Replace this functionality with your own OAuth provider.
 *
 * @param headers HTTP request headers
 * @return The user id
 */
export async function getUser(headers: Headers): Promise<string> {
  const authorization = headers.authorization
  const accessToken = (authorization as string).substr(7)
  return await Firestore.getUserId(accessToken)
} ...
  • What issues exactly are you running into? – Nick Felker Jul 10 '19 at 19:04
  • Hi Nick, I found your [tutorial](https://medium.com/google-developers/authenticating-smart-home-actions-for-the-google-assistant-with-auth0-b6fda3d2ee3d) and could not make it work, on the line `const app = smarthome` says **smarthome** is not a function, so I tried another way to use the Auth0-spa-js library but I have no idea how to do this, there is no TypeScript sample in the Auth0 site. I know there are a lot of concepts missing for me, but after a lot of fighting, I managed to make the Google Home sample work perfectly and now I have to implement the OAuth2 server. – Marcelo Arnaldi Jul 10 '19 at 19:39
  • What is the problem with this: https://github.com/auth0/auth0-spa-js#getting-started – Dan Woda Jul 10 '19 at 21:46
  • Hi Dan, I've seen this documentation, in the sample I'm running from Google Home: When I enter the Google Assistant App -> Home Automation -> "+" -> I select my Application -> The Auth0 screen appears -> I log in, after that I should receive the token, but I'm lost as adapt the code, for example how to register the "Endpoints". Certainly I lack concepts for me ... – Marcelo Arnaldi Jul 10 '19 at 22:32

1 Answers1

1

Resolved, after much fighting I was able to use the Auth0 library in TypeScript:

import { AuthenticationClient } from 'auth0'

const auth0 = new AuthenticationClient({
   domain: '<my-domin-auth0>.auth0.com',
   clientId: '<clientId>',
   clientSecret: '<clientSecret>'
});

export async function getUser(headers: Headers): Promise<string> {       
   const authorization = headers.authorization
   const accessToken = (authorization as string).substr(7)
   const {email} = await auth0.getProfile(accessToken)
   console.log(email)
   return await Firestore.getUserId(accessToken)
}

I strongly recommend reading @nick-felker article.