From e7296d2b5e44d6648a743ffc4c018ca4b77c6802 Mon Sep 17 00:00:00 2001 From: Godopu Date: Mon, 26 Dec 2022 15:06:41 +0900 Subject: [PATCH] update checkAuthority --- webserver/go.mod | 2 ++ webserver/go.sum | 4 ++++ webserver/router/auth.go | 2 +- webserver/router/route.go | 11 +++-------- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/webserver/go.mod b/webserver/go.mod index fc269b6..7a4d41e 100644 --- a/webserver/go.mod +++ b/webserver/go.mod @@ -5,6 +5,8 @@ go 1.19 require ( github.com/coreos/go-oidc v2.2.1+incompatible github.com/gin-gonic/gin v1.8.2 + github.com/golang-jwt/jwt/v4 v4.4.3 + github.com/google/uuid v1.3.0 golang.org/x/oauth2 v0.3.0 ) diff --git a/webserver/go.sum b/webserver/go.sum index 7e61804..bfea184 100644 --- a/webserver/go.sum +++ b/webserver/go.sum @@ -18,6 +18,8 @@ github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJ github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU= github.com/goccy/go-json v0.9.11 h1:/pAaQDLHEoCq/5FFmSKBswWmK6H0e8g4159Kc/X/nqk= github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/golang-jwt/jwt/v4 v4.4.3 h1:Hxl6lhQFj4AnOX6MLrsCb/+7tCj7DxP7VA+2rDIq5AU= +github.com/golang-jwt/jwt/v4 v4.4.3/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= @@ -25,6 +27,8 @@ github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= diff --git a/webserver/router/auth.go b/webserver/router/auth.go index cafb677..236c633 100644 --- a/webserver/router/auth.go +++ b/webserver/router/auth.go @@ -95,7 +95,7 @@ func authCallback(ctx *gin.Context) { return } - ss, err := authmod.IssueJWT(userInfo, time.Second) + ss, err := authmod.IssueJWT(userInfo, time.Hour) if err != nil { http.Error(ctx.Writer, "generate jwt error", http.StatusInternalServerError) return diff --git a/webserver/router/route.go b/webserver/router/route.go index 47a21f3..8ebaace 100644 --- a/webserver/router/route.go +++ b/webserver/router/route.go @@ -29,7 +29,7 @@ func NewRouter() *gin.Engine { r.Any("/*any", func(c *gin.Context) { defer handleError(c) path := c.Param("any") - if strings.HasPrefix(path, "/dashboard") { + if strings.HasPrefix(path, "/home") { assetEngine.HandleContext(c) return } else if strings.HasPrefix(path, "/auth") { @@ -71,14 +71,9 @@ func checkAuthority(c *gin.Context) bool { return false } - claims, err := authmod.ParseJWTwithClaims(editAuth) - if err != nil { - return false - } + _, err = authmod.ParseJWTwithClaims(editAuth) - fmt.Println(claims.UserInfo) - - return true + return err == nil } func handleError(c *gin.Context) {