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