| ... | ... | @@ -313,9 +313,9 @@ pub fn Handlers(comptime T: type) type { |
| 313 | 313 | try params.append("state", "none"); |
| 314 | 314 | const req_body = try params.encode(); |
| 315 | 315 | |
| 316 | | var req = try http_client.open(.POST, try std.Uri.parse(client.provider.token_url), .{ |
| 317 | | .server_header_buffer = &buf, |
| 316 | var req = try http_client.request(.POST, try std.Uri.parse(client.provider.token_url), .{ |
| 318 | 317 | .headers = .{ |
| 318 | .accept_encoding = .{ .override = "identity" }, |
| 319 | 319 | .authorization = .{ .override = try nio.fmt.allocPrint(alloc, "Basic {s}", .{try extras.base64EncodeAlloc(alloc, try std.mem.join(alloc, ":", &.{ client.id, client.secret }))}) }, |
| 320 | 320 | .content_type = .{ .override = "application/x-www-form-urlencoded" }, |
| 321 | 321 | }, |
| ... | ... | @@ -325,14 +325,11 @@ pub fn Handlers(comptime T: type) type { |
| 325 | 325 | .redirect_behavior = .not_allowed, |
| 326 | 326 | }); |
| 327 | 327 | defer req.deinit(); |
| 328 | | req.transfer_encoding = .{ .content_length = req_body.len }; |
| 329 | | try req.send(); |
| 330 | | try req.writer().writeAll(req_body); |
| 331 | | try req.finish(); |
| 332 | | try req.wait(); |
| 333 | | const body_content = try req.reader().readAllAlloc(alloc, 1024 * 1024 * 5); |
| 334 | | if (req.response.status != .ok) std.log.scoped(.oauth).debug("{s}: {s}", .{ @tagName(req.response.status), body_content }); |
| 335 | | if (req.response.status != .ok) return error.OauthBadToken; |
| 328 | try req.sendBodyComplete(req_body); |
| 329 | var resp = try req.receiveHead(&.{}); |
| 330 | const body_content = try resp.reader(&buf).allocRemaining(alloc, .limited(1024 * 1024 * 5)); |
| 331 | if (resp.head.status != .ok) std.log.scoped(.oauth).debug("{s}: {s}", .{ @tagName(resp.head.status), body_content }); |
| 332 | if (resp.head.status != .ok) return error.OauthBadToken; |
| 336 | 333 | const val = try json.parseFromSlice(alloc, "body.json", body_content, .{ .maximum_depth = 100, .support_trailing_commas = true }); |
| 337 | 334 | val.acquire(); |
| 338 | 335 | const tt = val.root.object().getS("token_type").?; |
| ... | ... | @@ -340,9 +337,9 @@ pub fn Handlers(comptime T: type) type { |
| 340 | 337 | const at = val.root.object().getS("access_token") orelse return try fail(response_status, body_writer, "Identity Provider Login Error!\n{s}", .{body_content}); |
| 341 | 338 | val.release(); |
| 342 | 339 | |
| 343 | | var req2 = try http_client.open(.GET, try std.Uri.parse(client.provider.me_url), .{ |
| 344 | | .server_header_buffer = &buf, |
| 340 | var req2 = try http_client.request(.GET, try std.Uri.parse(client.provider.me_url), .{ |
| 345 | 341 | .headers = .{ |
| 342 | .accept_encoding = .{ .override = "identity" }, |
| 346 | 343 | .authorization = .{ .override = try nio.fmt.allocPrint(alloc, "Bearer {s}", .{at}) }, |
| 347 | 344 | }, |
| 348 | 345 | .extra_headers = &.{ |
| ... | ... | @@ -351,12 +348,11 @@ pub fn Handlers(comptime T: type) type { |
| 351 | 348 | .redirect_behavior = .not_allowed, |
| 352 | 349 | }); |
| 353 | 350 | defer req2.deinit(); |
| 354 | | try req2.send(); |
| 355 | | try req2.finish(); |
| 356 | | try req2.wait(); |
| 357 | | const body_content2 = try req2.reader().readAllAlloc(alloc, 1024 * 1024 * 5); |
| 358 | | if (req2.response.status != .ok) std.log.scoped(.oauth).debug("{s}: {s}", .{ @tagName(req2.response.status), body_content2 }); |
| 359 | | if (req2.response.status != .ok) return error.OauthBadUserinfo; |
| 351 | try req2.sendBodiless(); |
| 352 | var resp2 = try req2.receiveHead(&.{}); |
| 353 | const body_content2 = try resp2.reader(&buf).allocRemaining(alloc, .limited(1024 * 1024 * 5)); |
| 354 | if (resp2.head.status != .ok) std.log.scoped(.oauth).debug("{s}: {s}", .{ @tagName(resp2.head.status), body_content2 }); |
| 355 | if (resp2.head.status != .ok) return error.OauthBadUserinfo; |
| 360 | 356 | const val2 = try json.parseFromSlice(alloc, "body2.json", body_content2, .{ .maximum_depth = 100, .support_trailing_commas = true }); |
| 361 | 357 | val2.acquire(); |
| 362 | 358 | const id = try fixId(val2.root.object().getAny(client.provider.id_prop).?); |