Skip to content

How can I use my own secret in V4 #32

Closed Answered by oSethoum
oSethoum asked this question in Q&A
Discussion options

You must be logged in to vote

found it, it's really easy and straight forward
UPDATE: not an answer

package main

import (
	"fmt"
	"time"

	"aidanwoods.dev/go-paseto"
)

func main() {
       // producing token
        token := paseto.NewToken()
	token.SetExpiration(time.Now().Add(time.Hour * 12))
	token.SetString("access", "products:view-many")
        key := paseto.NewV4SymmetricKey()
        t := token.V4Encrypt(key, []byte("secret"))

       // validating token
       vtoken, err := paseto.NewParser().ParseV4Local(key, t, []byte("secret"))
      if err != nil {
            panic(err)
      } else {
           println(vtoken.GetString("access"))
     }
}

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@aidantwoods
Comment options

@aidantwoods
Comment options

@oSethoum
Comment options

Answer selected by oSethoum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants