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
2524type 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
182181func (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