Essential Go JWT Authorization in Go  Edit on GitHub      File Issue

Using the StandardClaims type by itself to parse a token

The StandardClaims type is designed to be embedded into your custom types to provide standard validation features. You can use it alone, but there’s no way to retrieve other fields after parsing. See the custom claims example for intended usage.

mySigningKey := []byte("AllYourBase")

// Create the Claims
claims := &jwt.StandardClaims{
    ExpiresAt: 15000,
    Issuer:    "test",
}

token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
ss, err := token.SignedString(mySigningKey)
fmt.Printf("%v %v", ss, err)

Output:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MDAwLCJpc3MiOiJ0ZXN0In0.QsODzZu3lUZMVdhbO76u3Jv02iYCvEHcYVUI1kOWEU0 <nil>

(From the documentation, courtesy of Dave Grijalva.)

  ↑ ↓ to navigate     ↵ to select     Esc to close