package auth import ( "clapclap/internal/env" "time" "github.com/gin-gonic/gin" "github.com/golang-jwt/jwt/v5" ) type Authenticator interface { Authenticate(*gin.Context) } func Use(r gin.IRoutes, a Authenticator) gin.IRoutes { r.Use(a.Authenticate) return r } func EnvironmentAccessTokenDuration(c *gin.Context) { c.Set("token-duration", env.C.ACCESS_DURATION) c.Next() } func EnvironmentRefreshTokenDuration(c *gin.Context) { c.Set("token-duration", env.C.REFRESH_DURATION) c.Next() } func SetTokenDuration(d time.Duration) gin.HandlerFunc { return func(c *gin.Context) { c.Set("token-duration", d) c.Next() } } func EnvironmentHmacSigningKey(c *gin.Context) { secret := env.C.JWT_SECRET // TODO (pipo) : i have to find better names for these keys, sorry c.Set("signing-key", []byte(secret)) c.Set("server-jwt-secret", []byte(secret)) } func HmacSigningMethod(c *gin.Context) { c.Set("signing-method", jwt.SigningMethodHS256) c.Next() }