authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-05-31 01:23:49 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-05-31 01:23:49 -07:00
logfc6019f80f5d9a4e4465f1f8d7978c252d9f23fa
tree3992f6d2e53eb899c54ee012646a2d2efad44af9
parentbfaf7b50c0300ea64d770ea432f9fbc247e4a50f

use std.json instead of nektro/zig-json


2 files changed, 7 insertions(+), 9 deletions(-)

src/lib.zig+7-8
......@@ -6,7 +6,6 @@ const http = @import("apple_pie");
66const files = @import("self/files");
77const pek = @import("pek");
88const zfetch = @import("zfetch");
9const json = @import("json");
109const extras = @import("extras");
1110const UrlValues = @import("UrlValues");
1211const Base = @This();
......@@ -280,24 +279,24 @@ pub fn Handlers(comptime T: type) type {
280279 try req.do(.POST, headers, try params.encode());
281280 const r = req.reader();
282281 const body_content = try r.readAllAlloc(alloc, 1024 * 1024 * 5);
283 const val = try json.parse(alloc, body_content);
282 const val = try extras.parse_json(alloc, body_content);
284283
285 const at = val.get("access_token") orelse return try fail(response, "Identity Provider Login Error!\n{s}", .{body_content});
284 const at = val.root.object.get("access_token") orelse return try fail(response, body_writer, "Identity Provider Login Error!\n{s}", .{body_content});
286285
287286 const req2 = try zfetch.Request.init(alloc, client.provider.me_url, null);
288287 var headers2 = zfetch.Headers.init(alloc);
289 try headers2.appendValue("Authorization", try std.fmt.allocPrint(alloc, "Bearer {s}", .{at.String}));
288 try headers2.appendValue("Authorization", try std.fmt.allocPrint(alloc, "Bearer {s}", .{at.string}));
290289 try headers2.appendValue("Accept", "application/json");
291290
292291 // TODO print error message if this fails
293292 try req2.do(.GET, headers2, null);
294293 const r2 = req2.reader();
295294 const body_content2 = try r2.readAllAlloc(alloc, 1024 * 1024 * 5);
296 const val2 = try json.parse(alloc, body_content2);
295 const val2 = try extras.parse_json(alloc, body_content2);
297296
298 const id = try fixId(alloc, val2.get(client.provider.id_prop).?);
299 const name = val2.get(client.provider.name_prop).?.String;
300 try T.saveInfo(response, request, client.provider, id, name, val, val2);
297 const id = try fixId(alloc, val2.root.object.get(client.provider.id_prop).?);
298 const name = val2.root.object.get(client.provider.name_prop).?.string;
299 try T.saveInfo(response, alloc, client.provider, id, name, val.root, val2.root);
301300
302301 try response.headers.put("Location", T.doneUrl);
303302 try response.writeHeader(.found);
zig.mod-1
......@@ -9,6 +9,5 @@ dependencies:
99 - src: git https://github.com/Luukdegram/apple_pie
1010 - src: git https://github.com/nektro/zig-pek
1111 - src: git https://github.com/truemedian/zfetch
12 - src: git https://github.com/nektro/zig-json
1312 - src: git https://github.com/nektro/zig-extras
1413 - src: git https://github.com/nektro/zig-UrlValues