| ... | @@ -255,7 +255,7 @@ pub fn Handlers(comptime T: type) type { | ... | @@ -255,7 +255,7 @@ pub fn Handlers(comptime T: type) type { |
| 255 | const Self = @This(); | 255 | const Self = @This(); |
| 256 | pub var clients: []Client = &.{}; | 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 | if (query.get("with")) |with| { | 259 | if (query.get("with")) |with| { |
| 260 | const client = clientByProviderId(Self.clients, with) orelse return try fail(response_status, body_writer, "Client with that ID not found!\n", .{}); | 260 | const client = clientByProviderId(Self.clients, with) orelse return try fail(response_status, body_writer, "Client with that ID not found!\n", .{}); |
| 261 | return try loginOne(request, alloc, T, client, T.callbackPath, request_headers, response_status, response_headers); | 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,7 +264,7 @@ pub fn Handlers(comptime T: type) type { |
| 264 | return try loginOne(request, alloc, T, clients[0], T.callbackPath, request_headers, response_status, response_headers); | 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 | const page = files.@"/selector.pek"; | 268 | const page = files.@"/selector.pek"; |
| 269 | const tmpl = comptime pek.parse(page); | 269 | const tmpl = comptime pek.parse(page); |
| 270 | try pek.compile(Base, alloc, body_writer, tmpl, .{ | 270 | try pek.compile(Base, alloc, body_writer, tmpl, .{ |
| ... | @@ -272,7 +272,7 @@ pub fn Handlers(comptime T: type) type { | ... | @@ -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 | _ = request; | 276 | _ = request; |
| 277 | const state = query.get("state") orelse return try fail(response_status, body_writer, "", .{}); | 277 | const state = query.get("state") orelse return try fail(response_status, body_writer, "", .{}); |
| 278 | const client = clientByProviderId(Self.clients, state) orelse return try fail(response_status, body_writer, "error: No handler found for provider: {s}\n", .{state}); | 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,15 +321,15 @@ pub fn Handlers(comptime T: type) type { |
| 321 | const name = val2.value.object.get(client.provider.name_prop).?.string; | 321 | const name = val2.value.object.get(client.provider.name_prop).?.string; |
| 322 | try T.saveInfo(response_headers, alloc, client.provider, id, name, val.value, val2.value); | 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 | response_status.* = .found; | 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 | if (try T.isLoggedIn(request, alloc)) { | 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 | } else { | 333 | } else { |
| 334 | const idp = client.provider; | 334 | const idp = client.provider; |
| 335 | var params = url.SearchParams.init(alloc); | 335 | var params = url.SearchParams.init(alloc); |
| ... | @@ -340,7 +340,7 @@ fn loginOne(request: *http.ServerRequest, alloc: std.mem.Allocator, comptime T: | ... | @@ -340,7 +340,7 @@ fn loginOne(request: *http.ServerRequest, alloc: std.mem.Allocator, comptime T: |
| 340 | try params.append("duration", "temporary"); | 340 | try params.append("duration", "temporary"); |
| 341 | try params.append("state", idp.id); | 341 | try params.append("state", idp.id); |
| 342 | const authurl = try std.mem.join(alloc, "?", &.{ idp.authorize_url, try params.encode() }); | 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 | response_status.* = .found; | 345 | response_status.* = .found; |
| 346 | } | 346 | } |
| ... | @@ -351,7 +351,7 @@ fn fail(response_status: *http.Status, body_writer: anytype, comptime err: strin | ... | @@ -351,7 +351,7 @@ fn fail(response_status: *http.Status, body_writer: anytype, comptime err: strin |
| 351 | } | 351 | } |
| 352 | | 352 | |
| 353 | fn redirectUri(request_headers: *const std.StringHashMapUnmanaged(string), alloc: std.mem.Allocator, callbackPath: string) !string { | 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 | const maybe_tls = std.mem.eql(u8, xproto, "https"); | 355 | const maybe_tls = std.mem.eql(u8, xproto, "https"); |
| 356 | const proto: string = if (maybe_tls) "https" else "http"; | 356 | const proto: string = if (maybe_tls) "https" else "http"; |
| 357 | const host = request_headers.get("host").?; | 357 | const host = request_headers.get("host").?; |