Using RegisteredClaims to create a token

suggest change

RegisteredClaims represents the claims registered by the JWT specification. It can be used by itself or embedded in a custom claims type.

mySigningKey := []byte("AllYourBase")

// Create the Claims
claims := &jwt.RegisteredClaims{
    ExpiresAt: jwt.NewNumericDate(time.Unix(15000, 0)),
    Issuer:    "test",
}

token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
ss, err := token.SignedString(mySigningKey)
fmt.Printf("%v %v", ss, err)
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MDAwLCJpc3MiOiJ0ZXN0In0.QsODzZu3lUZMVdhbO76u3Jv02iYCvEHcYVUI1kOWEU0 <nil>

Real applications should use a strong, randomly generated key and a meaningful expiration time. Never commit a production signing key to source control.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents