子衿沉夜
看看 https://github.com/googleapis/google-api-php-client/blob/2fb6e702aca5d68203fa737f89f6f774022494c6/src/AccessToken/Verify.php#L90 上的php示例,似乎Google API使用RS256(RSA签名与SHA-256)对令牌进行签名。以下代码应验证签名并分析令牌。无需在代码中拆分令牌。新浪网.RSACheck(token []byte, key *rsa.PublicKey) (*jwt.“github.com/pascaldekloe/jwt”包中的索赔,错误)将为您完成所有繁重的工作。keyLocation是存储在本地的Google公钥package mainimport "github.com/pascaldekloe/jwt"//jwtValidator verifies and parses the JWT Tokenfunc jwtValidator(token string, keyLocation string) (j *jwtToken, err error) { token := []byte(token) pubK, err := rsaPublicKey(keyLocation) if err != nil { return } // parses the token only if signature is valid claims, err := jwt.RSACheck(token, pubK) if err != nil { err = fmt.Errorf("token signature invalid %s", err) return } if !claims.Valid(time.Now()) { err = fmt.Errorf("token time constraints exceeded") return } j = &jwtToken{ id: claims.ID, issuer: claims.Issuer, issued: claims.Issued, subject: claims.Subject, expires: claims.Expires, } return}