Skip to content

Commit 4b34e17

Browse files
authored
Upgrade github.com/golang-jwt/jwt to v5 for LINE provider (#602)
Signed-off-by: Eng Zer Jun <[email protected]>
1 parent 8b2bdca commit 4b34e17

File tree

3 files changed

+10
-31
lines changed

3 files changed

+10
-31
lines changed

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ go 1.18
44

55
require (
66
github.com/go-chi/chi/v5 v5.1.0
7-
github.com/golang-jwt/jwt/v4 v4.5.1
8-
github.com/golang-jwt/jwt/v5 v5.2.1
7+
github.com/golang-jwt/jwt/v5 v5.2.2
98
github.com/gorilla/mux v1.6.2
109
github.com/gorilla/pat v0.0.0-20180118222023-199c85a7f6d1
1110
github.com/gorilla/sessions v1.1.1

go.sum

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,14 @@ github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw=
1313
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
1414
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
1515
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
16-
github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo=
17-
github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
18-
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
19-
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
16+
github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8=
17+
github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
2018
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
2119
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
2220
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
2321
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
2422
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
2523
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
26-
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
2724
github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8=
2825
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
2926
github.com/gorilla/mux v1.6.2 h1:Pgr17XVTNXAk3q/r4CpKzC5xBM/qW1uVLV+IhRZpIIk=

providers/line/line.go

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import (
88
"fmt"
99
"io"
1010
"net/http"
11-
"time"
1211

13-
"github.com/golang-jwt/jwt/v4"
12+
"github.com/golang-jwt/jwt/v5"
1413
"github.com/markbates/goth"
1514
"golang.org/x/oauth2"
1615
)
@@ -23,7 +22,7 @@ const (
2322
)
2423

2524
type IDTokenClaims struct {
26-
jwt.StandardClaims
25+
jwt.RegisteredClaims
2726
Email string `json:"email"`
2827
}
2928

@@ -181,28 +180,12 @@ func (p *Provider) SetBotPrompt(botPrompt string) {
181180

182181
func (p *Provider) addDataFromIdToken(idToken string, user *goth.User) error {
183182
token, err := jwt.ParseWithClaims(idToken, &IDTokenClaims{}, func(t *jwt.Token) (interface{}, error) {
184-
claims := t.Claims.(*IDTokenClaims)
185-
vErr := new(jwt.ValidationError)
186-
187-
if !claims.VerifyAudience(p.ClientKey, true) {
188-
vErr.Inner = fmt.Errorf("audience is incorrect")
189-
vErr.Errors |= jwt.ValidationErrorAudience
190-
}
191-
if !claims.VerifyIssuer(issuerURL, true) {
192-
vErr.Inner = fmt.Errorf("issuer is incorrect")
193-
vErr.Errors |= jwt.ValidationErrorIssuer
194-
}
195-
if !claims.VerifyExpiresAt(time.Now().Unix(), true) {
196-
vErr.Inner = fmt.Errorf("token is expired")
197-
vErr.Errors |= jwt.ValidationErrorExpired
198-
}
199-
if vErr.Errors > 0 {
200-
return nil, vErr
201-
}
202-
203183
return []byte(p.Secret), nil
204-
})
205-
184+
},
185+
jwt.WithAudience(p.ClientKey),
186+
jwt.WithIssuer(issuerURL),
187+
jwt.WithExpirationRequired(),
188+
)
206189
if err != nil {
207190
return err
208191
}

0 commit comments

Comments
 (0)