| ... | @@ -8,6 +8,7 @@ const pek = @import("pek"); | ... | @@ -8,6 +8,7 @@ const pek = @import("pek"); |
| 8 | const uri = @import("uri"); | 8 | const uri = @import("uri"); |
| 9 | const zfetch = @import("zfetch"); | 9 | const zfetch = @import("zfetch"); |
| 10 | const json = @import("json"); | 10 | const json = @import("json"); |
| | 11 | const extras = @import("extras"); |
| 11 | | 12 | |
| 12 | pub const Provider = struct { | 13 | pub const Provider = struct { |
| 13 | id: string, | 14 | id: string, |
| ... | @@ -241,7 +242,7 @@ pub fn Handlers(comptime T: type) type { | ... | @@ -241,7 +242,7 @@ pub fn Handlers(comptime T: type) type { |
| 241 | | 242 | |
| 242 | var headers = zfetch.Headers.init(alloc); | 243 | var headers = zfetch.Headers.init(alloc); |
| 243 | try headers.appendValue("Content-Type", "application/x-www-form-urlencoded"); | 244 | try headers.appendValue("Content-Type", "application/x-www-form-urlencoded"); |
| 244 | try headers.appendValue("Authorization", try std.fmt.allocPrint(alloc, "Basic {s}", .{try base64EncodeAlloc(alloc, try std.mem.join(alloc, ":", &.{ client.id, client.secret }))})); | 245 | try headers.appendValue("Authorization", try std.fmt.allocPrint(alloc, "Basic {s}", .{try extras.base64EncodeAlloc(alloc, try std.mem.join(alloc, ":", &.{ client.id, client.secret }))})); |
| 245 | try headers.appendValue("Accept", "application/json"); | 246 | try headers.appendValue("Accept", "application/json"); |
| 246 | | 247 | |
| 247 | // TODO print error message to response if this fails | 248 | // TODO print error message to response if this fails |
| ... | @@ -310,12 +311,6 @@ fn fixId(alloc: *std.mem.Allocator, id: json.Value) !string { | ... | @@ -310,12 +311,6 @@ fn fixId(alloc: *std.mem.Allocator, id: json.Value) !string { |
| 310 | }; | 311 | }; |
| 311 | } | 312 | } |
| 312 | | 313 | |
| 313 | fn base64EncodeAlloc(alloc: *std.mem.Allocator, input: string) !string { | | |
| 314 | const base64 = std.base64.standard_encoder; | | |
| 315 | var buf = try alloc.alloc(u8, base64.calcSize(input.len)); | | |
| 316 | return base64.encode(buf, input); | | |
| 317 | } | | |
| 318 | | | |
| 319 | // | 314 | // |
| 320 | // | 315 | // |
| 321 | | 316 | |