【发布时间】:2018-03-05 07:59:32
【问题描述】:
更新:拥有自己的 OAuth 服务器:
感谢您分享分步说明链接。另外,我没有 Firebase 托管。
以下是我的理解,如有错误请指正:
方法 1
我需要激活 Firebase 托管并构建 2 个端点。一个用于授权交换,另一个用于令牌交换。
我需要使用 OAuth 服务器。假设:ory-hydra 并使用我在 firebase 中创建的端点对其进行配置。或 AWS Lambda。
在 Internet 上的某处托管 OAuth (ory-hydra) 服务器。
在 google 上的操作中使用这些端点,并制作一个简单的网页,用户将被重定向到该网页进行身份验证。
方法 2
我需要激活 Firebase 托管并构建 2 个端点。一个用于授权交换,另一个用于令牌交换。
使用 firebase 函数来实现 OAuth 和令牌端点。 (我不知道该怎么做,如果可能的话)
在 google 上的操作中使用这些端点,并制作一个简单的网页,用户将被重定向到该网页进行身份验证。
如果我错了,请纠正我。
更新:进行以下更改后:
- 将授权 URL 更改为:
- 将授权类型更改为隐式。
现在,我在调试部分获得了授权 URL,我可以通过将该 URL 粘贴到另一个选项卡中来进行授权。
但是,我在获取用户信息方面仍然遇到问题。我在 input.welcome 意图中有以下代码:
'input.welcome': () => {
// Use the Actions on Google lib to respond to Google requests; for other requests use JSON
if (requestSource === googleAssistantRequest) {
sendGoogleResponse('Hello, Welcome to my First Fulfillment agent!'); // Send simple response to user
app.askForSignIn();
let displayName = app.getUserName().displayName;
console.log(displayName)
}
我得到的只是调试日志中的 Null。
上一个问题 我正在尝试在 google 操作意图中获取用户信息。以下是我所做的:
1.) 从谷歌开发者控制台为我的项目创建了一个 OAUTH 密钥。 https://console.developers.google.com/apis/dashboard?project=.
2.) 登录到 console.actions.google.com 并点击帐户链接。
3.) 输入信息。请参阅屏幕截图以查看我输入的信息。
4.) 在我的“input.welcome”意图中添加了以下代码:
app.askForSignIn();
现在在模拟器中,我得到:“看起来您的我的测试应用帐户尚未关联。”我还从对话流 UI 中检查了我的意图所需的登录。
上一个问题 我正在尝试从我的谷歌助手对话机器人发送电子邮件。我可以使用 nodemailer 发送电子邮件。但是,我无法获取用户电子邮件地址。
以下是我发送电子邮件的代码:
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'My-Email',
pass: 'My-Pass',
}
});
var mailOptions = {
from: 'Sender-Email',
to: 'Receiver-Email',
subject: 'Requested Information',
text: 'Your information is here'
};
function sendEmail(){
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
}
最后,我在动作意图中调用它:
'input.sendmail': () => {
sendEmail();
},
到目前为止,当有人说,向我的谷歌助理操作发送电子邮件时,我可以发送电子邮件。
在此之后,我尝试使用以下方法获取用户的电子邮件地址:
const app = new DialogflowApp({request: request, response: response});
console.log(app.getUserName())
console.log(app.getUser().userName)
console.log(app.getUser().userId)
但他们都没有给我用户的信息。相反,我在 dialogflow 控制台日志中得到以下信息:
{
userStorage: '{"data":{}}',
lastSeen: '2018-03-05T10:18:17Z',
locale: 'en-US',
userId: 'ABadfdfrffsdffNa0H4hlCy_eyZmVNa8LweMJMCyirUg-
qAx8FHwvSI49QurUhxhgLsT6IUU4nGfF1',
user_id: 'ABerysteui4hlCy_eyZmVNa8LweMJMCyirUg-
qAx8FHwvSI49QurUhxhgLsT6IUU4nGfF1',
access_token: undefined,
userName: null
}
我试图用谷歌搜索这个问题,但我似乎需要关注 [1],但不确定。
如果有人能告诉我 [1] 是否是正确的指南,我将不胜感激,或者我需要其他东西?
谢谢!
[1]https://developers.google.com/actions/identity/account-linking
【问题讨论】:
标签: node.js firebase oauth-2.0 actions-on-google dialogflow-es