diff --git a/oauth2.zig b/oauth2.zig index c0b46b86413c9b53a1fce5a936b4311f889dea72..0a0feb303d0a407eaa72566822800c1275192fb9 100644 --- a/oauth2.zig +++ b/oauth2.zig @@ -255,7 +255,7 @@ pub fn Handlers(comptime T: type) type { const Self = @This(); pub var clients: []Client = &.{}; - 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 { + 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 { if (query.get("with")) |with| { const client = clientByProviderId(Self.clients, with) orelse return try fail(response_status, body_writer, "Client with that ID not found!\n", .{}); 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 { }); } - 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 { + 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 { _ = request; const state = query.get("state") orelse return try fail(response_status, body_writer, "", .{}); 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 { }; } -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 { +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 { if (try T.isLoggedIn(request, alloc)) { try response_headers.append("location", T.doneUrl); } else { @@ -350,11 +350,11 @@ fn fail(response_status: *http.Status, body_writer: anytype, comptime err: strin try body_writer.print(err, args); } -fn redirectUri(request_headers: *const std.StringHashMapUnmanaged(string), alloc: std.mem.Allocator, callbackPath: string) !string { - const xproto = request_headers.get("x-forwarded-proto") orelse ""; +fn redirectUri(request_headers: *const http.HeadersMap, alloc: std.mem.Allocator, callbackPath: string) !string { + const xproto = request_headers.find("x-forwarded-proto") orelse ""; const maybe_tls = std.mem.eql(u8, xproto, "https"); const proto: string = if (maybe_tls) "https" else "http"; - const host = request_headers.get("host").?; + const host = request_headers.find("host").?; return try std.fmt.allocPrint(alloc, "{s}://{s}{s}", .{ proto, host, callbackPath }); }