dialogflow-es - 谷歌助理帐号关联失败
问题描述
我正在尝试在谷歌操作中实现帐户链接。我选择了具有隐式链接类型的Google 和 OAuth 。在我正在验证请求并重定向到 google 的 oauth 处理程序中。这是示例代码,Authorization URL
@Post('/google/actions/authorize')
public async authorizeGoogle(
@Req() request: Request,
@Res() response: Response,
@Body() authorizeRequest: DAuthorizeRequest,
) {
// tempToken is stored in cookie after login.
const tempToken = request.cookies['temp-token'];
if (!tempToken) {
throw new UnauthorizedException();
}
let token: DTemporaryToken;
try {
token = await this.jwtService.verifyAsync<DTemporaryToken>(tempToken);
} catch (err) {
throw new UnauthorizedException();
}
// validate request parameters are as it should be.
const valid = this.authService.validateGoogleOauthRequest(
token,
authorizeRequest,
);
if (!valid) {
throw new UnauthorizedException();
}
const user: User = await this.userService.findById(token.user_id);
const accessToken = await this.authService.generateAccessTokenForGoogle(
user,
);
const redirectUri = `${
authorizeRequest.redirect_uri
}?access_token=${accessToken}&error=${false}&token_type=bearer&state=${
authorizeRequest.state
}`;
response.redirect(redirectUri);
}
重定向后我收到此错误,
抱歉,出了点问题,所以我无法让你登录。不过你可以稍后再试。
这是dialogflow
代码
dialogFlowApp.intent(
'Default Welcome Intent',
async (conv: DialogflowConversation) => {
conv.ask(new SignIn('to access your data'));
},
);
dialogFlowApp.intent('sign_in', (conv, params, signIn) => {
console.log('SIGN IN', signIn)
conv.ask('how are you?');
})
该signIn
值的控制台日志是
登录{'@type':'type.googleapis.com/google.actions.v2.SignInValue',状态:'ERROR'}
就是这样,我无法弄清楚出了什么问题。没有足够的描述性错误来解释哪里出错了。
解决方案
这是我的一个愚蠢的错误。问题出在重定向 url 中access_token
,我没有将这些参数和其他参数作为 url 片段发送,而是将它们作为查询参数发送。因此,将访问令牌生成更改为此解决了问题。
const redirectUri = `${
authorizeRequest.redirect_uri
}#access_token=${accessToken}&error=${false}&token_type=bearer&state=${
authorizeRequest.state
}`;
不过,我仍然认为从谷歌的角度来看,错误报告应该更全面。这是一个愚蠢的错误,如果错误的意义大于Something went wrong
推荐阅读
- composer-php - Composer php 错误 - 应为以下之一:'STRING'、'NUMBER'、'NULL'、'TRUE'、'FALSE'、'{'、'['
- algorithm - 内循环为 j < i 的嵌套循环的时间复杂度是多少?
- python - Itertools 排列组合与固定放置
- python-3.x - Pyspark在用0替换null时出错
- javascript - 多个输入内的多个输入表单
- wcf - 由于 WCF 服务中的 HTTPS 更改导致应用程序流中的 TLS 问题
- javascript - 添加卡片时无法读取@lourenci/react-kanban 中未定义的属性“卡片”
- sql - BigQuery:如何使用应用于同一列的三个不同过滤器获取数据?
- android - Admob 对不同活动的最小请求间隔
- android - 如何通过每次 Retrofit API 调用发送更新的 Firebase 令牌