google助手帐号绑定失败

google assistant account linking faliure

我正在尝试在 google 操作中实现帐户链接。我选择了 Google 和 OAuth 以及 Implicit 链接类型。在 Authorization URL 中,我正在验证请求并重定向到 google 的 oauth 处理程序。这是示例代码,

@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);
}

重定向后出现此错误,

Sorry, something went wrong, so I couldn't sign you in. But you can try again later.

这是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 值的控制台日志是

SIGN IN { '@type': 'type.googleapis.com/google.actions.v2.SignInValue', status: 'ERROR' }

就是这样,我不知道是哪里出了问题。没有足够的描述性错误来解释哪里出了问题。

我犯了一个愚蠢的错误。问题出在重定向 url 中,而不是将 access_token 和其他参数作为 url 片段发送,我将它们作为查询参数发送。因此,将访问令牌生成更改为此可以解决问题。

const redirectUri = `${
  authorizeRequest.redirect_uri
}#access_token=${accessToken}&error=${false}&token_type=bearer&state=${
  authorizeRequest.state
}`;

不过,我仍然认为 google 的错误报告应该更全面。这是一个愚蠢的错误,如果错误比 Something went wrong

更有意义,则应该花 10 秒而不是几个小时来修复