【问题标题】:Auth0 & Dialogflow AuthenticationAuth0 和 Dialogflow 身份验证
【发布时间】:2018-11-22 06:53:11
【问题描述】:

我想使用 Auth0 访问 Google API。正在尝试按照this post 上的说明进行操作

目前触发Auth0,我使用conv.ask(new SignIn());app.intent("actions_intent_SIGN_IN", (conv, params, signin) => { ... })

我在 actions_intent_SIGN_IN 中从const code = conv.user.access.token; 获得了一个令牌。

但是,该令牌似乎不是用于为 Google 获取 access_token 的令牌,即通过 POST /oauth/token。不管这个令牌是什么,它似乎对除 GET /userinfo 之外的任何请求都不起作用。在 Google Cloud Functions 上,我在日志中看到了这个:

{ error: 'invalid_grant', error_description: 'Invalid authorization code' }

我和 Postman 玩了一会儿,并设法通过 GET /authorize 检索(看似?)正确的授权代码,该代码可用于 POST /oauth/token 并构建我自己的 url,如 https://[APPNAME].auth0 .com/authorize?response_type=code&client_id=[CLIENT ID]&redirect_uri=[REDIRECT URI]。授权码出现在https://[APPNAME].auth0.com/login/callback?code=[CODE HERE]

问题是 - 如何从对话流中检索 code=[CODE HERE]?

【问题讨论】:

    标签: node.js auth0 dialogflow-es


    【解决方案1】:

    您可以使用使用 OAuth2.0 的服务帐户进行身份验证——您可以阅读更多关于此的一般信息 here,它们将为您节省网络调用。您还需要找到适当的 Google API 范围here。 Dialogflow 的示例展示了如何在 Github 上为example 完成此操作。

    const {google} = require('googleapis');
    const serviceAccount =  { };   // Enter Service Account private key JSON
    
    const client = new google.auth.JWT({
      email: serviceAccount.client_email,
      key: serviceAccount.private_key,
      scopes: ['https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/drive']
    });
    

    【讨论】:

      猜你喜欢
      • 2015-04-10
      • 1970-01-01
      • 2016-04-22
      • 2018-12-06
      • 2016-09-25
      • 2020-04-11
      • 1970-01-01
      • 2017-10-11
      • 1970-01-01
      相关资源
      最近更新 更多