This commit is contained in:
ACoolName 2024-05-25 22:16:13 +03:00
parent f9932f0362
commit ea8ed9202a

View File

@ -194,13 +194,28 @@ func (con Connection) signIn(c *gin.Context) {
} }
func (con Connection) verify(c *gin.Context) { func (con Connection) verify(c *gin.Context) {
claims, exists := c.Get("claims") authCookie, err := c.Request.Cookie("auth")
if !exists { if err != nil {
log.Println("No Claims") c.Redirect(303, fmt.Sprintf("http://%s/", DOMAIN))
c.AbortWithStatus(403)
return 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") forwarded_host := c.Request.Header.Get("x-forwarded-host")
log.Printf("Checking auth of %s", forwarded_host) log.Printf("Checking auth of %s", forwarded_host)