How to build 'entire' token? #356
-
I can new a token: But according to jwt.io, a JWT token has 3 segments: "header.payload.signature" So my question is:
Thanks for any help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Assuming you are doing everything correctly, you should get a proper JWS with three segments. I think you are just not catching the "."'s package main
import (
"crypto/rand"
"crypto/rsa"
"fmt"
"github.com/lestrrat-go/jwx/jwa"
"github.com/lestrrat-go/jwx/jwt"
)
func main() {
privKey, _ := rsa.GenerateKey(rand.Reader, 2048)
tok := jwt.New()
tok.Set(jwt.SubjectKey, "Hello, World")
signed, err := jwt.Sign(tok, jwa.RS256, privKey)
if err != nil {
panic(err)
}
fmt.Printf("%s", signed)
} Code like above will output something like the following (the output will always change because the key changes every run)
If you look closely you will notice the dots, and see that you have three segments
|
Beta Was this translation helpful? Give feedback.
Assuming you are doing everything correctly, you should get a proper JWS with three segments. I think you are just not catching the "."'s
Code like above will output something like the following (the output will always change because the key changes every run)