| ... | ... | @@ -255,7 +255,7 @@ pub fn Handlers(comptime T: type) type { |
| 255 | 255 | const Self = @This(); |
| 256 | 256 | pub var clients: []Client = &.{}; |
| 257 | 257 | |
| 258 | | pub fn login(request: *http.ServerRequest, body_writer: anytype, alloc: std.mem.Allocator, query: url.SearchParams, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *http.Status, response_headers: *std.ArrayListUnmanaged(std.http.Header)) !void { |
| 258 | pub fn login(request: *http.ServerRequest, body_writer: anytype, alloc: std.mem.Allocator, query: url.SearchParams, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *http.Status, response_headers: *http.HeadersMap) !void { |
| 259 | 259 | if (query.get("with")) |with| { |
| 260 | 260 | const client = clientByProviderId(Self.clients, with) orelse return try fail(response_status, body_writer, "Client with that ID not found!\n", .{}); |
| 261 | 261 | return try loginOne(request, alloc, T, client, T.callbackPath, request_headers, response_status, response_headers); |
| ... | ... | @@ -264,7 +264,7 @@ pub fn Handlers(comptime T: type) type { |
| 264 | 264 | return try loginOne(request, alloc, T, clients[0], T.callbackPath, request_headers, response_status, response_headers); |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | | try response_headers.append(alloc, .{ .name = "Content-Type", .value = "text/html" }); |
| 267 | try response_headers.append("content-type", "text/html"); |
| 268 | 268 | const page = files.@"/selector.pek"; |
| 269 | 269 | const tmpl = comptime pek.parse(page); |
| 270 | 270 | try pek.compile(Base, alloc, body_writer, tmpl, .{ |
| ... | ... | @@ -272,7 +272,7 @@ pub fn Handlers(comptime T: type) type { |
| 272 | 272 | }); |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | | pub fn callback(request: *http.ServerRequest, body_writer: anytype, alloc: std.mem.Allocator, query: url.SearchParams, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *http.Status, response_headers: *std.ArrayListUnmanaged(std.http.Header)) !void { |
| 275 | pub fn callback(request: *http.ServerRequest, body_writer: anytype, alloc: std.mem.Allocator, query: url.SearchParams, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *http.Status, response_headers: *http.HeadersMap) !void { |
| 276 | 276 | _ = request; |
| 277 | 277 | const state = query.get("state") orelse return try fail(response_status, body_writer, "", .{}); |
| 278 | 278 | const client = clientByProviderId(Self.clients, state) orelse return try fail(response_status, body_writer, "error: No handler found for provider: {s}\n", .{state}); |
| ... | ... | @@ -321,15 +321,15 @@ pub fn Handlers(comptime T: type) type { |
| 321 | 321 | const name = val2.value.object.get(client.provider.name_prop).?.string; |
| 322 | 322 | try T.saveInfo(response_headers, alloc, client.provider, id, name, val.value, val2.value); |
| 323 | 323 | |
| 324 | | try response_headers.append(alloc, .{ .name = "Location", .value = T.doneUrl }); |
| 324 | try response_headers.append("location", T.doneUrl); |
| 325 | 325 | response_status.* = .found; |
| 326 | 326 | } |
| 327 | 327 | }; |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | | fn loginOne(request: *http.ServerRequest, alloc: std.mem.Allocator, comptime T: type, client: Client, callbackPath: string, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *http.Status, response_headers: *std.ArrayListUnmanaged(std.http.Header)) !void { |
| 330 | fn loginOne(request: *http.ServerRequest, alloc: std.mem.Allocator, comptime T: type, client: Client, callbackPath: string, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *http.Status, response_headers: *http.HeadersMap) !void { |
| 331 | 331 | if (try T.isLoggedIn(request, alloc)) { |
| 332 | | try response_headers.append(alloc, .{ .name = "Location", .value = T.doneUrl }); |
| 332 | try response_headers.append("location", T.doneUrl); |
| 333 | 333 | } else { |
| 334 | 334 | const idp = client.provider; |
| 335 | 335 | var params = url.SearchParams.init(alloc); |
| ... | ... | @@ -340,7 +340,7 @@ fn loginOne(request: *http.ServerRequest, alloc: std.mem.Allocator, comptime T: |
| 340 | 340 | try params.append("duration", "temporary"); |
| 341 | 341 | try params.append("state", idp.id); |
| 342 | 342 | const authurl = try std.mem.join(alloc, "?", &.{ idp.authorize_url, try params.encode() }); |
| 343 | | try response_headers.append(alloc, .{ .name = "Location", .value = authurl }); |
| 343 | try response_headers.append("location", authurl); |
| 344 | 344 | } |
| 345 | 345 | response_status.* = .found; |
| 346 | 346 | } |
| ... | ... | @@ -351,7 +351,7 @@ fn fail(response_status: *http.Status, body_writer: anytype, comptime err: strin |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | fn redirectUri(request_headers: *const std.StringHashMapUnmanaged(string), alloc: std.mem.Allocator, callbackPath: string) !string { |
| 354 | | const xproto = request_headers.get("X-Forwarded-Proto") orelse ""; |
| 354 | const xproto = request_headers.get("x-forwarded-proto") orelse ""; |
| 355 | 355 | const maybe_tls = std.mem.eql(u8, xproto, "https"); |
| 356 | 356 | const proto: string = if (maybe_tls) "https" else "http"; |
| 357 | 357 | const host = request_headers.get("host").?; |