Skip to content

Commit 1d13876

Browse files
committed
Update examples
1 parent 003ab85 commit 1d13876

File tree

4 files changed

+16
-31
lines changed

4 files changed

+16
-31
lines changed

examples/http-example/main.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import (
99
"gopkg.in/square/go-jose.v2"
1010
"gopkg.in/square/go-jose.v2/jwt"
1111

12-
"github.com/auth0/go-jwt-middleware"
1312
"github.com/auth0/go-jwt-middleware/validate/josev2"
13+
14+
"github.com/auth0/go-jwt-middleware"
1415
)
1516

1617
var handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -32,19 +33,12 @@ func main() {
3233
return []byte("secret"), nil
3334
}
3435

35-
expectedClaimsFunc := func() jwt.Expected {
36-
// By setting up expected claims we are saying
37-
// a token must have the data we specify.
38-
return jwt.Expected{
39-
Issuer: "josev2-example",
40-
}
41-
}
42-
4336
// Set up the josev2 validator.
4437
validator, err := josev2.New(
4538
keyFunc,
4639
jose.HS256,
47-
josev2.WithExpectedClaims(expectedClaimsFunc),
40+
"josev2-example",
41+
jwt.Audience{},
4842
)
4943
if err != nil {
5044
log.Fatalf("failed to set up the josev2 validator: %v", err)

examples/http-jwks-example/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import (
88
"time"
99

1010
"gopkg.in/square/go-jose.v2"
11+
"gopkg.in/square/go-jose.v2/jwt"
1112

12-
"github.com/auth0/go-jwt-middleware"
1313
"github.com/auth0/go-jwt-middleware/validate/josev2"
14+
15+
"github.com/auth0/go-jwt-middleware"
1416
)
1517

1618
var handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -38,6 +40,8 @@ func main() {
3840
validator, err := josev2.New(
3941
provider.KeyFunc,
4042
jose.RS256,
43+
"josev2-example",
44+
jwt.Audience{},
4145
)
4246
if err != nil {
4347
log.Fatalf("failed to set up the josev2 validator: %v", err)

middleware_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,8 @@ func Test_CheckJWT(t *testing.T) {
3333
return []byte("secret"), nil
3434
},
3535
jose.HS256,
36-
josev2.WithExpectedClaims(
37-
func() jwt.Expected {
38-
return jwt.Expected{Issuer: "testing"}
39-
},
40-
),
36+
"testing",
37+
jwt.Audience{},
4138
)
4239
if err != nil {
4340
t.Fatal(err)

validate/josev2/examples/main.go

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,16 @@ func main() {
4949
return []byte("secret"), nil
5050
}
5151

52-
expectedClaims := func() jwt.Expected {
53-
// By setting up expected claims we are saying
54-
// a token must have the data we specify.
55-
return jwt.Expected{
56-
Issuer: "josev2-example",
57-
Time: time.Now(),
58-
}
59-
}
60-
61-
customClaims := func() josev2.CustomClaims {
62-
// We want this struct to be filled in with
63-
// our custom claims from the token.
64-
return &CustomClaimsExample{}
65-
}
52+
// We want this struct to be filled in with
53+
// our custom claims from the token.
54+
customClaims := &CustomClaimsExample{}
6655

6756
// Set up the josev2 validator.
6857
validator, err := josev2.New(
6958
keyFunc,
7059
jose.HS256,
71-
josev2.WithExpectedClaims(expectedClaims),
60+
"josev2-example",
61+
jwt.Audience{},
7262
josev2.WithCustomClaims(customClaims),
7363
josev2.WithAllowedClockSkew(30*time.Second),
7464
)

0 commit comments

Comments
 (0)