From ea8ed9202a4ff72a6d1976feda608bac8059276b Mon Sep 17 00:00:00 2001 From: ACoolName Date: Sat, 25 May 2024 22:16:13 +0300 Subject: [PATCH] done --- auth/auth.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index b58eb6d..d14356e 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -194,13 +194,28 @@ func (con Connection) signIn(c *gin.Context) { } func (con Connection) verify(c *gin.Context) { - claims, exists := c.Get("claims") - if !exists { - log.Println("No Claims") - c.AbortWithStatus(403) + authCookie, err := c.Request.Cookie("auth") + if err != nil { + c.Redirect(303, fmt.Sprintf("http://%s/", DOMAIN)) return } + token, err := jwt.ParseWithClaims(authCookie.Value, &AuthClaims{}, func(token *jwt.Token) (interface{}, error) { + // Don't forget to validate the alg is what you expect: + if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok { + return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) + } + + // hmacSampleSecret is a []byte containing your secret, e.g. []byte("my_secret_key") + return secret, nil + }) + + if err != nil { + c.AbortWithError(403, err) + return + } + claims := token.Claims + forwarded_host := c.Request.Header.Get("x-forwarded-host") log.Printf("Checking auth of %s", forwarded_host)