我正在尝试在Google操作中实现帐户关联。我选择了隐式链接类型的 Google和OAuth 。在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);
}
重定向后,我收到此错误,
抱歉,出了点问题,所以我无法登录。但是您可以 稍后再试。
这是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'}
就是这样,我不知道出了什么问题。没有足够的描述性错误可以解释问题出在哪里。
答案 0 :(得分:0)
这对我来说是一个愚蠢的错误。问题出在重定向URL中,而不是将access_token
和其他参数作为URL片段发送,而是将它们作为查询参数发送。因此,将访问令牌的生成更改为此可以解决此问题。
const redirectUri = `${
authorizeRequest.redirect_uri
}#access_token=${accessToken}&error=${false}&token_type=bearer&state=${
authorizeRequest.state
}`;
尽管如此,我仍然认为错误报告从Google的角度来看应该更加全面。如果该错误比Something went wrong