| ... | @@ -7,6 +7,7 @@ const pek = @import("pek"); | ... | @@ -7,6 +7,7 @@ const pek = @import("pek"); |
| 7 | const extras = @import("extras"); | 7 | const extras = @import("extras"); |
| 8 | const url = @import("url"); | 8 | const url = @import("url"); |
| 9 | const http = @import("http"); | 9 | const http = @import("http"); |
| | 10 | const nio = @import("nio"); |
| 10 | const Base = @This(); | 11 | const Base = @This(); |
| 11 | | 12 | |
| 12 | pub const Provider = struct { | 13 | pub const Provider = struct { |
| ... | @@ -223,9 +224,9 @@ pub fn providerById(alloc: std.mem.Allocator, name: string) !?Provider { | ... | @@ -223,9 +224,9 @@ pub fn providerById(alloc: std.mem.Allocator, name: string) !?Provider { |
| 223 | if (std.mem.eql(u8, didp.id, p_id)) { | 224 | if (std.mem.eql(u8, didp.id, p_id)) { |
| 224 | return Provider{ | 225 | return Provider{ |
| 225 | .id = name, | 226 | .id = name, |
| 226 | .authorize_url = try std.fmt.allocPrint(alloc, didp.authorize_url, args), | 227 | .authorize_url = try nio.fmt.allocPrint(alloc, didp.authorize_url, args), |
| 227 | .token_url = try std.fmt.allocPrint(alloc, didp.token_url, args), | 228 | .token_url = try nio.fmt.allocPrint(alloc, didp.token_url, args), |
| 228 | .me_url = try std.fmt.allocPrint(alloc, didp.me_url, args), | 229 | .me_url = try nio.fmt.allocPrint(alloc, didp.me_url, args), |
| 229 | .scope = didp.scope, | 230 | .scope = didp.scope, |
| 230 | .name_prop = didp.name_prop, | 231 | .name_prop = didp.name_prop, |
| 231 | .name_prefix = didp.name_prefix, | 232 | .name_prefix = didp.name_prefix, |
| ... | @@ -239,9 +240,9 @@ pub fn providerById(alloc: std.mem.Allocator, name: string) !?Provider { | ... | @@ -239,9 +240,9 @@ pub fn providerById(alloc: std.mem.Allocator, name: string) !?Provider { |
| 239 | if (std.mem.eql(u8, didp.id, p_id)) { | 240 | if (std.mem.eql(u8, didp.id, p_id)) { |
| 240 | return Provider{ | 241 | return Provider{ |
| 241 | .id = name, | 242 | .id = name, |
| 242 | .authorize_url = try std.fmt.allocPrint(alloc, didp.authorize_url, args), | 243 | .authorize_url = try nio.fmt.allocPrint(alloc, didp.authorize_url, args), |
| 243 | .token_url = try std.fmt.allocPrint(alloc, didp.token_url, args), | 244 | .token_url = try nio.fmt.allocPrint(alloc, didp.token_url, args), |
| 244 | .me_url = try std.fmt.allocPrint(alloc, didp.me_url, args), | 245 | .me_url = try nio.fmt.allocPrint(alloc, didp.me_url, args), |
| 245 | .scope = didp.scope, | 246 | .scope = didp.scope, |
| 246 | .name_prop = didp.name_prop, | 247 | .name_prop = didp.name_prop, |
| 247 | .name_prefix = didp.name_prefix, | 248 | .name_prefix = didp.name_prefix, |
| ... | @@ -314,7 +315,7 @@ pub fn Handlers(comptime T: type) type { | ... | @@ -314,7 +315,7 @@ pub fn Handlers(comptime T: type) type { |
| 314 | var req = try http_client.open(.POST, try std.Uri.parse(client.provider.token_url), .{ | 315 | var req = try http_client.open(.POST, try std.Uri.parse(client.provider.token_url), .{ |
| 315 | .server_header_buffer = &buf, | 316 | .server_header_buffer = &buf, |
| 316 | .headers = .{ | 317 | .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 }))}) }, |
| 318 | .content_type = .{ .override = "application/x-www-form-urlencoded" }, | 319 | .content_type = .{ .override = "application/x-www-form-urlencoded" }, |
| 319 | }, | 320 | }, |
| 320 | .extra_headers = &.{ | 321 | .extra_headers = &.{ |
| ... | @@ -341,7 +342,7 @@ pub fn Handlers(comptime T: type) type { | ... | @@ -341,7 +342,7 @@ pub fn Handlers(comptime T: type) type { |
| 341 | var req2 = try http_client.open(.GET, try std.Uri.parse(client.provider.me_url), .{ | 342 | var req2 = try http_client.open(.GET, try std.Uri.parse(client.provider.me_url), .{ |
| 342 | .server_header_buffer = &buf, | 343 | .server_header_buffer = &buf, |
| 343 | .headers = .{ | 344 | .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}) }, |
| 345 | }, | 346 | }, |
| 346 | .extra_headers = &.{ | 347 | .extra_headers = &.{ |
| 347 | .{ .name = "Accept", .value = "application/json" }, | 348 | .{ .name = "Accept", .value = "application/json" }, |
| ... | @@ -395,14 +396,14 @@ fn redirectUri(request_headers: *const http.HeadersMap, alloc: std.mem.Allocator | ... | @@ -395,14 +396,14 @@ fn redirectUri(request_headers: *const http.HeadersMap, alloc: std.mem.Allocator |
| 395 | const maybe_tls = std.mem.eql(u8, xproto, "https"); | 396 | const maybe_tls = std.mem.eql(u8, xproto, "https"); |
| 396 | const proto: string = if (maybe_tls) "https" else "http"; | 397 | const proto: string = if (maybe_tls) "https" else "http"; |
| 397 | const host = request_headers.find("host").?; | 398 | 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 }); |
| 399 | } | 400 | } |
| 400 | | 401 | |
| 401 | fn fixId(alloc: std.mem.Allocator, id: std.json.Value) !string { | 402 | fn fixId(alloc: std.mem.Allocator, id: std.json.Value) !string { |
| 402 | return switch (id) { | 403 | return switch (id) { |
| 403 | .string => |v| v, | 404 | .string => |v| v, |
| 404 | .integer => |v| try std.fmt.allocPrint(alloc, "{d}", .{v}), | 405 | .integer => |v| try nio.fmt.allocPrint(alloc, "{d}", .{v}), |
| 405 | .float => |v| try std.fmt.allocPrint(alloc, "{d}", .{v}), | 406 | .float => |v| try nio.fmt.allocPrint(alloc, "{d}", .{v}), |
| 406 | else => unreachable, | 407 | else => unreachable, |
| 407 | }; | 408 | }; |
| 408 | } | 409 | } |