Skip to content

How to build 'entire' token? #356

Answered by lestrrat
michael-wang asked this question in Q&A
Discussion options

You must be logged in to vote

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)

eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJIZWxsbywg…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@michael-wang
Comment options

Answer selected by lestrrat
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