GithubHelp home page GithubHelp logo

ismarslomic / google-assistant-oauth Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 2.0 29 KB

Simple utility for retrieving OAuth 2.0 tokens for access to Google Assistant SDK

Dockerfile 9.56% JavaScript 90.44%
google google-assistant-sdk oauth oauth2

google-assistant-oauth's Introduction

google-assistant-oauth

Docker Image CI

Simple utility wrapped in Docker image for retrieving the OAuth 2.0 tokens for access to Google Assistant Service.

Get support

Bugs and questions related to the source code and Docker image can be reported at Github Issues in the ismarslomic/google-assistant-oauth repo.

About

In order to access the Google Assistant Service you need to retrieve access and refresh tokens by using Google OAuth2 implementation, this is explained in Google Authorization and Authentication documentation .

This utility simplifies going through the OAuth2 flow and was created in the context of implementing embedded Google Assistant for broadcasting message to Google Assistant enabled speakers, see ismarslomic/google-assistant-broadcast .

Setup

Prerequisites

  • docker - you need to have Docker installed on your machine, read Get Docker for more information.
  • Google OAuth 2.0 Client ID - in order to authenticate yourself and get access to your Google Assistant.
    • Follow steps 1-5 in Configure an Actions Console project
    • Make sure that you choose "Device registration" when creating new project in Actions Console
    • !Important! Download the OAuth Client file from GCP Console / API & Services / Credentials page (not from Google Actions Console), read solution on issue #7. Make also sure that the Application type of the OAuth Client is Desktop
    • Rename the downloaded file from client_secret_****.apps.googleusercontent.com.json to client_secret.json

Run docker container with docker run

Replace /home/pi/config with full path to the folder where your client_secret.json file is located.

Warning To avoid write permission issues inside container, please use a folder with ownership of the OS user you are logged in with. Typically /home/pi on RPI or /home/ubuntu on Ubuntu.

When docker container is terminated and the OAuth2 flow finished, you will find tokens.json file produced in the same folder.

docker run --rm \
-p 3005:3005 \
-v /home/pi/config:/usr/src/config \
ismarslomic/google-assistant-oauth:latest

Click on the URL provided in the console output from the Docker container.

Example of expected client_secret.json file

{
  "installed": {
    "client_id": "****.apps.googleusercontent.com",
    "project_id": "you-project-id",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "****",
    "redirect_uris": [
      "http://localhost"
    ]
  }
}

google-assistant-oauth's People

Contributors

ismarslomic avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

google-assistant-oauth's Issues

Not able to access the URL running on pi from my Mac

I think I mostly have this working, but when the container executes and I get a URL, I'm not sure how to follow that. I copy the URL and access it from Mac, but get a message "can't connect to server" which makes sense because it's trying to go to local host. I don't have a web server on my pi (and accessing via command line) so I tried curl with the URL and that doesn't seem to work or result in a tokens.json file.

client_secret.json is not valid, root property 'installed' missing

When I try to run the command (with or without sudo):

docker run --rm \
-p 3005:3005 \
-v /home/[user]/google:/usr/src/config \
ismarslomic/google-assistant-oauth:latest
TypeError: Cannot read properties of undefined (reading 'token_uri')
    at validateClientSecretFile (/usr/src/app/index.js:132:25)
    at main (/usr/src/app/index.js:16:3)
    at Object.<anonymous> (/usr/src/app/index.js:143:1)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Module._load (node:internal/modules/cjs/loader:827:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47

The contents of "client_secret.json" (with sensitive data replaced with placeholders) is:

{"web":{"client_id":"[client_id]","project_id":"[project_id]","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"[client_secret]","redirect_uris":["[redirect_uris]"]}}

Fatal error in , line 0

Hi,

I get this error when I try to run the docker:

Fatal error in , line 0

unreachable code

#FailureMessage Object: 0x7ed0156c

I've put the client_secret.json file in /home/pi/config

FetchError: request to Google token API failed

what am i doing wrong ? :(

Go to this URL in your browser: https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fassistant-sdk-prototype&response_type=code&client_id=ddwa13****422dwad34-4r1ld028*dwdw*****vljbr7ddv805jd*d**dwd**.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A3005%2Foauth2callback

Code is 4/0ARtbsJrHn5CjFdwddaadMwgybO4wB8LA_sziKadSyp5Zd3K7awdawdaDuvqdwd**
FetchError: request to https://oauth2.googleapis.com/token failed, reason: getaddrinfo EAI_AGAIN oauth2.googleapis.com
.......................
.......................

Acquired token in tokens.json file is not found after authentication

Hello.

I'm trying to use this to make the tokens file and I think that I'm close but I'm running into an issue.
I've got this setup using a portainer stack and the config looks like this:

version: "3.9"
services:
google-assistant-oauth:
container_name: google-assistant-oauth
image: ismarslomic/google-assistant-oauth:latest
ports:
- "3005:3005"
volumes:
- /home/containers/google-assistant-oauth:/usr/src/config

I've created the client_secret.json file in the /home/containers/google-assistant-oauth directory and copied the content from the client_secret_****.apps.googleusercontent.com.json file into /home/containers/google-assistant-oauth/client_secret.json.

I can start the google-assistant-oauth container and go to it's logs and I get an entry like this:

Go to this URL in your browser: https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fassistant-sdk-prototype&response_type=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

I go to that link and I get a "sign in with Google" page where I see my google account, I click that and hit the continue button.

It then changes to a "http://localhost:3005/oauth2callback?code=xxxxxxxxxxxxxxxxxxxxxxxxx" page that times out. But if replace the localhost part with the IP address of the LXC where docker is running, then I get this:

Authentication successful! Please return to the console.

I go back to the logs of the container and see this:

Tokens acquired.
Tokens saved to /usr/src/config/tokens.json.

However, I don't see a tokens.json file:

root@docker:/home/containers/google-assistant-oauth# ls
client_secret.json
root@docker:/home/containers/google-assistant-oauth#

I'm a bit lost here, where am I going wrong?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.