authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-04 03:55:15 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-04 03:55:15 -08:00
loga017ade68e7be106b1c8b9cc3b72f5fb2f92dfe8
treec363fac5a4237f8f4d3ace8dc754d08bf128fbea
parent3a4d58d06bdfbe4e6adb1219c580d07adb8a3488
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

switch to using nektro/zig-net-http


2 files changed, 6 insertions(+), 4 deletions(-)

oauth2.zig+5-4
......@@ -7,6 +7,7 @@ const pek = @import("pek");
77const zfetch = @import("zfetch");
88const extras = @import("extras");
99const url = @import("url");
10const http = @import("http");
1011const Base = @This();
1112
1213pub const Provider = struct {
......@@ -254,7 +255,7 @@ pub fn Handlers(comptime T: type) type {
254255 const Self = @This();
255256 pub var clients: []Client = &.{};
256257
257 pub fn login(request: *std.http.Server.Request, body_writer: anytype, alloc: std.mem.Allocator, query: url.SearchParams, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *std.http.Status, response_headers: *std.ArrayListUnmanaged(std.http.Header)) !void {
258 pub fn login(request: *http.ServerRequest, body_writer: anytype, alloc: std.mem.Allocator, query: url.SearchParams, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *http.Status, response_headers: *std.ArrayListUnmanaged(std.http.Header)) !void {
258259 if (query.get("with")) |with| {
259260 const client = clientByProviderId(Self.clients, with) orelse return try fail(response_status, body_writer, "Client with that ID not found!\n", .{});
260261 return try loginOne(request, alloc, T, client, T.callbackPath, request_headers, response_status, response_headers);
......@@ -271,7 +272,7 @@ pub fn Handlers(comptime T: type) type {
271272 });
272273 }
273274
274 pub fn callback(request: *std.http.Server.Request, body_writer: anytype, alloc: std.mem.Allocator, query: url.SearchParams, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *std.http.Status, response_headers: *std.ArrayListUnmanaged(std.http.Header)) !void {
275 pub fn callback(request: *http.ServerRequest, body_writer: anytype, alloc: std.mem.Allocator, query: url.SearchParams, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *http.Status, response_headers: *std.ArrayListUnmanaged(std.http.Header)) !void {
275276 _ = request;
276277 const state = query.get("state") orelse return try fail(response_status, body_writer, "", .{});
277278 const client = clientByProviderId(Self.clients, state) orelse return try fail(response_status, body_writer, "error: No handler found for provider: {s}\n", .{state});
......@@ -326,7 +327,7 @@ pub fn Handlers(comptime T: type) type {
326327 };
327328}
328329
329fn loginOne(request: *std.http.Server.Request, alloc: std.mem.Allocator, comptime T: type, client: Client, callbackPath: string, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *std.http.Status, response_headers: *std.ArrayListUnmanaged(std.http.Header)) !void {
330fn loginOne(request: *http.ServerRequest, alloc: std.mem.Allocator, comptime T: type, client: Client, callbackPath: string, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *http.Status, response_headers: *std.ArrayListUnmanaged(std.http.Header)) !void {
330331 if (try T.isLoggedIn(request, alloc)) {
331332 try response_headers.append(alloc, .{ .name = "Location", .value = T.doneUrl });
332333 } else {
......@@ -344,7 +345,7 @@ fn loginOne(request: *std.http.Server.Request, alloc: std.mem.Allocator, comptim
344345 response_status.* = .found;
345346}
346347
347fn fail(response_status: *std.http.Status, body_writer: anytype, comptime err: string, args: anytype) !void {
348fn fail(response_status: *http.Status, body_writer: anytype, comptime err: string, args: anytype) !void {
348349 response_status.* = .bad_request;
349350 try body_writer.print(err, args);
350351}
zig.mod+1
......@@ -10,3 +10,4 @@ dependencies:
1010 - src: git https://github.com/nektro/zfetch
1111 - src: git https://github.com/nektro/zig-extras
1212 - src: git https://github.com/nektro/zig-whatwg-url
13 - src: git https://github.com/nektro/zig-net-http