Skip to content

Commit

Permalink
get rid of jwt v1 direct dependency in example dir
Browse files Browse the repository at this point in the history
  • Loading branch information
paskal committed Jul 29, 2024
1 parent 7ea8cc5 commit 4dc75ad
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions _example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
log "github.com/go-pkgz/lgr"
"github.com/go-pkgz/rest"
"github.com/go-pkgz/rest/logger"
oldjwt "github.com/golang-jwt/jwt"
"github.com/golang-jwt/jwt/v5"
"golang.org/x/oauth2"

"github.com/go-pkgz/auth"
Expand Down Expand Up @@ -295,7 +295,7 @@ func initGoauth2Srv() *goauth2.Server {
manager.MustTokenStorage(store.NewMemoryTokenStore())

// generate jwt access token
manager.MapAccessGenerate(generates.NewJWTAccessGenerate("custom", []byte("00000000"), oldjwt.SigningMethodHS512))
manager.MapAccessGenerate(generates.NewJWTAccessGenerate("custom", []byte("00000000"), &signingMethodHMACWrapperV1{SigningMethodHMAC: jwt.SigningMethodHS512}))

// client memory store
clientStore := store.NewClientStore()
Expand Down Expand Up @@ -329,3 +329,18 @@ func initGoauth2Srv() *goauth2.Server {

return srv
}

type signingMethodHMACWrapperV1 struct {
*jwt.SigningMethodHMAC
}

// Verify the way it was implemented in v1, wrapper for v5
func (s *signingMethodHMACWrapperV1) Verify(signingString string, signature string, key interface{}) error {
return s.SigningMethodHMAC.Verify(signingString, []byte(signature), key)
}

// Sign the way it was implemented in v1, wrapper for v5
func (s signingMethodHMACWrapperV1) Sign(signingString string, key interface{}) (string, error) {
sig, err := s.SigningMethodHMAC.Sign(signingString, key)
return string(sig), err
}

0 comments on commit 4dc75ad

Please sign in to comment.