From 3ff196f05862e08263bc49339b3704704804813a Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Wed, 2 Feb 2022 04:36:25 -0800 Subject: [PATCH] pass proper redirect_uri when behind a tls reverse proxy --- src/lib.zig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib.zig b/src/lib.zig index 3648026b973e48aee8c95d706f80b9e13a014970..26e8709ec6de2bc84b2d22032583e7a526e7d0fe 100644 --- a/src/lib.zig +++ b/src/lib.zig @@ -330,7 +330,11 @@ fn fail(response: *http.Response, comptime err: string, args: anytype) !void { } fn redirectUri(alloc: std.mem.Allocator, request: http.Request, callbackPath: string) !string { - return try std.fmt.allocPrint(alloc, "http://{s}{s}", .{ request.host().?, callbackPath }); + const headers = try request.headers(alloc); + const xproto = headers.get("X-Forwarded-Proto") orelse ""; + const maybe_tls = std.mem.eql(u8, xproto, "https"); + const proto: string = if (maybe_tls) "https" else "http"; + return try std.fmt.allocPrint(alloc, "{s}://{s}{s}", .{ proto, request.host().?, callbackPath }); } fn fixId(alloc: std.mem.Allocator, id: json.Value) !string { -- 2.54.0