Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing token and getting payload #53

Open
mikolajsemeniuk opened this issue Apr 7, 2022 · 1 comment
Open

Parsing token and getting payload #53

mikolajsemeniuk opened this issue Apr 7, 2022 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@mikolajsemeniuk
Copy link

Parsing token and getting payload

Is there any way to extract claims from token like in this package (any example appreciated)?

@gbrlsnchs
Copy link
Owner

In order to parse the token you'll need to verify it:

import "github.com/gbrlsnchs/jwt/v3"

type CustomPayload struct {
	jwt.Payload
	Foo string `json:"foo,omitempty"`
	Bar int    `json:"bar,omitempty"`
}

var hs = jwt.NewHS256([]byte("secret"))

func main() {
	// ...

	var pl CustomPayload
	hd, err := jwt.Verify(token, hs, &pl)
	if err != nil {
		// ...
	}

	// ...
}

This was done on purpose in order to avoid security flaws where users use data from tokens that weren't validated.

Let me know if this info is enough for you so I can close this issue. 😃

@gbrlsnchs gbrlsnchs added the question Further information is requested label Apr 8, 2022
@gbrlsnchs gbrlsnchs self-assigned this Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants