authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-02-02 04:36:25 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-02-02 04:36:25 -08:00
log3ff196f05862e08263bc49339b3704704804813a
tree8b13d3a06565adf2971ea691ed9d3252bfb154bb
parente91ba1b1acc69dadeb44f636993cd7b9a913fa3b

pass proper redirect_uri when behind a tls reverse proxy


1 files changed, 5 insertions(+), 1 deletions(-)

src/lib.zig+5-1
......@@ -330,7 +330,11 @@ fn fail(response: *http.Response, comptime err: string, args: anytype) !void {
330330}
331331
332332fn redirectUri(alloc: std.mem.Allocator, request: http.Request, callbackPath: string) !string {
333 return try std.fmt.allocPrint(alloc, "http://{s}{s}", .{ request.host().?, callbackPath });
333 const headers = try request.headers(alloc);
334 const xproto = headers.get("X-Forwarded-Proto") orelse "";
335 const maybe_tls = std.mem.eql(u8, xproto, "https");
336 const proto: string = if (maybe_tls) "https" else "http";
337 return try std.fmt.allocPrint(alloc, "{s}://{s}{s}", .{ proto, request.host().?, callbackPath });
334338}
335339
336340fn fixId(alloc: std.mem.Allocator, id: json.Value) !string {