From 25be3f40cce77c252da048962129eb95afe52ef8 Mon Sep 17 00:00:00 2001 From: Ewan Harris Date: Tue, 5 Dec 2023 12:14:35 +0000 Subject: [PATCH 1/2] Update golang backend qs to use latest versions --- .../backend/golang/01-authorization.md | 8 ++++---- articles/quickstart/backend/golang/files/jwt.md | 17 +++++++++-------- .../quickstart/backend/golang/files/main.md | 10 +++++++--- articles/quickstart/backend/golang/index.yml | 2 +- .../quickstart/backend/golang/interactive.md | 6 +++--- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/articles/quickstart/backend/golang/01-authorization.md b/articles/quickstart/backend/golang/01-authorization.md index 9c80f008f2..8fa1a0a938 100644 --- a/articles/quickstart/backend/golang/01-authorization.md +++ b/articles/quickstart/backend/golang/01-authorization.md @@ -28,11 +28,11 @@ Add a `go.mod` file to list all the dependencies to be used. module 01-Authorization-RS256 -go 1.16 +go 1.21 require ( - github.com/auth0/go-jwt-middleware/v2 v2.0.0 - github.com/joho/godotenv v1.4.0 + github.com/auth0/go-jwt-middleware/v2 v2.2.0 + github.com/joho/godotenv v1.5.1 ) ``` @@ -77,7 +77,7 @@ import ( "os" "time" - "github.com/auth0/go-jwt-middleware/v2" + jwtmiddleware "github.com/auth0/go-jwt-middleware/v2" "github.com/auth0/go-jwt-middleware/v2/jwks" "github.com/auth0/go-jwt-middleware/v2/validator" ) diff --git a/articles/quickstart/backend/golang/files/jwt.md b/articles/quickstart/backend/golang/files/jwt.md index 7c113a9b69..d9aba4c4f1 100644 --- a/articles/quickstart/backend/golang/files/jwt.md +++ b/articles/quickstart/backend/golang/files/jwt.md @@ -14,9 +14,10 @@ import ( "net/http" "net/url" "os" + "strings" "time" - "github.com/auth0/go-jwt-middleware/v2" + jwtmiddleware "github.com/auth0/go-jwt-middleware/v2" "github.com/auth0/go-jwt-middleware/v2/jwks" "github.com/auth0/go-jwt-middleware/v2/validator" ) @@ -77,13 +78,13 @@ func EnsureValidToken() func(next http.Handler) http.Handler { // HasScope checks whether our claims have a specific scope. func (c CustomClaims) HasScope(expectedScope string) bool { - result := strings.Split(c.Scope, " ") - for i := range result { - if result[i] == expectedScope { - return true - } - } + result := strings.Split(c.Scope, " ") + for i := range result { + if result[i] == expectedScope { + return true + } + } - return false + return false } ``` diff --git a/articles/quickstart/backend/golang/files/main.md b/articles/quickstart/backend/golang/files/main.md index b22b8cd1ba..5e8d5498df 100644 --- a/articles/quickstart/backend/golang/files/main.md +++ b/articles/quickstart/backend/golang/files/main.md @@ -9,10 +9,13 @@ language: go package main import ( + "01-Authorization-RS256/middleware" "log" "net/http" + + jwtmiddleware "github.com/auth0/go-jwt-middleware/v2" + "github.com/auth0/go-jwt-middleware/v2/validator" "github.com/joho/godotenv" - "01-Authorization-RS256/middleware" ) func main() { @@ -37,9 +40,9 @@ func main() { w.Write([]byte(`{"message":"Hello from a private endpoint! You need to be authenticated to see this."}`)) }), )) - + // This route is only accessible if the user has a - // valid access_token with the read:messages scope. + // valid access_token with the read:messages scope. router.Handle("/api/private-scoped", middleware.EnsureValidToken()( http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") @@ -63,4 +66,5 @@ func main() { log.Fatalf("There was an error with the http server: %v", err) } } + ``` diff --git a/articles/quickstart/backend/golang/index.yml b/articles/quickstart/backend/golang/index.yml index 6f5160e9d3..08e116eafa 100644 --- a/articles/quickstart/backend/golang/index.yml +++ b/articles/quickstart/backend/golang/index.yml @@ -36,7 +36,7 @@ sdk: url: https://github.com/auth0/go-jwt-middleware logo: golang requirements: - - Go 1.15+ + - Go 1.21+ next_steps: - path: 01-authorization list: diff --git a/articles/quickstart/backend/golang/interactive.md b/articles/quickstart/backend/golang/interactive.md index 3d4f17ef04..5acb9131e8 100644 --- a/articles/quickstart/backend/golang/interactive.md +++ b/articles/quickstart/backend/golang/interactive.md @@ -40,11 +40,11 @@ Add a `go.mod` file to list all the necessary dependencies. module 01-Authorization-RS256 -go 1.16 +go 1.21 require ( - github.com/auth0/go-jwt-middleware/v2 v2.0.0 - github.com/joho/godotenv v1.4.0 + github.com/auth0/go-jwt-middleware/v2 v2.2.0 + github.com/joho/godotenv v1.5.1 ) ``` From 52ca19aece962b69bfb45c9e3d4864370a105b04 Mon Sep 17 00:00:00 2001 From: Ewan Harris Date: Tue, 5 Dec 2023 12:14:55 +0000 Subject: [PATCH 2/2] Update golang webapp qs to use latest versions --- articles/quickstart/webapp/golang/01-login.md | 12 ++++++------ articles/quickstart/webapp/golang/files/go-mod.md | 12 ++++++------ articles/quickstart/webapp/golang/index.yml | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/articles/quickstart/webapp/golang/01-login.md b/articles/quickstart/webapp/golang/01-login.md index 08db10ba8d..b2600c857b 100644 --- a/articles/quickstart/webapp/golang/01-login.md +++ b/articles/quickstart/webapp/golang/01-login.md @@ -27,14 +27,14 @@ Start by adding a `go.mod` file to list all the dependencies to be used. module 01-Login -go 1.16 +go 1.21 require ( - github.com/coreos/go-oidc/v3 v3.1.0 - github.com/gin-contrib/sessions v0.0.3 - github.com/gin-gonic/gin v1.7.4 - github.com/joho/godotenv v1.4.0 - golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d + github.com/coreos/go-oidc/v3 v3.8.0 + github.com/gin-contrib/sessions v0.0.5 + github.com/gin-gonic/gin v1.9.1 + github.com/joho/godotenv v1.5.1 + golang.org/x/oauth2 v0.15.0 ) ``` diff --git a/articles/quickstart/webapp/golang/files/go-mod.md b/articles/quickstart/webapp/golang/files/go-mod.md index 2cb0a7f3ce..636aa7c45f 100644 --- a/articles/quickstart/webapp/golang/files/go-mod.md +++ b/articles/quickstart/webapp/golang/files/go-mod.md @@ -8,13 +8,13 @@ language: go-mod module 01-Login -go 1.16 +go 1.21 require ( - github.com/coreos/go-oidc/v3 v3.1.0 - github.com/gin-contrib/sessions v0.0.3 - github.com/gin-gonic/gin v1.7.4 - github.com/joho/godotenv v1.4.0 - golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d + github.com/coreos/go-oidc/v3 v3.8.0 + github.com/gin-contrib/sessions v0.0.5 + github.com/gin-gonic/gin v1.9.1 + github.com/joho/godotenv v1.5.1 + golang.org/x/oauth2 v0.15.0 ) ``` diff --git a/articles/quickstart/webapp/golang/index.yml b/articles/quickstart/webapp/golang/index.yml index 0c08eb0779..38a4052a43 100644 --- a/articles/quickstart/webapp/golang/index.yml +++ b/articles/quickstart/webapp/golang/index.yml @@ -26,7 +26,7 @@ github: repo: auth0-golang-web-app branch: master requirements: - - Go 1.16+ + - Go 1.21+ next_steps: - path: 01-login list: