wire up atproto module to log requester DIDs

Changed files
+21 -2
src
+1 -2
src/atproto.zig
··· 118 118 // 3. verify JWT signature using the public key 119 119 // 120 120 // for now, we at least verify claims which catches expired/wrong-audience tokens 121 - _ = payload; 122 121 123 122 return payload; 124 123 } ··· 229 228 230 229 const decoder = base64.standard.Decoder; 231 230 const decoded_len = decoder.calcSizeForSlice(buf[0..i]) catch return JwtError.InvalidBase64; 232 - var result = try allocator.alloc(u8, decoded_len); 231 + const result = try allocator.alloc(u8, decoded_len); 233 232 decoder.decode(result, buf[0..i]) catch return JwtError.InvalidBase64; 234 233 235 234 return result;
+20
src/http.zig
··· 5 5 const feed = @import("feed.zig"); 6 6 const config = @import("config.zig"); 7 7 const dashboard = @import("dashboard.zig"); 8 + const atproto = @import("atproto.zig"); 8 9 9 10 const HTTP_BUF_SIZE = 8192; 10 11 ··· 111 112 defer arena.deinit(); 112 113 const alloc = arena.allocator(); 113 114 115 + // extract requester DID from authorization header 116 + const auth_header = getHeader(request, "authorization"); 117 + const service_did = config.getServiceDid(); 118 + const requester_did = atproto.getRequesterDid(alloc, auth_header, service_did); 119 + 120 + if (requester_did) |did| { 121 + std.debug.print("feed request from: {s}\n", .{did}); 122 + } 123 + 114 124 // parse query params 115 125 const feed_param = parseQueryParam(alloc, target, "feed") catch { 116 126 try sendJson(request, .bad_request, ··· 140 150 }; 141 151 142 152 try sendJson(request, .ok, result); 153 + } 154 + 155 + fn getHeader(request: *http.Server.Request, name: []const u8) ?[]const u8 { 156 + var it = request.iterateHeaders(); 157 + while (it.next()) |header| { 158 + if (std.ascii.eqlIgnoreCase(header.name, name)) { 159 + return header.value; 160 + } 161 + } 162 + return null; 143 163 } 144 164 145 165 fn parseQueryParam(alloc: std.mem.Allocator, target: []const u8, param: []const u8) ![]const u8 {