···
130
130
}
131
131
132
132
pub fn resolveHandle(request: *http.Server.Request) !void {
133
133
+
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
134
134
+
defer arena.deinit();
135
135
+
const allocator = arena.allocator();
136
136
+
133
137
var handle_buf: [256]u8 = undefined;
134
134
-
const handle = http_api.queryParam(request.head.target, "handle", &handle_buf) orelse {
138
138
+
const handle_param = http_api.queryParam(request.head.target, "handle", &handle_buf) orelse {
135
139
return http_api.xrpcError(request, .bad_request, "InvalidRequest", "Missing handle");
136
140
};
141
141
+
const handle = std.mem.trim(u8, handle_param, &std.ascii.whitespace);
142
142
+
if (handle.len == 0) {
143
143
+
return http_api.xrpcError(request, .bad_request, "InvalidRequest", "Missing handle");
144
144
+
}
145
145
+
137
146
const did = if (store.resolveRepo(handle)) |account|
138
147
account.did
139
148
else if (std.ascii.eqlIgnoreCase(handle, "mod-authority.test"))
140
149
"did:plc:ar7c4by46qjdydhdevvrndac"
141
141
-
else
142
142
-
return http_api.xrpcError(request, .bad_request, "InvalidRequest", "Handle not found");
150
150
+
else did: {
151
151
+
const parsed_handle = zat.Handle.parse(handle) orelse {
152
152
+
return http_api.xrpcError(request, .bad_request, "InvalidHandle", "Invalid handle format");
153
153
+
};
154
154
+
var resolver = zat.HandleResolver.init(store.currentIo(), allocator);
155
155
+
defer resolver.deinit();
156
156
+
break :did resolver.resolve(parsed_handle) catch {
157
157
+
return http_api.xrpcError(request, .not_found, "HandleNotFound", "Unable to resolve handle");
158
158
+
};
159
159
+
};
143
160
144
144
-
var body_buf: [320]u8 = undefined;
145
145
-
const body = try std.fmt.bufPrint(&body_buf, "{{\"did\":{f}}}", .{std.json.fmt(did, .{})});
161
161
+
const body = try std.fmt.allocPrint(allocator, "{{\"did\":{f}}}", .{std.json.fmt(did, .{})});
146
162
return http_api.json(request, .ok, body);
147
163
}
148
164
···
46
46
sqlite3 "$db" "insert into accounts (did, handle, email, password_hash, activated_at, email_confirmed_at) values ('did:plc:smoketest', 'smoke.test', 'smoke@test.com', 'password', unixepoch(), unixepoch())"
47
47
sqlite3 "$db" "insert into oauth_requests (request_id, client_id, redirect_uri, scope, state, code_challenge, code_challenge_method, login_hint, expires_at) values ('smoke-oauth', 'https://client.example/oauth-client.json', 'https://client.example/callback', 'repo:*?action=create blob:*/*', 'state', 'challenge', 'S256', 'smoke.test', unixepoch() + 600)"
48
48
49
49
+
resolved=$(curl -fsS "$base/xrpc/com.atproto.identity.resolveHandle?handle=smoke.test")
50
50
+
printf '%s' "$resolved" | grep -q '"did":"did:plc:smoketest"'
51
51
+
49
52
session=$(curl -fsS -X POST "$base/xrpc/com.atproto.server.createSession" \
50
53
-H 'content-type: application/json' \
51
54
--data '{"identifier":"smoke.test","password":"password"}')