Skip to content

Commit 9272752

Browse files
committed
fix: Apparently spelling is hard - fixed spelling on ExampleMesage => ExampleMessage
Added main.go and README.md for grpc-example
1 parent 088c2e7 commit 9272752

File tree

17 files changed

+153
-84
lines changed

17 files changed

+153
-84
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import (
4545

4646
"github.com/auth0/go-jwt-middleware/v2"
4747
"github.com/auth0/go-jwt-middleware/v2/validator"
48-
jwtmiddleware "github.com/auth0/go-jwt-middleware/v2"
4948
)
5049

5150
var handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -68,7 +67,7 @@ var handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
6867
func main() {
6968
keyFunc := func(ctx context.Context) (interface{}, error) {
7069
// Our token must be signed using this data.
71-
return []byte("secret"), nil
70+
return []byte("abcdefghijklmnopqrstuvwxyz012345"), nil
7271
}
7372

7473
// Set up the validator.
@@ -92,7 +91,7 @@ func main() {
9291
After running that code (`go run main.go`) you can then curl the http server from another terminal:
9392

9493
```
95-
$ curl -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJpc3MiOiJnby1qd3QtbWlkZGxld2FyZS1leGFtcGxlIiwiYXVkIjoiZ28tand0LW1pZGRsZXdhcmUtZXhhbXBsZSJ9.xcnkyPYu_b3qm2yeYuEgr5R5M5t4pN9s04U1ya53-KM" localhost:3000
94+
$ curl -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJpc3MiOiJnby1qd3QtbWlkZGxld2FyZS1leGFtcGxlIiwiYXVkIjoiZ28tand0LW1pZGRsZXdhcmUtZXhhbXBsZSJ9.Wkxc3JFClh8CVeGpZlsW4vhlcvCQpyTGkL8ezcp-V-A" localhost:3000
9695
```
9796

9897
That should give you the following response:
@@ -109,7 +108,7 @@ That should give you the following response:
109108
}
110109
```
111110

112-
The JWT included in the Authorization header above is signed with `secret`.
111+
The JWT included in the Authorization header above is signed with `abcdefghijklmnopqrstuvwxyz012345`.
113112

114113
To test how the response would look like with an invalid token:
115114

examples/echo-example/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import (
44
"log"
55
"net/http"
66

7-
jwtmiddleware "github.com/auth0/go-jwt-middleware/v2"
7+
"github.com/auth0/go-jwt-middleware/v2"
88
"github.com/auth0/go-jwt-middleware/v2/validator"
99
"github.com/labstack/echo/v4"
1010
)
1111

1212
// Try it out with:
1313
//
14-
// eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnby1qd3QtbWlkZGxld2FyZS1leGFtcGxlIiwiYXVkIjoiYXVkaWVuY2UtZXhhbXBsZSIsInN1YiI6IjEyMzQ1Njc4OTAiLCJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjE1MTYyMzkwMjIsInVzZXJuYW1lIjoidXNlcjEyMyJ9.XFhrzWzntyINkgoRt2mb8dES84dJcuOoORdzKfwUX70
14+
// eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnby1qd3QtbWlkZGxld2FyZS1leGFtcGxlIiwiYXVkIjoiYXVkaWVuY2UtZXhhbXBsZSIsInN1YiI6IjEyMzQ1Njc4OTAiLCJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjE1MTYyMzkwMjIsInVzZXJuYW1lIjoidXNlcjEyMyJ9.DSY4NlpZZ2mOqaKuXvJkOrgZA3nD5HuGaf1wB9-0OVw
1515
//
16-
// which is signed with 'secret' and has the data:
16+
// which is signed with 'abcdefghijklmnopqrstuvwxyz012345' and has the data:
1717
//
1818
// {
1919
// "iss": "go-jwt-middleware-example",
@@ -26,9 +26,9 @@ import (
2626
//
2727
// You can also try out the custom validation with:
2828
//
29-
// eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnby1qd3QtbWlkZGxld2FyZS1leGFtcGxlIiwiYXVkIjoiYXVkaWVuY2UtZXhhbXBsZSIsInN1YiI6IjEyMzQ1Njc4OTAiLCJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjE1MTYyMzkwMjIsInVzZXJuYW1lIjoidXNlcjEyMyIsInNob3VsZFJlamVjdCI6dHJ1ZX0.Jf13PY_Oyu2x3Gx1JQ0jXRiWaCOb5T2RbKOrTPBNHJA
29+
// eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnby1qd3QtbWlkZGxld2FyZS1leGFtcGxlIiwiYXVkIjoiYXVkaWVuY2UtZXhhbXBsZSIsInN1YiI6IjEyMzQ1Njc4OTAiLCJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjE1MTYyMzkwMjIsInVzZXJuYW1lIjoidXNlcjEyMyIsInNob3VsZFJlamVjdCI6dHJ1ZX0.qjjJBgKNomlbEQrCobpEU9ASgvSpLQhQBryRkp6-RQc
3030
//
31-
// which is signed with 'secret' and has the data:
31+
// which is signed with 'abcdefghijklmnopqrstuvwxyz012345' and has the data:
3232
//
3333
// {
3434
// "iss": "go-jwt-middleware-example",

examples/echo-example/middleware.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import (
77
"net/http"
88
"time"
99

10-
jwtmiddleware "github.com/auth0/go-jwt-middleware/v2"
10+
"github.com/auth0/go-jwt-middleware/v2"
1111
"github.com/auth0/go-jwt-middleware/v2/validator"
1212
)
1313

1414
var (
1515
// The signing key for the token.
16-
signingKey = []byte("secret")
16+
signingKey = []byte("abcdefghijklmnopqrstuvwxyz012345")
1717

1818
// The issuer of our token.
1919
issuer = "go-jwt-middleware-example"

examples/gin-example/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import (
44
"log"
55
"net/http"
66

7-
jwtmiddleware "github.com/auth0/go-jwt-middleware/v2"
7+
"github.com/auth0/go-jwt-middleware/v2"
88
"github.com/auth0/go-jwt-middleware/v2/validator"
99
"github.com/gin-gonic/gin"
1010
)
1111

1212
// Try it out with:
1313
//
14-
// eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnby1qd3QtbWlkZGxld2FyZS1leGFtcGxlIiwiYXVkIjoiYXVkaWVuY2UtZXhhbXBsZSIsInN1YiI6IjEyMzQ1Njc4OTAiLCJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjE1MTYyMzkwMjIsInVzZXJuYW1lIjoidXNlcjEyMyJ9.XFhrzWzntyINkgoRt2mb8dES84dJcuOoORdzKfwUX70
14+
// eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnby1qd3QtbWlkZGxld2FyZS1leGFtcGxlIiwiYXVkIjoiYXVkaWVuY2UtZXhhbXBsZSIsInN1YiI6IjEyMzQ1Njc4OTAiLCJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjE1MTYyMzkwMjIsInVzZXJuYW1lIjoidXNlcjEyMyJ9.DSY4NlpZZ2mOqaKuXvJkOrgZA3nD5HuGaf1wB9-0OVw
1515
//
16-
// which is signed with 'secret' and has the data:
16+
// which is signed with 'abcdefghijklmnopqrstuvwxyz012345' and has the data:
1717
//
1818
// {
1919
// "iss": "go-jwt-middleware-example",
@@ -26,9 +26,9 @@ import (
2626
//
2727
// You can also try out the custom validation with:
2828
//
29-
// eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnby1qd3QtbWlkZGxld2FyZS1leGFtcGxlIiwiYXVkIjoiYXVkaWVuY2UtZXhhbXBsZSIsInN1YiI6IjEyMzQ1Njc4OTAiLCJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjE1MTYyMzkwMjIsInVzZXJuYW1lIjoidXNlcjEyMyIsInNob3VsZFJlamVjdCI6dHJ1ZX0.Jf13PY_Oyu2x3Gx1JQ0jXRiWaCOb5T2RbKOrTPBNHJA
29+
// eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnby1qd3QtbWlkZGxld2FyZS1leGFtcGxlIiwiYXVkIjoiYXVkaWVuY2UtZXhhbXBsZSIsInN1YiI6IjEyMzQ1Njc4OTAiLCJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjE1MTYyMzkwMjIsInVzZXJuYW1lIjoidXNlcjEyMyIsInNob3VsZFJlamVjdCI6dHJ1ZX0.qjjJBgKNomlbEQrCobpEU9ASgvSpLQhQBryRkp6-RQc
3030
//
31-
// which is signed with 'secret' and has the data:
31+
// which is signed with 'abcdefghijklmnopqrstuvwxyz012345' and has the data:
3232
//
3333
// {
3434
// "iss": "go-jwt-middleware-example",

examples/gin-example/middleware.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import (
66
"net/http"
77
"time"
88

9-
jwtmiddleware "github.com/auth0/go-jwt-middleware/v2"
9+
"github.com/auth0/go-jwt-middleware/v2"
1010
"github.com/auth0/go-jwt-middleware/v2/validator"
1111
"github.com/gin-gonic/gin"
1212
)
1313

1414
var (
1515
// The signing key for the token.
16-
signingKey = []byte("secret")
16+
signingKey = []byte("abcdefghijklmnopqrstuvwxyz012345")
1717

1818
// The issuer of our token.
1919
issuer = "go-jwt-middleware-example"

examples/grpc-example/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# GRPC example
2+
3+
This is an example of how to use the grpc middleware.
4+
5+
# Using it
6+
7+
To try this out:
8+
9+
* Install all dependencies with `go mod vendor`.
10+
* Run `go run main.go` to start the app.
11+
* Use [jwt.io](https://jwt.io/) to generate a JWT signed with the HS256 algorithm and `abcdefghijklmnopqrstuvwxyz012345`.
12+
* [optional] use [grpc-client-cli](https://github.com/vadimi/grpc-client-cli) and run `echo '{"msg":"hello"}' | grpc-client-cli --insecure --proto=example.proto --header "authorization: <jwt from jwt.io>" --service ExampleService --method DoSomething localhost:8080
13+
`

examples/grpc-example/example.pb.go

Lines changed: 23 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/grpc-example/example.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ package example;
44
option go_package = "example.com/main";
55

66
service ExampleService {
7-
rpc DoSomething(ExampleMesage) returns (ExampleMesage) {}
7+
rpc DoSomething(ExampleMessage) returns (ExampleMessage) {}
88
}
99

10-
message ExampleMesage {
10+
message ExampleMessage {
1111
string msg = 1;
1212
}

examples/grpc-example/example_grpc.pb.go

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/grpc-example/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/auth0/go-jwt-middleware/v2 v2.0.0-00010101000000-000000000000
77
github.com/stretchr/testify v1.9.0
88
google.golang.org/grpc v1.68.0
9-
google.golang.org/protobuf v1.34.2
9+
google.golang.org/protobuf v1.35.1
1010
)
1111

1212
require (

0 commit comments

Comments
 (0)