Implement chat server auth, models, handlers, and docs context
This commit is contained in:
1 parent
23602efd5f
commit
f6b27565cd
16 files changed
+1285
-152
No files matched your search
@@ -1,18 +1,28 @@
|
||||
import 'package:chat_server/models.dart';
|
||||
import 'package:chat_server/objectbox.g.dart';
|
||||
import 'package:relic/relic.dart';
|
||||
|
||||
import '../../config/config.dart';
|
||||
import '../state/app_state.dart';
|
||||
import '../utils/extensions.dart';
|
||||
|
||||
/// Public endpoint for cross-server identity verification
|
||||
/// Called by other servers to verify a user's public key
|
||||
///
|
||||
///
|
||||
/// GET /.well-known/users/{username}
|
||||
/// Returns: { userId, publicKey, username, displayName, avatarUrl }
|
||||
Future<Response> publicUserHandler(Request req, String username) async {
|
||||
final query = userBox.query(
|
||||
User_.username.equals(username) & User_.isLocal.equals(true),
|
||||
).build();
|
||||
Future<Response> publicUserHandler(Request req) async {
|
||||
final username = req.rawPathParameters[#username];
|
||||
if (username == null) {
|
||||
return Response.badRequest(
|
||||
body: Body.fromString('Username required'),
|
||||
);
|
||||
}
|
||||
|
||||
final query = userBox
|
||||
.query(
|
||||
ChatUser_.username.equals(username) & ChatUser_.isLocal.equals(true),
|
||||
)
|
||||
.build();
|
||||
|
||||
final user = query.findFirst();
|
||||
query.close();
|
||||
@@ -39,13 +49,22 @@ Future<Response> publicUserHandler(Request req, String username) async {
|
||||
|
||||
/// Public endpoint to verify a user exists
|
||||
/// Lightweight check without full profile
|
||||
///
|
||||
///
|
||||
/// GET /.well-known/verify/{userId}
|
||||
/// Returns: { exists, userId, publicKey }
|
||||
Future<Response> publicVerifyHandler(Request req, String userId) async {
|
||||
final query = userBox.query(
|
||||
User_.userId.equals(userId) & User_.isLocal.equals(true),
|
||||
).build();
|
||||
Future<Response> publicVerifyHandler(Request req) async {
|
||||
final userId = req.rawPathParameters[#userId];
|
||||
if (userId == null) {
|
||||
return Response.badRequest(
|
||||
body: Body.fromString('userId required'),
|
||||
);
|
||||
}
|
||||
|
||||
final query = userBox
|
||||
.query(
|
||||
ChatUser_.userId.equals(userId) & ChatUser_.isLocal.equals(true),
|
||||
)
|
||||
.build();
|
||||
|
||||
final user = query.findFirst();
|
||||
query.close();
|
||||
@@ -70,7 +89,7 @@ Future<Response> publicVerifyHandler(Request req, String userId) async {
|
||||
}
|
||||
|
||||
/// Public server info
|
||||
///
|
||||
///
|
||||
/// GET /.well-known/server
|
||||
/// Returns: { serverHost, serverName, version }
|
||||
Future<Response> publicServerInfoHandler(Request req) async {
|
||||
|
||||
Reference in new issue
Block a user