authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-31 23:44:23 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-01 02:23:06 -07:00
log27873c7ccc0aed3bd3694fe2250d2cf2fd8101e5
tree14fa7f3e3ccc6b19363be282f5ab405b872ec7f0
parentbd3a5452ae3f88dcefd030bef36915079062308e
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

update to zig 0.15.2


2 files changed, 15 insertions(+), 19 deletions(-)

README.md+1-1
...@@ -3,7 +3,7 @@...@@ -3,7 +3,7 @@
3![loc](https://sloc.xyz/github/nektro/zig-oauth2)3![loc](https://sloc.xyz/github/nektro/zig-oauth2)
4[![license](https://img.shields.io/github/license/nektro/zig-oauth2.svg)](https://github.com/nektro/zig-oauth2/blob/master/LICENSE)4[![license](https://img.shields.io/github/license/nektro/zig-oauth2.svg)](https://github.com/nektro/zig-oauth2/blob/master/LICENSE)
5[![nektro @ github sponsors](https://img.shields.io/badge/sponsors-nektro-purple?logo=github)](https://github.com/sponsors/nektro)5[![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.14-f7a41d)](https://ziglang.org/)6[![Zig](https://img.shields.io/badge/Zig-0.15-f7a41d)](https://ziglang.org/)
7[![Zigmod](https://img.shields.io/badge/Zigmod-latest-f7a41d)](https://github.com/nektro/zigmod)7[![Zigmod](https://img.shields.io/badge/Zigmod-latest-f7a41d)](https://github.com/nektro/zigmod)
88
9HTTP handler functions to allow you to easily add OAuth2 login support to your Zig application.9HTTP handler functions to allow you to easily add OAuth2 login support to your Zig application.
oauth2.zig+14-18
...@@ -313,9 +313,9 @@ pub fn Handlers(comptime T: type) type {...@@ -313,9 +313,9 @@ pub fn Handlers(comptime T: type) type {
313 try params.append("state", "none");313 try params.append("state", "none");
314 const req_body = try params.encode();314 const req_body = try params.encode();
315315
316 var req = try http_client.open(.POST, try std.Uri.parse(client.provider.token_url), .{316 var req = try http_client.request(.POST, try std.Uri.parse(client.provider.token_url), .{
317 .server_header_buffer = &buf,
318 .headers = .{317 .headers = .{
318 .accept_encoding = .{ .override = "identity" },
319 .authorization = .{ .override = try nio.fmt.allocPrint(alloc, "Basic {s}", .{try extras.base64EncodeAlloc(alloc, try std.mem.join(alloc, ":", &.{ client.id, client.secret }))}) },319 .authorization = .{ .override = try nio.fmt.allocPrint(alloc, "Basic {s}", .{try extras.base64EncodeAlloc(alloc, try std.mem.join(alloc, ":", &.{ client.id, client.secret }))}) },
320 .content_type = .{ .override = "application/x-www-form-urlencoded" },320 .content_type = .{ .override = "application/x-www-form-urlencoded" },
321 },321 },
...@@ -325,14 +325,11 @@ pub fn Handlers(comptime T: type) type {...@@ -325,14 +325,11 @@ pub fn Handlers(comptime T: type) type {
325 .redirect_behavior = .not_allowed,325 .redirect_behavior = .not_allowed,
326 });326 });
327 defer req.deinit();327 defer req.deinit();
328 req.transfer_encoding = .{ .content_length = req_body.len };328 try req.sendBodyComplete(req_body);
329 try req.send();329 var resp = try req.receiveHead(&.{});
330 try req.writer().writeAll(req_body);330 const body_content = try resp.reader(&buf).allocRemaining(alloc, .limited(1024 * 1024 * 5));
331 try req.finish();331 if (resp.head.status != .ok) std.log.scoped(.oauth).debug("{s}: {s}", .{ @tagName(resp.head.status), body_content });
332 try req.wait();332 if (resp.head.status != .ok) return error.OauthBadToken;
333 const body_content = try req.reader().readAllAlloc(alloc, 1024 * 1024 * 5);
334 if (req.response.status != .ok) std.log.scoped(.oauth).debug("{s}: {s}", .{ @tagName(req.response.status), body_content });
335 if (req.response.status != .ok) return error.OauthBadToken;
336 const val = try json.parseFromSlice(alloc, "body.json", body_content, .{ .maximum_depth = 100, .support_trailing_commas = true });333 const val = try json.parseFromSlice(alloc, "body.json", body_content, .{ .maximum_depth = 100, .support_trailing_commas = true });
337 val.acquire();334 val.acquire();
338 const tt = val.root.object().getS("token_type").?;335 const tt = val.root.object().getS("token_type").?;
...@@ -340,9 +337,9 @@ pub fn Handlers(comptime T: type) type {...@@ -340,9 +337,9 @@ pub fn Handlers(comptime T: type) type {
340 const at = val.root.object().getS("access_token") orelse return try fail(response_status, body_writer, "Identity Provider Login Error!\n{s}", .{body_content});337 const at = val.root.object().getS("access_token") orelse return try fail(response_status, body_writer, "Identity Provider Login Error!\n{s}", .{body_content});
341 val.release();338 val.release();
342339
343 var req2 = try http_client.open(.GET, try std.Uri.parse(client.provider.me_url), .{340 var req2 = try http_client.request(.GET, try std.Uri.parse(client.provider.me_url), .{
344 .server_header_buffer = &buf,
345 .headers = .{341 .headers = .{
342 .accept_encoding = .{ .override = "identity" },
346 .authorization = .{ .override = try nio.fmt.allocPrint(alloc, "Bearer {s}", .{at}) },343 .authorization = .{ .override = try nio.fmt.allocPrint(alloc, "Bearer {s}", .{at}) },
347 },344 },
348 .extra_headers = &.{345 .extra_headers = &.{
...@@ -351,12 +348,11 @@ pub fn Handlers(comptime T: type) type {...@@ -351,12 +348,11 @@ pub fn Handlers(comptime T: type) type {
351 .redirect_behavior = .not_allowed,348 .redirect_behavior = .not_allowed,
352 });349 });
353 defer req2.deinit();350 defer req2.deinit();
354 try req2.send();351 try req2.sendBodiless();
355 try req2.finish();352 var resp2 = try req2.receiveHead(&.{});
356 try req2.wait();353 const body_content2 = try resp2.reader(&buf).allocRemaining(alloc, .limited(1024 * 1024 * 5));
357 const body_content2 = try req2.reader().readAllAlloc(alloc, 1024 * 1024 * 5);354 if (resp2.head.status != .ok) std.log.scoped(.oauth).debug("{s}: {s}", .{ @tagName(resp2.head.status), body_content2 });
358 if (req2.response.status != .ok) std.log.scoped(.oauth).debug("{s}: {s}", .{ @tagName(req2.response.status), body_content2 });355 if (resp2.head.status != .ok) return error.OauthBadUserinfo;
359 if (req2.response.status != .ok) return error.OauthBadUserinfo;
360 const val2 = try json.parseFromSlice(alloc, "body2.json", body_content2, .{ .maximum_depth = 100, .support_trailing_commas = true });356 const val2 = try json.parseFromSlice(alloc, "body2.json", body_content2, .{ .maximum_depth = 100, .support_trailing_commas = true });
361 val2.acquire();357 val2.acquire();
362 const id = try fixId(val2.root.object().getAny(client.provider.id_prop).?);358 const id = try fixId(val2.root.object().getAny(client.provider.id_prop).?);