Vlad
Vlad

Reputation: 149

Google Home actions

I try to create actions for Google Home. For my new action I need to ask user authorization in my web site, I need to identified user. For this user should be find my action in Google Home app, linked on my web site and sign in. My question in the next. Have I any chance to create all this using only emulator? Or without Google Home device I can't do anything?

Upvotes: 0

Views: 579

Answers (1)

Prisoner
Prisoner

Reputation: 50731

You'll definitely be able to implement and test this just using the emulator, although it will not work as smoothly as if you had an actual device. The procedure is known as "account linking" and is detailed at https://developers.google.com/actions/develop/identity/oauth2-overview, but in general the flow is:

  1. Your service needs to act as an OAuth 2.0 server and have an authorization page and a token exchange endpoint available to the Google Assistant.
  2. When the user activates your Action for the first time, they're told they need to give Home permission to access your account and they should check the Google Home app for a card.
  3. The card will redirect them to the authorization page, where they log into your website and authorize access to your site from Google Home.
  4. As part of authorization, you'll continue the OAuth 2.0 flow and will (eventually) issue a bearer token that Google Home will store.
  5. Users can then re-trigger the Action. Every time your webhook is called, Google Home will send this token to you.
  6. You can then use this token to lookup which user is making the request.

There are a lot of additional details, which are covered in Google's documentation and in the OAuth 2.0 specification, but this is generally how it works.

For the emulator, users are not directed to the card in the Google Home app. Instead, you can see in the return JSON provided by the emulator the first time you activate the Action. In it, the debugInfo.sharedDebugInfo.debugInfo field contains the authentication URL. You should go to the URL in a browser, complete the sign-in and authorization flow, and will eventually be redirected to a URL that includes the parameter result_code=SUCCESS. After this, using the emulator will send the access token to your webhook. See https://developers.google.com/actions/tools/testing#testing_on_the_google_home_web_simulator for additional details.

Upvotes: 2

Related Questions