authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-08-26 23:43:00 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-08-26 23:43:00 -07:00
logea10cca9029d6b3c29a2d1cda51798f78fb9de9f
tree1bde333029f38546345d138ff770c551dd407d55
parent4b0978e5becb22f8dee96a7c9861f2f5513bcd78

allow apps to inject custom providers


1 files changed, 21 insertions(+), 0 deletions(-)

oauth2.zig+21
......@@ -188,6 +188,11 @@ pub fn providerById(alloc: std.mem.Allocator, name: string) !?Provider {
188188 return p;
189189 }
190190 }
191 inline for (comptime std.meta.globalOption("oauth2_providers", []const Provider) orelse &.{}) |p| {
192 if (std.mem.eql(u8, p.id, name)) {
193 return p;
194 }
195 }
191196 const c_ind = std.mem.indexOfScalar(u8, name, ',') orelse return null;
192197 const p_id = name[0..c_ind];
193198 const domain = name[c_ind + 1 ..];
......@@ -209,6 +214,22 @@ pub fn providerById(alloc: std.mem.Allocator, name: string) !?Provider {
209214 };
210215 }
211216 }
217 inline for (comptime std.meta.globalOption("oauth2_dynamic_providers", []const Provider) orelse &.{}) |didp| {
218 if (std.mem.eql(u8, didp.id, p_id)) {
219 return Provider{
220 .id = name,
221 .authorize_url = try std.fmt.allocPrint(alloc, didp.authorize_url, args),
222 .token_url = try std.fmt.allocPrint(alloc, didp.token_url, args),
223 .me_url = try std.fmt.allocPrint(alloc, didp.me_url, args),
224 .scope = didp.scope,
225 .name_prop = didp.name_prop,
226 .name_prefix = didp.name_prefix,
227 .id_prop = didp.id_prop,
228 .logo = didp.logo,
229 .color = didp.color,
230 };
231 }
232 }
212233 return null;
213234}
214235