Skip to content

How to parse the JWT payload with keyset json file? #480

Answered by Modeux
Modeux asked this question in Q&A
Discussion options

You must be logged in to vote

Ok, I have figured it out by myself.

For someone not familiar with JWK and JWT, I'll describe my steps more clearly.

  1. Create the RSA key pair.
raw, err := rsa.GenerateKey(rand.Reader, 2048)
	if err != nil {
		fmt.Printf("failed to generate new RSA privatre key: %s\n", err)
		return
	}
	key, err := jwk.New(raw)
	if err != nil {
		fmt.Printf("failed to create symmetric key: %s\n", err)
		return
	}

	if _, ok := key.(jwk.RSAPrivateKey); !ok {
		fmt.Printf("expected jwk.SymmetricKey, got %T\n", key)
		return
	}
	key.Set(jwk.KeyIDKey, "mykey")
	key.Set(jwk.AlgorithmKey, jwa.RS256)

	buf, err := json.MarshalIndent(key, "", "  ")
	if err != nil {
		fmt.Printf("failed to marshal key into JSON: %…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@lestrrat
Comment options

@Modeux
Comment options

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