代表谷歌家庭用户访问谷歌apis

问题描述 投票:1回答:1

我正在尝试开发一个简单的概念证明,通过Dialogflow Fullfilment使用用户的授权从Google Home与Google API进行交互。

例如,我们希望能够创建/读取/更新/删除用户的联系人。

实施Google登录相对容易,但我不知道如何申请其他范围

此外,我之前从未实现过OAuth服务器,而且我仍然不确定是否需要它,或者我是否可以重用现有服务器。

我在这里看了很多帖子,所以大多数帖子都被@Prisoner回答了,他们也在Google Home Authorization Code and Authentication with Google Account提供了详细的流程

在他的回答中,他提到我们可以“将用户重定向到Web登录页面”,但我仍然不明白如何从完整的文件中做到这一点

以下是我以前使用Google登录的履行代码:

//requirements
const { dialogflow, SignIn} = require('actions-on-google');
const functions = require('firebase-functions');

//initialisation
const app = dialogflow(
{
    debug: true,

    // REPLACE THE PLACEHOLDER WITH THE CLIENT_ID OF YOUR ACTIONS PROJECT
    clientId: '1111111111111-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.apps.googleusercontent.com'
});

//Welcome Intent
app.intent('Default Welcome Intent', (conv) => {
    conv.ask(`Welcome to the demo agent, say "Connect-me" to proceed`);
}); 

//Default Intent
app.intent('Default Fallback Intent', (conv) => {
    conv.ask(`Sorry, can you repeat please?`);
}); 

//Intent starting the Google SignIn
//  Create an intent with the name "Start Signin"
app.intent('Start Signin', (conv) => {
    //SignIn Helper (https://developers.google.com/actions/assistant/helpers#account_sign-in)
    conv.ask(new SignIn(`Need to identify you`));
});


//Intent called when the user complete the authentication
//  Create an intent with the name "Get Signin" and assign it the event "actions_intent_SIGN_IN"
app.intent('Get Signin', (conv, params, signin) => {
    if (signin.status === 'OK') {
        const payload = conv.user.profile.payload;

        conv.ask(`Hello ${payload.name}. You can now access your contacts informations...  but not really `);
    } else {
        conv.ask(`Sorry but you should authentify yourself `);
    }
});

//Example of intent that I would like to make it works
app.intent('How many contacts', (conv) => {
    /*
    TODO: How to ask for additional scopes ("https://www.google.com/m8/feeds/" : read/write access to Contacts and Contact Groups)
    NOTE: Actually, I'm more interrested on how to get the additional scopes.  
          I could probably do the querying contacts part by myself since it's quite documented (https://developers.google.com/contacts/v3/)
    */

    conv.ask(new SignIn(`You have ${nbContacts} contacts defined in your Google Contact`));
});

exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
google-api dialogflow google-oauth2 google-home
1个回答
0
投票

你在这里捆绑了一些相关的问题。

如何通过Google登录申请其他范围?

不幸的是你不能。

这是为了用户的安全。因为当你通过语音授予额外的权限时并不总是显而易见的,并且要求太多的范围可能会使语音压倒一切,他们现在不允许这样做。

好。那么我该如何获得这些额外的范围呢?

您引用了另一篇文章,该文章介绍了我建议的方法。它涉及通过同一Google Cloud Project中的网页登录和授予范围。在Google的cross-client identity系统下,这些将在用户通过智能助理连接时应用。

那么如何将它们引导到网页呢?

我通常使用带有网站链接按钮的card或网站上的link out suggestion。但是,这两者都依赖于支持Web浏览器的可视化界面。因此,您可能希望使用surface capabilities进行检查。

如果您使用自己的OAuth服务器,使用"OAuth and Google Sign-In" method组合,智能助理将为您处理这些事情。

我是否需要编写自己的OAuth服务器?

不可以。您可以使用像Auth0这样的东西来为您处理OAuth部分。

© www.soinside.com 2019 - 2024. All rights reserved.