在为我的 Nuxt 应用程序使用 nuxt-auth 插件时遇到问题。在授予授权码后,我正在使用谷歌策略来检索 access_token 和 refresh_token :
google: {
clientId: 'MY CLIENT ID',
codeChallengeMethod: '',
responseType: 'code',
grantType: 'authorization_code',
endpoints: {
authorization: 'https://accounts.google.com/o/oauth2/auth',
token: 'http://localhost:3000/signin/google',
userInfo: 'https://www.googleapis.com/oauth2/v3/userinfo',
},
prompt: 'consent',
accessType: 'offline',
token: {
property: 'access_token',
type: 'Bearer',
maxAge: 1800,
},
refreshToken: {
property: 'refresh_token',
maxAge: 60 * 60 * 24 * 30,
},
scope: [
'openid',
'profile',
'email',
],
}
我验证了授权代码以检索正确的凭据(access_token、refresh_token 等):
const response = await googleAuthClient.getToken(req.body.code)
googleAuthClient.setCredentials(response.tokens)
const tokenInfo = await googleAuthClient.getTokenInfo(
response.tokens.access_token,
)
res.status(200).json(response.tokens)
当我第一次登录时(例如在浏览器会话期间),我会从我的 GoogleOAuth2Client 中正确检索 access_token 和 refresh_token。
但是,当我注销并第二次登录时,凭据中的 refresh_token 属性丢失(我得到了 access_token id_token)......所以我无法使用它来正确刷新存储的访问令牌通过nuxt-auth 插件。
我已经读过要强制生成 refresh_token,我必须指定一个“prompt=consent”参数。
但是,将此参数放在我的 nuxt-auth 策略配置中的什么位置?