Google Sign-In in Jovo

google-assistant

#1

Is there a way to implement Google Sign-in via voice using Jovo framework?
If not - is there a way to use Actions on Google node.js sdk inside a Jovo app?


#2

answering my own question, I found something in the docs: https://www.jovo.tech/docs/reference/GoogleAction.html#main

I already enabled Sign In with voice in Action on Google console, and used this:
this.$googleAction.askForSignIn(speech)
in my app. First test returned a prompt from AoG to sign up :slight_smile:
I’ll update with full solution when I get it - unless someone can do it quicker :smiley:


#3

so the next step is to create an intent:
ON_SIGN_IN () {

}

And inside try to get user profile data, hoping to provide access to email address.
The intent works, but I can’t get user profile data.

I tried this:
let profile = await this.$googleAction.$user.getProfile()
but it returns undefined.

Please help.


#4

Can you paste the full request JSON here?


#5

I found the problem, and the the solution too!

here’s the working ask for sign-in and sign-in confirmation intent:

async ASK_FOR_SIGNIN () {
  const speech = 'To receive emails'
  this.$googleAction.askForSignIn(speech)
}

async ON_SIGN_IN () {
    if (this.$googleAction.getSignInStatus() === 'OK') {
      // get token
      const tokenId = this.$originalRequest.user.idToken

      // decode token
      const tokenUrl = 'https://oauth2.googleapis.com/tokeninfo?id_token=' + tokenId
      try {
        const response = await axios.get(tokenUrl)
        const tokenData = response.data;
        // pull email from the decoded token
        this.tell(`User email is: ${tokenData.email}`);
      } catch (error) {
        console.error(error);
        this.tell(`Can't decode the token`);
      }
    } else {
      this.tell('There was an error.');
    }
  },

I’m not sure if that’s the recommended way of doing it, but it works :slight_smile:


#6

thanks for sharing this! we will take a look :slight_smile:


Getting user email address in google action