authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-03 02:03:42 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-03 02:03:42 -08:00
log3a4d58d06bdfbe4e6adb1219c580d07adb8a3488
tree9d0861ec3e5dc35db14bcf081c7e9d7baef0876e
parent49f33e433fd16fd4371a251590e39def192fff1e
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

replace UrlValues with url.SearchParams


3 files changed, 9 insertions(+), 7 deletions(-)

licenses.txt+3-1
...@@ -3,16 +3,18 @@ MIT:...@@ -3,16 +3,18 @@ MIT:
3- This3- This
4- git https://github.com/nektro/iguanaTLS4- git https://github.com/nektro/iguanaTLS
5- git https://github.com/nektro/zfetch5- git https://github.com/nektro/zfetch
6- git https://github.com/nektro/zig-UrlValues
7- git https://github.com/nektro/zig-extras6- git https://github.com/nektro/zig-extras
8- git https://github.com/nektro/zig-sys-linux7- git https://github.com/nektro/zig-sys-linux
9- git https://github.com/nektro/zig-tracer8- git https://github.com/nektro/zig-tracer
9- git https://github.com/nektro/zig-unicode-ucd
10- git https://github.com/truemedian/hzzp10- git https://github.com/truemedian/hzzp
11- git https://github.com/kivikakk/htmlentities.zig11- git https://github.com/kivikakk/htmlentities.zig
1212
13MPL-2.0:13MPL-2.0:
14= https://spdx.org/licenses/MPL-2.014= https://spdx.org/licenses/MPL-2.0
15- git https://github.com/nektro/zig-pek15- git https://github.com/nektro/zig-pek
16- git https://github.com/nektro/zig-unicode-idna
17- git https://github.com/nektro/zig-whatwg-url
1618
17Unspecified:19Unspecified:
18- system_lib c20- system_lib c
oauth2.zig+5-5
...@@ -6,7 +6,7 @@ const files = @import("./files.zig");...@@ -6,7 +6,7 @@ const files = @import("./files.zig");
6const pek = @import("pek");6const pek = @import("pek");
7const zfetch = @import("zfetch");7const zfetch = @import("zfetch");
8const extras = @import("extras");8const extras = @import("extras");
9const UrlValues = @import("UrlValues");9const url = @import("url");
10const Base = @This();10const Base = @This();
1111
12pub const Provider = struct {12pub const Provider = struct {
...@@ -254,7 +254,7 @@ pub fn Handlers(comptime T: type) type {...@@ -254,7 +254,7 @@ pub fn Handlers(comptime T: type) type {
254 const Self = @This();254 const Self = @This();
255 pub var clients: []Client = &.{};255 pub var clients: []Client = &.{};
256256
257 pub fn login(request: *std.http.Server.Request, body_writer: anytype, alloc: std.mem.Allocator, query: UrlValues, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *std.http.Status, response_headers: *std.ArrayListUnmanaged(std.http.Header)) !void {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 if (query.get("with")) |with| {258 if (query.get("with")) |with| {
259 const client = clientByProviderId(Self.clients, with) orelse return try fail(response_status, body_writer, "Client with that ID not found!\n", .{});259 const client = clientByProviderId(Self.clients, with) orelse return try fail(response_status, body_writer, "Client with that ID not found!\n", .{});
260 return try loginOne(request, alloc, T, client, T.callbackPath, request_headers, response_status, response_headers);260 return try loginOne(request, alloc, T, client, T.callbackPath, request_headers, response_status, response_headers);
...@@ -271,13 +271,13 @@ pub fn Handlers(comptime T: type) type {...@@ -271,13 +271,13 @@ pub fn Handlers(comptime T: type) type {
271 });271 });
272 }272 }
273273
274 pub fn callback(request: *std.http.Server.Request, body_writer: anytype, alloc: std.mem.Allocator, query: UrlValues, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *std.http.Status, response_headers: *std.ArrayListUnmanaged(std.http.Header)) !void {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 _ = request;275 _ = request;
276 const state = query.get("state") orelse return try fail(response_status, body_writer, "", .{});276 const state = query.get("state") orelse return try fail(response_status, body_writer, "", .{});
277 const client = clientByProviderId(Self.clients, state) orelse return try fail(response_status, body_writer, "error: No handler found for provider: {s}\n", .{state});277 const client = clientByProviderId(Self.clients, state) orelse return try fail(response_status, body_writer, "error: No handler found for provider: {s}\n", .{state});
278 const code = query.get("code") orelse return try fail(response_status, body_writer, "", .{});278 const code = query.get("code") orelse return try fail(response_status, body_writer, "", .{});
279279
280 var params = UrlValues.init(alloc);280 var params = url.SearchParams.init(alloc);
281 try params.append("client_id", client.id);281 try params.append("client_id", client.id);
282 try params.append("client_secret", client.secret);282 try params.append("client_secret", client.secret);
283 try params.append("grant_type", "authorization_code");283 try params.append("grant_type", "authorization_code");
...@@ -331,7 +331,7 @@ fn loginOne(request: *std.http.Server.Request, alloc: std.mem.Allocator, comptim...@@ -331,7 +331,7 @@ fn loginOne(request: *std.http.Server.Request, alloc: std.mem.Allocator, comptim
331 try response_headers.append(alloc, .{ .name = "Location", .value = T.doneUrl });331 try response_headers.append(alloc, .{ .name = "Location", .value = T.doneUrl });
332 } else {332 } else {
333 const idp = client.provider;333 const idp = client.provider;
334 var params = UrlValues.init(alloc);334 var params = url.SearchParams.init(alloc);
335 try params.append("client_id", client.id);335 try params.append("client_id", client.id);
336 try params.append("redirect_uri", try redirectUri(request_headers, alloc, callbackPath));336 try params.append("redirect_uri", try redirectUri(request_headers, alloc, callbackPath));
337 try params.append("response_type", "code");337 try params.append("response_type", "code");
zig.mod+1-1
...@@ -9,4 +9,4 @@ dependencies:...@@ -9,4 +9,4 @@ dependencies:
9 - src: git https://github.com/nektro/zig-pek9 - src: git https://github.com/nektro/zig-pek
10 - src: git https://github.com/nektro/zfetch10 - src: git https://github.com/nektro/zfetch
11 - src: git https://github.com/nektro/zig-extras11 - src: git https://github.com/nektro/zig-extras
12 - src: git https://github.com/nektro/zig-UrlValues12 - src: git https://github.com/nektro/zig-whatwg-url