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

drop legacy #22

Merged
merged 3 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
The purpose of this package is to provide a
[`jwt.Keyfunc`](https://pkg.go.dev/github.com/golang-jwt/jwt/v4#Keyfunc) for the
[github.com/golang-jwt/jwt/v4](https://github.com/golang-jwt/jwt) package and its popular forks using a JSON Web Key Set
(JWKs) for parsing and verifying JSON Web Tokens (JWTs). This
was [formally](https://github.com/dgrijalva/jwt-go/issues/462)
the [github.com/dgrijalva/jwt-go](https://github.com/dgrijalva/jwt-go) package.
(JWKs) for parsing and verifying JSON Web Tokens (JWTs).

It's common for an identity provider, such as [Keycloak](https://www.keycloak.org/)
or [Amazon Cognito (AWS)](https://aws.amazon.com/cognito/) to expose a JWKs via an HTTPS endpoint. This package has the
Expand All @@ -17,7 +15,6 @@ HTTPS to ensure the keys are from the correct trusted source.

This repository has the following dependencies:
* [github.com/golang-jwt/jwt/v4](https://github.com/golang-jwt/jwt)
* [github.com/dgrijalva/jwt-go](https://github.com/dgrijalva/jwt-go)
* [github.com/form3tech-oss/jwt-go](https://github.com/form3tech-oss/jwt-go)

`jwt.Keyfunc` signatures are imported from these, implemented, then exported as methods.
Expand Down Expand Up @@ -154,12 +151,6 @@ jwtMiddleware := jwtmiddleware.New(jwtmiddleware.Options{
})
```

### Support for [github.com/dgrijalva/jwt-go](https://github.com/dgrijalva/jwt-go)
This project originally only supported [github.com/dgrijalva/jwt-go](https://github.com/dgrijalva/jwt-go), but since it
is no longer maintained, it's method was moved
to [`JWKs.KeyfuncLegacy`](https://pkg.go.dev/github.com/MicahParks/keyfunc#JWKs.KeyfuncLegacy) if you have not moved to
[github.com/golang-jwt/jwt/v4](https://github.com/golang-jwt/jwt) yet.

## Test coverage

Test coverage is currently `>90%`.
Expand Down
2 changes: 0 additions & 2 deletions examples/auth0middleware/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
github.com/auth0/go-jwt-middleware v1.0.1 h1:/fsQ4vRr4zod1wKReUH+0A3ySRjGiT9G34kypO/EKwI=
github.com/auth0/go-jwt-middleware v1.0.1/go.mod h1:YSeUX3z6+TF2H+7padiEqNJ73Zy9vXW72U//IgN0BIM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
github.com/form3tech-oss/jwt-go v3.2.5+incompatible h1:/l4kBbb4/vGSsdtB5nUe8L7B9mImVMaBPw9L/0TBHU8=
github.com/form3tech-oss/jwt-go v3.2.5+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/MicahParks/keyfunc
go 1.13

require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/form3tech-oss/jwt-go v3.2.5+incompatible
github.com/golang-jwt/jwt/v4 v4.0.0
)
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/form3tech-oss/jwt-go v3.2.5+incompatible h1:/l4kBbb4/vGSsdtB5nUe8L7B9mImVMaBPw9L/0TBHU8=
github.com/form3tech-oss/jwt-go v3.2.5+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
github.com/golang-jwt/jwt/v4 v4.0.0 h1:RAqyYixv1p7uEnocuy8P1nru5wprCh/MH2BIlW5z5/o=
Expand Down
8 changes: 0 additions & 8 deletions jwks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"testing"
"time"

jwtLegacy "github.com/dgrijalva/jwt-go"
jwtF3T "github.com/form3tech-oss/jwt-go"
"github.com/golang-jwt/jwt/v4"

Expand Down Expand Up @@ -177,13 +176,6 @@ func TestJWKs(t *testing.T) {
}
}

// Use the JWKs jwt.Keyfunc to parse the token for supported forks.
if _, err = jwtLegacy.Parse(tc.token, jwks.KeyfuncLegacy); err != nil {
if errors.Is(err, jwt.ErrInvalidKeyType) {
t.Errorf("Invaild key type selected for legacy.\nError: %s", err.Error())
t.FailNow()
}
}
if _, err = jwtF3T.Parse(tc.token, jwks.KeyfuncF3T); err != nil {
if errors.Is(err, jwt.ErrInvalidKeyType) {
t.Errorf("Invaild key type selected for F3T.\nError: %s", err.Error())
Expand Down
15 changes: 0 additions & 15 deletions keyfunc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"

legacy "github.com/dgrijalva/jwt-go"
f3t "github.com/form3tech-oss/jwt-go"
"github.com/golang-jwt/jwt/v4"
)
Expand Down Expand Up @@ -71,17 +70,3 @@ func (j *JWKs) KeyfuncF3T(f3tToken *f3t.Token) (interface{}, error) {
}
return j.Keyfunc(token)
}

// KeyfuncLegacy is a compatibility function that matches the signature of the legacy github.com/dgrijalva/jwt-go's
// Keyfunc function.
func (j *JWKs) KeyfuncLegacy(legacyToken *legacy.Token) (interface{}, error) {
token := &jwt.Token{
Raw: legacyToken.Raw,
Method: legacyToken.Method,
Header: legacyToken.Header,
Claims: legacyToken.Claims,
Signature: legacyToken.Signature,
Valid: legacyToken.Valid,
}
return j.Keyfunc(token)
}