| ... | ... | @@ -262,10 +262,11 @@ pub fn Handlers(comptime T: type) type { |
| 262 | 262 | try headers.appendValue("Authorization", try std.fmt.allocPrint(alloc, "Basic {s}", .{try extras.base64EncodeAlloc(alloc, try std.mem.join(alloc, ":", &.{ client.id, client.secret }))})); |
| 263 | 263 | try headers.appendValue("Accept", "application/json"); |
| 264 | 264 | |
| 265 | | // TODO print error message to response if this fails |
| 266 | 265 | try req.do(.POST, headers, try params.encode()); |
| 267 | 266 | const r = req.reader(); |
| 268 | 267 | const body_content = try r.readAllAlloc(alloc, 1024 * 1024 * 5); |
| 268 | if (req.status != .ok) std.log.scoped(.oauth).debug("{s}", .{body_content}); |
| 269 | if (req.status != .ok) return error.OauthBadToken; |
| 269 | 270 | const val = try extras.parse_json(alloc, body_content); |
| 270 | 271 | |
| 271 | 272 | const at = val.root.object.get("access_token") orelse return try fail(response, body_writer, "Identity Provider Login Error!\n{s}", .{body_content}); |
| ... | ... | @@ -275,10 +276,11 @@ pub fn Handlers(comptime T: type) type { |
| 275 | 276 | try headers2.appendValue("Authorization", try std.fmt.allocPrint(alloc, "Bearer {s}", .{at.string})); |
| 276 | 277 | try headers2.appendValue("Accept", "application/json"); |
| 277 | 278 | |
| 278 | | // TODO print error message if this fails |
| 279 | 279 | try req2.do(.GET, headers2, null); |
| 280 | 280 | const r2 = req2.reader(); |
| 281 | 281 | const body_content2 = try r2.readAllAlloc(alloc, 1024 * 1024 * 5); |
| 282 | if (req2.status != .ok) std.log.scoped(.oauth).debug("{s}", .{body_content2}); |
| 283 | if (req2.status != .ok) return error.OauthBadUserinfo; |
| 282 | 284 | const val2 = try extras.parse_json(alloc, body_content2); |
| 283 | 285 | |
| 284 | 286 | const id = try fixId(alloc, val2.root.object.get(client.provider.id_prop).?); |