我使用 "@nuxtjs/auth-next": "5.0.0-1618898588.9655d0e"
进行身份验证,我想使用它集成 google。
我在 nuxt.config.js 中设置了以下代码
google: {
clientId: process.env.GOOGLE_CLIENT_ID_LATEST,
redirectUri: 'http://localhost:3000/account/login',
responseType: 'code',
accessType: 'offline',
grantType: 'authorization_code',
codeChallengeMethod: 'S256'
}
在登录页面
loginWithGoogle() {
this.$auth.loginWith('google')
}
在我点击使用谷歌登录后,谷歌请求被重定向到redirectUri,查询附加为http://localhost:3000/account/login?state=3OyMNy2ODj&code=4%2F0AY0e-g6YkRJFyVCVxo8Ph2-WXpTYjKbxyuAE3r6F1PB_pt8W9QlRgdtxpEeKxfzYvX6g&scope=email%20profile%20openid%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&authuser=0&prompt=consent
现在我需要再次向 google 请求访问令牌,但我不知道该怎么做。
答案 0 :(得分:0)
您需要使用访问令牌交换授权码。除了身份验证代码,您还需要发送您的 oauth2 客户端密码和客户端 ID。
示例:
curl -d https://accounts.google.com/o/oauth2/token?client_id=<YOUR_CLIENT_ID>&client_secret=<YOUR_CLIENT_SECRET>&code=<AUTH_CODE_RECEIVED>A&grant_type=authorization_code&redirect_uri=http://localhost:3000/account/login