feat: Initial MVP with home server identity model
- User model with Ed25519 keypair identity - Register/login on home server (creates keypair) - Join guest servers with signature verification - Public endpoints for cross-server identity - Channel and message CRUD - JWT authentication middleware Architecture: Home server model, no federation, client-driven sync
This commit is contained in:
commit
6a8977c4c3
14 files changed
+1494
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import 'package:relic/relic.dart';
|
||||
|
||||
import '../../config/config.dart';
|
||||
import '../utils/extensions.dart';
|
||||
import 'crypto_service.dart';
|
||||
|
||||
final userIdProperty = ContextProperty<String>('userId');
|
||||
final usernameProperty = ContextProperty<String>('username');
|
||||
final userLocalIdProperty = ContextProperty<int>('userLocalId');
|
||||
|
||||
/// JWT authentication middleware
|
||||
final jwtMiddleware = createMiddleware(
|
||||
onRequest: (request) {
|
||||
final authHeader = request.headers.authorization;
|
||||
|
||||
if (authHeader is! BearerAuthorizationHeader) {
|
||||
return Response.unauthorized(
|
||||
body: Body.fromString('Bearer token required'),
|
||||
);
|
||||
}
|
||||
|
||||
final payload = AuthService.verifyToken(authHeader.token);
|
||||
if (payload == null) {
|
||||
return Response.forbidden(
|
||||
body: Body.fromString('Invalid or expired token'),
|
||||
);
|
||||
}
|
||||
|
||||
final userId = payload['sub'] as String?;
|
||||
final username = payload['username'] as String?;
|
||||
|
||||
if (userId == null) {
|
||||
return Response.forbidden(
|
||||
body: Body.fromString('Invalid token payload'),
|
||||
);
|
||||
}
|
||||
|
||||
userIdProperty[request] = userId;
|
||||
if (username != null) {
|
||||
usernameProperty[request] = username;
|
||||
}
|
||||
|
||||
return null; // Continue to handler
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user