authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-07 20:48:29 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-07 20:48:29 -07:00
logb9eee6396695f32b59a9eada10524e488c0d60c1
tree4f5d3be9689d1c3071d5d413e6a6c39e8998a28c
parent9153a5a3b11eec15482d9b610a607a55f7e67a35
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

update to zig 0.16.0


5 files changed, 37 insertions(+), 10 deletions(-)

README.md+1-1
......@@ -3,7 +3,7 @@
33![loc](https://sloc.xyz/github/nektro/zig-oauth2)
44[![license](https://img.shields.io/github/license/nektro/zig-oauth2.svg)](https://github.com/nektro/zig-oauth2/blob/master/LICENSE)
55[![nektro @ github sponsors](https://img.shields.io/badge/sponsors-nektro-purple?logo=github)](https://github.com/sponsors/nektro)
6[![Zig](https://img.shields.io/badge/Zig-0.15-f7a41d)](https://ziglang.org/)
6[![Zig](https://img.shields.io/badge/Zig-0.16-f7a41d)](https://ziglang.org/)
77[![Zigmod](https://img.shields.io/badge/Zigmod-latest-f7a41d)](https://github.com/nektro/zigmod)
88
99HTTP handler functions to allow you to easily add OAuth2 login support to your Zig application.
build.zig+1-1
......@@ -14,7 +14,7 @@ pub fn build(b: *std.Build) void {
1414 }),
1515 });
1616 deps.addAllTo(tests);
17 tests.linkLibC();
17 tests.root_module.link_libc = true;
1818 tests.use_llvm = !disable_llvm;
1919 tests.use_lld = !disable_llvm;
2020 b.getInstallStep().dependOn(&tests.step);
oauth2.zig+4-6
......@@ -9,6 +9,8 @@ const url = @import("url");
99const http = @import("http");
1010const nio = @import("nio");
1111const json = @import("json");
12const builtin = @import("builtin");
13const root = @import("root");
1214const Base = @This();
1315
1416pub const Provider = struct {
......@@ -266,11 +268,6 @@ pub fn clientByProviderId(clients: []const Client, name: string) ?Client {
266268}
267269
268270pub fn Handlers(comptime T: type) type {
269 comptime std.debug.assert(@hasDecl(T, "isLoggedIn"));
270 comptime std.debug.assert(@hasDecl(T, "doneUrl"));
271 comptime std.debug.assert(@hasDecl(T, "saveInfo"));
272 comptime std.debug.assert(@hasDecl(T, "callbackPath"));
273
274271 return struct {
275272 const Self = @This();
276273 pub var clients: []Client = &.{};
......@@ -298,8 +295,9 @@ pub fn Handlers(comptime T: type) type {
298295 const client = clientByProviderId(Self.clients, state) orelse return try fail(response_status, body_writer, "error: No handler found for provider: {s}\n", .{state});
299296 const code = query.get("code") orelse return try fail(response_status, body_writer, "", .{});
300297
298 const io = if (!builtin.is_test) root.io else std.Options.debug_io;
301299 var buf: [4096]u8 = @splat(0);
302 var http_client: std.http.Client = .{ .allocator = alloc };
300 var http_client: std.http.Client = .{ .allocator = alloc, .io = io };
303301 defer http_client.deinit();
304302
305303 var params = url.SearchParams.init(alloc);
test.zig+27-2
......@@ -1,7 +1,32 @@
11const std = @import("std");
22const oauth2 = @import("oauth2");
3const nio = @import("nio");
4const http = @import("http");
5const json = @import("json");
36
4// TODO: how do we make this better?
57test {
6 std.testing.refAllDeclsRecursive(oauth2);
8 _ = &oauth2.Provider;
9 _ = &oauth2.Client;
10 std.testing.refAllDecls(oauth2.providers);
11 std.testing.refAllDecls(oauth2.dynamic_providers);
12 _ = &oauth2.providerById;
13 _ = &oauth2.clientByProviderId;
14 _ = &oauth2.pek_domain;
15}
16test {
17 const S = struct {
18 pub const callbackPath = "/-/callback";
19 pub const doneUrl = "/";
20
21 pub fn isLoggedIn(_: *http.ServerRequest, _: std.mem.Allocator) !bool {
22 return false;
23 }
24 pub fn saveInfo(_: *http.HeadersMap, _: std.mem.Allocator, _: oauth2.Provider, _: []const u8, _: []const u8, _: json.Document, _: json.Document) !void {
25 //
26 }
27 };
28 const H = oauth2.Handlers(S);
29 std.testing.refAllDecls(oauth2.Handlers(S));
30 _ = @TypeOf(H.login(undefined, nio.NullWriter{}, undefined, undefined, undefined, undefined, undefined));
31 _ = @TypeOf(H.callback(undefined, nio.NullWriter{}, undefined, undefined, undefined, undefined, undefined));
732}
zig.mod+4
......@@ -12,3 +12,7 @@ dependencies:
1212 - src: git https://github.com/nektro/zig-net-http
1313 - src: git https://github.com/nektro/zig-nio
1414 - src: git https://github.com/nektro/zig-json
15root_dependencies:
16 - src: git https://github.com/nektro/zig-nio
17 - src: git https://github.com/nektro/zig-net-http
18 - src: git https://github.com/nektro/zig-json