| ... | @@ -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: *http.HeadersMap) !void { | 258 | pub fn login(request: *http.ServerRequest, body_writer: anytype, alloc: std.mem.Allocator, query: url.SearchParams, request_headers: *const http.HeadersMap, 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); |
| ... | @@ -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: *http.HeadersMap) !void { | 275 | pub fn callback(request: *http.ServerRequest, body_writer: anytype, alloc: std.mem.Allocator, query: url.SearchParams, request_headers: *const http.HeadersMap, 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}); |
| ... | @@ -327,7 +327,7 @@ pub fn Handlers(comptime T: type) type { | ... | @@ -327,7 +327,7 @@ pub fn Handlers(comptime T: type) type { |
| 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: *http.HeadersMap) !void { | 330 | fn loginOne(request: *http.ServerRequest, alloc: std.mem.Allocator, comptime T: type, client: Client, callbackPath: string, request_headers: *const http.HeadersMap, 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("location", T.doneUrl); | 332 | try response_headers.append("location", T.doneUrl); |
| 333 | } else { | 333 | } else { |
| ... | @@ -350,11 +350,11 @@ fn fail(response_status: *http.Status, body_writer: anytype, comptime err: strin | ... | @@ -350,11 +350,11 @@ fn fail(response_status: *http.Status, body_writer: anytype, comptime err: strin |
| 350 | try body_writer.print(err, args); | 350 | try body_writer.print(err, args); |
| 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 http.HeadersMap, alloc: std.mem.Allocator, callbackPath: string) !string { |
| 354 | const xproto = request_headers.get("x-forwarded-proto") orelse ""; | 354 | const xproto = request_headers.find("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.find("host").?; |
| 358 | return try std.fmt.allocPrint(alloc, "{s}://{s}{s}", .{ proto, host, callbackPath }); | 358 | return try std.fmt.allocPrint(alloc, "{s}://{s}{s}", .{ proto, host, callbackPath }); |
| 359 | } | 359 | } |
| 360 | | 360 | |