Skip to content
This repository has been archived by the owner on May 21, 2022. It is now read-only.

Create token example doesn't works #450

Open
victorabarros opened this issue Feb 9, 2021 · 2 comments
Open

Create token example doesn't works #450

victorabarros opened this issue Feb 9, 2021 · 2 comments

Comments

@victorabarros
Copy link

Hi guys!

I'm having some problem in try create token following:

	// Create the token
	token := jwt.New(jwt.GetSigningMethod("HS256"))
	// Set some claims
	token.Claims["foo"] = "bar"
	token.Claims["exp"] = time.Now().Add(time.Hour * 72).Unix()
	// Sign and get the complete encoded token as a string
	tokenString, err := token.SignedString(mySigningKey)
go: finding module for package github.com/dgrijalva/jwt-go
go: downloading github.com/dgrijalva/jwt-go v1.0.2
go: downloading github.com/dgrijalva/jwt-go v3.2.0+incompatible
go: found github.com/dgrijalva/jwt-go in github.com/dgrijalva/jwt-go v3.2.0+incompatible
./prog.go:12:14: invalid operation: token.Claims["foo"] (type jwt.Claims does not support indexing)

The issue #388 (comment) helps to solve, but I think would be better if the example from documentation works too.

@victorabarros victorabarros changed the title Create toke example doesn't works Create token example doesn't works Feb 23, 2021
@WhyNotHugo
Copy link

It looks like the API changed several years ago, but none of the documentation has been updated since.

If anyone has examples for how the new API works, that's be super useful. I'm not sure if versions > 1.0.2 are considered usable though, maybe they're still experimental?

@victorabarros
Copy link
Author

#388 (comment) helps?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants