| ... | ... | @@ -6,7 +6,7 @@ const files = @import("./files.zig"); |
| 6 | 6 | const pek = @import("pek"); |
| 7 | 7 | const zfetch = @import("zfetch"); |
| 8 | 8 | const extras = @import("extras"); |
| 9 | | const UrlValues = @import("UrlValues"); |
| 9 | const url = @import("url"); |
| 10 | 10 | const Base = @This(); |
| 11 | 11 | |
| 12 | 12 | pub const Provider = struct { |
| ... | ... | @@ -254,7 +254,7 @@ pub fn Handlers(comptime T: type) type { |
| 254 | 254 | const Self = @This(); |
| 255 | 255 | pub var clients: []Client = &.{}; |
| 256 | 256 | |
| 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 | 258 | if (query.get("with")) |with| { |
| 259 | 259 | const client = clientByProviderId(Self.clients, with) orelse return try fail(response_status, body_writer, "Client with that ID not found!\n", .{}); |
| 260 | 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 | 271 | }); |
| 272 | 272 | } |
| 273 | 273 | |
| 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 | 275 | _ = request; |
| 276 | 276 | const state = query.get("state") orelse return try fail(response_status, body_writer, "", .{}); |
| 277 | 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 | 278 | const code = query.get("code") orelse return try fail(response_status, body_writer, "", .{}); |
| 279 | 279 | |
| 280 | | var params = UrlValues.init(alloc); |
| 280 | var params = url.SearchParams.init(alloc); |
| 281 | 281 | try params.append("client_id", client.id); |
| 282 | 282 | try params.append("client_secret", client.secret); |
| 283 | 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 | 331 | try response_headers.append(alloc, .{ .name = "Location", .value = T.doneUrl }); |
| 332 | 332 | } else { |
| 333 | 333 | const idp = client.provider; |
| 334 | | var params = UrlValues.init(alloc); |
| 334 | var params = url.SearchParams.init(alloc); |
| 335 | 335 | try params.append("client_id", client.id); |
| 336 | 336 | try params.append("redirect_uri", try redirectUri(request_headers, alloc, callbackPath)); |
| 337 | 337 | try params.append("response_type", "code"); |