oauth - 在 Actions on Google 中与我自己的 OAuth 服务器关联的帐户缺少授权类型
问题描述
我正在尝试实施智能家居操作。它从这个例子开始
https://codelabs.developers.google.com/codelabs/smarthome-washer/#0
这很有效。
此示例使用 firestore 作为云服务。
我想自己实现服务器。作为我本地 PC 上的服务器的第一次测试,可通过端口转发访问。
我创建了一个让我们加密证书并使用 nodejs express htpps 服务器。
对于 Oauth 实现,我使用与示例相同的“不安全”代码。
expressApp.get('/fakeauth', async (req, res) => {
console.log('fakeauth',req.headers, req.body, req.query);
const responseurl = util.format('%s?code=%s&state=%s',
decodeURIComponent(req.query.redirect_uri), 'xxxxxx',
req.query.state);
console.log(responseurl);
return res.redirect(responseurl);
});
expressApp.all('/faketoken', async (req, res) => {
console.log('faketoken',req.headers, req.body, req.query);
const grantType = req.query.grant_type
? req.query.grant_type : req.body.grant_type;
const secondsInDay = 86400; // 60 * 60 * 24
const HTTP_STATUS_OK = 200;
console.log(`Grant type ${grantType}`);
let obj;
if (grantType === 'authorization_code') {
obj = {
token_type: 'bearer',
access_token: '123access',
refresh_token: '123refresh',
expires_in: secondsInDay,
};
} else if (grantType === 'refresh_token') {
obj = {
token_type: 'bearer',
access_token: '123access',
expires_in: secondsInDay,
};
}
res.status(HTTP_STATUS_OK)
.json(obj);
});
现在我将帐户链接网址更改为我的本地服务器。当我尝试连接到此操作时,它不起作用。
对 fakeauth 端点的请求是好的。
但是当谷歌调用 faketoken 端点时,查询丢失并且正文为空。
请求的 url 是 .../faketoken 没有任何查询和一个空的正文。
fakeauth 请求的响应不会有问题,因为如果我将 fakeauth 请求发送到我的服务器并将 faketoken 请求发送到 firestore 服务器,则帐户链接正在工作。
我试过的第二个。
将 fakeauth 发送到 firestore 服务器,将 faketoken 发送到我的服务器。
结果是一样的。没有查询也没有正文。
我不知道我做错了什么,因为这是来自谷歌的请求是错误的。
有没有人知道出了什么问题。我已经搜索过,但我找不到有同样问题的人。
谢谢你的帮助。
问候西蒙
解决方案
为了帮助其他人,我将描述这个问题。
我认为数据是作为 url 查询发送的,因为代码是从查询对象中读取它们的。
但是它们以内容类型发送到正文中:application/x-www-form-urlencoded
如果我使用
expressApp.use(bodyParser.urlencoded());
数据被添加到查询中,原始测试代码正在运行。
推荐阅读
- javascript - 使用 Node.js 实现类似多线程的行为
- python - Tesseract OCR 将 9 识别为 S
- python-2.7 - 在 Jython 中提取 zip 文件时,“TypeError:字符映射必须返回整数、无或 unicode”
- java - 由变量绑定的java随机数
- java - Apache Commons:不支持的ZipFeatureException (LZMA)
- ios - Apple Watch 锻炼分钟环从锻炼开始时间而不是持续时间更新
- java - 如何获取 OneSignal 用户 ID?
- google-api - 在 Google Calendar API 上启动 Event 的 Webhook
- r - 缺少数据时如何使用 n() 按组计数案例
- java - CustomTextView 作为父级和 Textview 作为父级之间的区别