每次都是新code,600秒的过期时间,为啥会一会报错一会儿又可以了。。??
// callback 接口代码
// …
const code = url.searchParams.get(“code”)
const tokenResponse = await fetch(${authConfig.appAuthHost}/oidc/token
, {
method: “POST”,
headers: {
“Content-Type”: “application/x-www-form-urlencoded”,
},
body: new URLSearchParams({
grant_type: “authorization_code”,
client_id: authConfig.appId,
client_secret: authConfig.appSecret,
code: code,
redirect_uri: authConfig.getRedirectUri(),
}),
})
if (!tokenResponse.ok) {
const errorText = await tokenResponse.text()
console.error("Token exchange failed:", errorText)
return NextResponse.redirect(new URL("/login?error=auth_failed", appHost))
}
Token exchange failed: {“error”:“invalid_grant”,“error_description”:“授权码无效或已过期”}