Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

🔖 Checkpoint: Edit /workspaces/claude-code-flow/user-service/src/middleware/auth.middleware.ts

rUv6e3d598124ef
diff --git a/benchmark/.claude/checkpoints/task-1754488887.json b/benchmark/.claude/checkpoints/task-1754488887.json
new file mode 100644
index 0000000000..b839e8d219
--- /dev/null
+++ b/benchmark/.claude/checkpoints/task-1754488887.json
@@ -0,0 +1 @@
+{"checkpoint": "task-20250806-140125", "task": "review the benchmark wiki documentation make sure everything is actually real and working. ", "timestamp": "2025-08-06T14:01:27Z", "commit": "1fc7c564ab5989cc0491803ab81bd1d4031d6968", "github_release": "true"}
diff --git a/user-service/src/middleware/auth.middleware.ts b/user-service/src/middleware/auth.middleware.ts
new file mode 100644
index 0000000000..52fa3dbee7
--- /dev/null
+++ b/user-service/src/middleware/auth.middleware.ts
@@ -0,0 +1,71 @@
+import { Request, Response, NextFunction } from 'express';
+import { userService } from '../services/user.service';
+import { TokenPayload, UserRole } from '../types/user.types';
+import { AuthenticationError, AuthorizationError } from '../utils/errors';
+
+// Extend Express Request type
+declare global {
+ namespace Express {
+ interface Request {
+ user?: TokenPayload;
+ }
+ }
+}
+
+export async function authenticate(
+ req: Request,
+ res: Response,
+ next: NextFunction
+): Promise<void> {
+ try {
+ const authHeader = req.headers.authorization;
+
+ if (!authHeader || !authHeader.startsWith('Bearer ')) {
+ throw new AuthenticationError('No token provided');
+ }
+
+ const token = authHeader.substring(7);
+ const payload = await userService.verifyToken(token);
+
+ req.user = payload;
+ next();
+ } catch (error) {
+ next(error);
+ }
+}
+
+export function authorize(...roles: UserRole[]) {
+ return (req: Request, res: Response, next: NextFunction): void => {
+ if (!req.user) {
+ return next(new AuthenticationError('Not authenticated'));
+ }
+
+ if (roles.length > 0 && !roles.includes(req.user.role)) {
+ return next(new AuthorizationError('Insufficient permissions'));
+ }
+
+ next();
+ };
+}
+
+export function authorizeOwner(userIdParam: string = 'id') {
+ return (req: Request, res: Response, next: NextFunction): void => {
+ if (!req.user) {
+ return next(new AuthenticationError('Not authenticated'));
+ }
+
+ const requestedUserId = req.params[userIdParam];
+
+ // Admins can access any user
+ if (req.user.role === UserRole.ADMIN) {
+ return next();
+ }
+
+ // Users can only access their own data
+ if (req.user.userId !== requestedUserId) {
+ return next(new AuthorizationError('Cannot access other user data'));
+ }
+
+ next();
+ };
+}
\ No newline at end of file