fixed region fetching in user_attributes
This commit is contained in:
+4
-3
@@ -1,7 +1,6 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"authorization/helper"
|
||||
"authorization/models"
|
||||
"authorization/redisclient"
|
||||
"context"
|
||||
@@ -16,6 +15,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
sabat "github.com/cespares/response"
|
||||
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
@@ -208,7 +209,7 @@ func JWTAuth(next http.HandlerFunc) http.HandlerFunc {
|
||||
// Extract token from header
|
||||
tokenString, ok := extractBearerToken(r.Header.Get("Authorization"))
|
||||
if !ok {
|
||||
helper.RespondWithError(w, http.StatusUnauthorized, "Unauthorized")
|
||||
sabat.RespondWithError(w, http.StatusUnauthorized, "Unauthorized")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -223,7 +224,7 @@ func JWTAuth(next http.HandlerFunc) http.HandlerFunc {
|
||||
// Parse and validate token
|
||||
claims, err := parseAndValidateToken(tokenString)
|
||||
if err != nil {
|
||||
helper.RespondWithError(w, http.StatusUnauthorized, errExpiredToken)
|
||||
sabat.RespondWithError(w, http.StatusUnauthorized, errExpiredToken)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"authorization/helper"
|
||||
"authorization/models"
|
||||
"authorization/redisclient"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
sabat "github.com/cespares/response"
|
||||
)
|
||||
|
||||
// DefaultRateLimitConfig returns default rate limiting settings
|
||||
@@ -24,7 +25,7 @@ func RateLimiterMiddleware(config models.RateLimitConfig) func(http.HandlerFunc)
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
// Fail-open: Skip rate limiting if Redis is not available (prevents full outage)
|
||||
if redisclient.RDB == nil {
|
||||
helper.LogError(nil, "Rate limiter: Redis not available, allowing request (fail-open)")
|
||||
sabat.LogError(nil, "Rate limiter: Redis not available, allowing request (fail-open)")
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
@@ -41,13 +42,13 @@ func RateLimiterMiddleware(config models.RateLimitConfig) func(http.HandlerFunc)
|
||||
allowed, err := checkRateLimit(identifier, config)
|
||||
if err != nil {
|
||||
// On error, fail open (allow request) but log the error
|
||||
helper.LogError(err, "rate limiter error")
|
||||
sabat.LogError(err, "rate limiter error")
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
if !allowed {
|
||||
helper.RespondWithError(w, http.StatusTooManyRequests, "Rate limit exceeded")
|
||||
sabat.RespondWithError(w, http.StatusTooManyRequests, "Rate limit exceeded")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user