设置:React 前端和 Golang 后端。
我的 React 前端成功从 Google 获取令牌:
<GoogleLogin
clientId="<client-id>.apps.googleusercontent.com"
onSuccess={response => responseGoogle(response)}
>
</GoogleLogin>
我有一个突变可以发送我需要的信息:
initiateTestMutation({
variables: {
idToken: response.getAuthResponse().id_token,
email: response.profileObj.email,
givenName: response.profileObj.givenName,
familyName: response.profileObj.familyName,
}
}
然后它发送一个我可以用 jwt.io 解码的令牌,但它显示“无效签名”。它包含我的正确信息,但同样无效。
在我的服务器端,我也尝试验证它并失败了。
// This is the token as a string
unencodedToken := *input.IDToken
fmt.Println(unencodedToken)
token, err := jwt.Parse(unencodedToken, func(token *jwt.Token) (interface{}, error){
return []byte("What goes here?"), nil
})
if err != nil {
fmt.Println("Could not decode the token")
fmt.Println(err)
}
if token.Valid {
fmt.Println("Valid token")
} else if ve, ok := err.(*jwt.ValidationError); ok {
if ve.Errors&jwt.ValidationErrorMalformed != 0 {
fmt.Println("That's not even a token")
} else if ve.Errors&(jwt.ValidationErrorExpired|jwt.ValidationErrorNotValidYet) != 0 {
// Token is either expired or not active yet
fmt.Println("Expired token")
} else {
fmt.Println("Couldn't handle this token:", err)
}
} else {
fmt.Println("Couldn't handle this token:", err)
}
其他信息:
这一切都在本地完成。app.localhost是请求作为已批准来源添加的 JWT 的域
慕丝7291255
相关分类