使用 google oauth 和 nestjs 进行身份验证

时间:2021-04-26 07:29:21

标签: javascript oauth-2.0 google-oauth nestjs

我想根据谷歌的访问令牌为我的路由控制器使用保护,但我不知道如何实现这一点。

我从我的 google oauth 中检索了这个

{
  "message": "User information from google",
  "user": {
    "email": "test@gmail.com",
    "firstName": "John",
    "lastName": "Kennedy",
    "picture": 
    "https://lh3.googleusercontent.com/a-/mypicture",
    "accessToken": "myaccesstoken"
  }
}

现在我不知道如何将此访问令牌用于我的其他路由,例如在控制器中:

  @UseGuards() // I don't know what to put here
  @Get('/get_customer/:id')
  async findCustomerById(@Param() params): Promise<Customer> {
    try {
      return await this.stripeService.findCustomerById(params.id);
    } catch (e) {
      throw new Error(e.message);
    }
  }

1 个答案:

答案 0 :(得分:1)

关注这个article,它对我有用。