Created
July 6, 2020 03:09
-
-
Save bodhi/a7bd835e6fe0c7b3181747cf3159fc79 to your computer and use it in GitHub Desktop.
Paseto scratch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"fmt" | |
"time" | |
paseto "github.com/o1egl/paseto/v2" | |
) | |
func main() { | |
key := []byte("YELLOW SUBMARINE, BLACK WIZARDRY") | |
claims := paseto.JSONToken{ | |
Audience: "test", | |
IssuedAt: time.Now(), | |
Expiration: time.Now().Add(10 * time.Second), | |
} | |
fmt.Println(claims) | |
token, err := paseto.Encrypt(key, claims, nil) | |
fmt.Println(token) | |
var decrypted paseto.JSONToken | |
err = paseto.Decrypt(token, key, &decrypted, nil) | |
fmt.Println("decrypted", err, decrypted) | |
err = decrypted.Validate(paseto.ForAudience("test"), | |
paseto.ValidAt(time.Now())) | |
fmt.Println("validated", err) | |
err = decrypted.Validate(paseto.ForAudience("test2"), | |
paseto.ValidAt(time.Now())) | |
fmt.Println("validated wrong audience", err) | |
err = decrypted.Validate(paseto.ForAudience("test"), | |
paseto.ValidAt(time.Now().Add(30*time.Second))) | |
fmt.Println("validated expired", err) | |
err = decrypted.Validate(paseto.ForAudience("test2"), | |
paseto.ValidAt(time.Now().Add(30*time.Second))) | |
fmt.Println("validated expired/wrong audience", err) | |
} |
Author
bodhi
commented
Jul 6, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment