authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-26 20:30:55 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-26 20:30:55 -07:00
logdaedcedeb7b2bf9720b851a23044f10ea1dbfeba
tree25ef798f5ee42d33c9e9858c6a88758666652d6d
parent9ccbbac07fbd2b1a809bfb0efee976fb32cd6827
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

use nio.fmt


2 files changed, 13 insertions(+), 11 deletions(-)

oauth2.zig+12-11
......@@ -7,6 +7,7 @@ const pek = @import("pek");
77const extras = @import("extras");
88const url = @import("url");
99const http = @import("http");
10const nio = @import("nio");
1011const Base = @This();
1112
1213pub const Provider = struct {
......@@ -223,9 +224,9 @@ pub fn providerById(alloc: std.mem.Allocator, name: string) !?Provider {
223224 if (std.mem.eql(u8, didp.id, p_id)) {
224225 return Provider{
225226 .id = name,
226 .authorize_url = try std.fmt.allocPrint(alloc, didp.authorize_url, args),
227 .token_url = try std.fmt.allocPrint(alloc, didp.token_url, args),
228 .me_url = try std.fmt.allocPrint(alloc, didp.me_url, args),
227 .authorize_url = try nio.fmt.allocPrint(alloc, didp.authorize_url, args),
228 .token_url = try nio.fmt.allocPrint(alloc, didp.token_url, args),
229 .me_url = try nio.fmt.allocPrint(alloc, didp.me_url, args),
229230 .scope = didp.scope,
230231 .name_prop = didp.name_prop,
231232 .name_prefix = didp.name_prefix,
......@@ -239,9 +240,9 @@ pub fn providerById(alloc: std.mem.Allocator, name: string) !?Provider {
239240 if (std.mem.eql(u8, didp.id, p_id)) {
240241 return Provider{
241242 .id = name,
242 .authorize_url = try std.fmt.allocPrint(alloc, didp.authorize_url, args),
243 .token_url = try std.fmt.allocPrint(alloc, didp.token_url, args),
244 .me_url = try std.fmt.allocPrint(alloc, didp.me_url, args),
243 .authorize_url = try nio.fmt.allocPrint(alloc, didp.authorize_url, args),
244 .token_url = try nio.fmt.allocPrint(alloc, didp.token_url, args),
245 .me_url = try nio.fmt.allocPrint(alloc, didp.me_url, args),
245246 .scope = didp.scope,
246247 .name_prop = didp.name_prop,
247248 .name_prefix = didp.name_prefix,
......@@ -314,7 +315,7 @@ pub fn Handlers(comptime T: type) type {
314315 var req = try http_client.open(.POST, try std.Uri.parse(client.provider.token_url), .{
315316 .server_header_buffer = &buf,
316317 .headers = .{
317 .authorization = .{ .override = try std.fmt.allocPrint(alloc, "Basic {s}", .{try extras.base64EncodeAlloc(alloc, try std.mem.join(alloc, ":", &.{ client.id, client.secret }))}) },
318 .authorization = .{ .override = try nio.fmt.allocPrint(alloc, "Basic {s}", .{try extras.base64EncodeAlloc(alloc, try std.mem.join(alloc, ":", &.{ client.id, client.secret }))}) },
318319 .content_type = .{ .override = "application/x-www-form-urlencoded" },
319320 },
320321 .extra_headers = &.{
......@@ -341,7 +342,7 @@ pub fn Handlers(comptime T: type) type {
341342 var req2 = try http_client.open(.GET, try std.Uri.parse(client.provider.me_url), .{
342343 .server_header_buffer = &buf,
343344 .headers = .{
344 .authorization = .{ .override = try std.fmt.allocPrint(alloc, "Bearer {s}", .{at.string}) },
345 .authorization = .{ .override = try nio.fmt.allocPrint(alloc, "Bearer {s}", .{at.string}) },
345346 },
346347 .extra_headers = &.{
347348 .{ .name = "Accept", .value = "application/json" },
......@@ -395,14 +396,14 @@ fn redirectUri(request_headers: *const http.HeadersMap, alloc: std.mem.Allocator
395396 const maybe_tls = std.mem.eql(u8, xproto, "https");
396397 const proto: string = if (maybe_tls) "https" else "http";
397398 const host = request_headers.find("host").?;
398 return try std.fmt.allocPrint(alloc, "{s}://{s}{s}", .{ proto, host, callbackPath });
399 return try nio.fmt.allocPrint(alloc, "{s}://{s}{s}", .{ proto, host, callbackPath });
399400}
400401
401402fn fixId(alloc: std.mem.Allocator, id: std.json.Value) !string {
402403 return switch (id) {
403404 .string => |v| v,
404 .integer => |v| try std.fmt.allocPrint(alloc, "{d}", .{v}),
405 .float => |v| try std.fmt.allocPrint(alloc, "{d}", .{v}),
405 .integer => |v| try nio.fmt.allocPrint(alloc, "{d}", .{v}),
406 .float => |v| try nio.fmt.allocPrint(alloc, "{d}", .{v}),
406407 else => unreachable,
407408 };
408409}
zig.mod+1
......@@ -10,3 +10,4 @@ dependencies:
1010 - src: git https://github.com/nektro/zig-extras
1111 - src: git https://github.com/nektro/zig-whatwg-url
1212 - src: git https://github.com/nektro/zig-net-http
13 - src: git https://github.com/nektro/zig-nio