mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-11-21 11:38:45 +00:00
feat: Add configurable authentication enforcement to charging engine with ENFORCE_AUTH environment variable
- Add ENFORCE_AUTH environment variable with true default to auth middleware - Add early return when ENFORCE_AUTH=false for development/testing bypass - Replace development comment with UNAUTHORIZED status code when no valid authentication found - Move authentication bypass logic from end of function to environment-based check at start
This commit is contained in:
@@ -74,6 +74,16 @@ pub async fn auth_middleware(
|
|||||||
request: Request,
|
request: Request,
|
||||||
next: Next,
|
next: Next,
|
||||||
) -> Result<Response, StatusCode> {
|
) -> Result<Response, StatusCode> {
|
||||||
|
// Check if authentication is enforced via environment variable
|
||||||
|
let enforce_auth = env::var("ENFORCE_AUTH")
|
||||||
|
.unwrap_or_else(|_| "true".to_string())
|
||||||
|
.to_lowercase() == "true";
|
||||||
|
|
||||||
|
if !enforce_auth {
|
||||||
|
// Allow requests without auth for development/testing
|
||||||
|
return Ok(next.run(request).await);
|
||||||
|
}
|
||||||
|
|
||||||
let auth_header = request
|
let auth_header = request
|
||||||
.headers()
|
.headers()
|
||||||
.get("Authorization")
|
.get("Authorization")
|
||||||
@@ -101,7 +111,6 @@ pub async fn auth_middleware(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow requests without auth for development/testing
|
// No valid authentication found
|
||||||
// In production, you would want to enable strict authentication
|
Err(StatusCode::UNAUTHORIZED)
|
||||||
Ok(next.run(request).await)
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user