From 3b0b21f8d155075e81043316434ac37a0cadd7fc Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 5 Apr 2021 20:27:42 +0200 Subject: refactor(web/converse): Use crimp instead of reqwest This simpler, curl-based HTTP client (which I wrote years ago) is a first step towards cleaning up the dependency mess of converse. Dependency stats: +4, -28 Change-Id: I4f5f3c9307895d261bfb0a6bcf2337b747f9a4c0 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2859 Tested-by: BuildkiteCI Reviewed-by: tazjin --- web/converse/Cargo.lock | 424 ++++++++------------------------------------- web/converse/Cargo.toml | 3 +- web/converse/src/errors.rs | 16 +- web/converse/src/main.rs | 3 +- web/converse/src/oidc.rs | 48 +++-- 5 files changed, 115 insertions(+), 379 deletions(-) (limited to 'web') diff --git a/web/converse/Cargo.lock b/web/converse/Cargo.lock index 67f3819e36bd..351ab1d261a5 100644 --- a/web/converse/Cargo.lock +++ b/web/converse/Cargo.lock @@ -68,7 +68,7 @@ dependencies = [ "brotli2", "byteorder", "bytes", - "cookie 0.11.4", + "cookie", "encoding", "failure", "flate2", @@ -103,7 +103,7 @@ dependencies = [ "tokio-reactor", "tokio-tcp", "tokio-timer", - "url 1.7.2", + "url", "v_htmlescape", "version_check 0.1.5", ] @@ -353,7 +353,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" dependencies = [ "byteorder", - "either", "iovec", ] @@ -448,11 +447,13 @@ dependencies = [ "askama", "chrono", "comrak", + "crimp", + "curl", "diesel", "env_logger", "failure", "futures", - "hyper 0.11.27", + "hyper", "log 0.4.14", "md5", "mime_guess", @@ -460,13 +461,12 @@ dependencies = [ "pulldown-cmark", "r2d2", "rand 0.4.6", - "reqwest", "serde", "serde_derive", "serde_json", "tokio", "tokio-timer", - "url 1.7.2", + "url", "url_serde", ] @@ -486,50 +486,6 @@ dependencies = [ "time", ] -[[package]] -name = "cookie" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "888604f00b3db336d2af898ec3c1d5d0ddf5e6d462220f2ededc33a87ac4bbd5" -dependencies = [ - "time", - "url 1.7.2", -] - -[[package]] -name = "cookie_store" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46750b3f362965f197996c4448e4a0935e791bf7d6631bfce9ee0af3d24c919c" -dependencies = [ - "cookie 0.12.0", - "failure", - "idna 0.1.5", - "log 0.4.14", - "publicsuffix", - "serde", - "serde_json", - "time", - "try_from", - "url 1.7.2", -] - -[[package]] -name = "core-foundation" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" - [[package]] name = "cpuid-bool" version = "0.1.2" @@ -551,6 +507,17 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "crimp" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbe8f9a320ad9c1a2e3bacedaa281587bd297fb10a10179fd39f777049d04794" +dependencies = [ + "curl", + "serde", + "serde_json", +] + [[package]] name = "crossbeam-channel" version = "0.3.9" @@ -637,6 +604,36 @@ dependencies = [ "cipher", ] +[[package]] +name = "curl" +version = "0.4.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a872858e9cb9e3b96c80dd78774ad9e32e44d3b05dc31e142b858d14aebc82c" +dependencies = [ + "curl-sys", + "libc", + "openssl-probe", + "openssl-sys", + "schannel", + "socket2", + "winapi 0.3.9", +] + +[[package]] +name = "curl-sys" +version = "0.4.41+curl-7.75.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec466abd277c7cab2905948f3e94d10bc4963f1f5d47921c1cc4ffd2028fe65" +dependencies = [ + "cc", + "libc", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", + "winapi 0.3.9", +] + [[package]] name = "diesel" version = "1.4.6" @@ -677,12 +674,6 @@ version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0" -[[package]] -name = "either" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" - [[package]] name = "encoding" version = "0.2.33" @@ -747,15 +738,6 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569" -[[package]] -name = "encoding_rs" -version = "0.8.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065" -dependencies = [ - "cfg-if 1.0.0", -] - [[package]] name = "entities" version = "1.0.1" @@ -834,31 +816,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - -[[package]] -name = "form_urlencoded" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" -dependencies = [ - "matches", - "percent-encoding 2.1.0", -] - [[package]] name = "fuchsia-cprng" version = "0.1.1" @@ -1018,18 +975,6 @@ dependencies = [ "itoa", ] -[[package]] -name = "http-body" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6741c859c1b2463a423a1dbce98d418e6c3c3fc720fb0d45528657320920292d" -dependencies = [ - "bytes", - "futures", - "http", - "tokio-buf", -] - [[package]] name = "httparse" version = "1.3.5" @@ -1069,50 +1014,7 @@ dependencies = [ "tokio-proto", "tokio-service", "unicase", - "want 0.0.4", -] - -[[package]] -name = "hyper" -version = "0.12.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c843caf6296fc1f93444735205af9ed4e109a539005abb2564ae1d6fad34c52" -dependencies = [ - "bytes", - "futures", - "futures-cpupool", - "h2", - "http", - "http-body", - "httparse", - "iovec", - "itoa", - "log 0.4.14", - "net2", - "rustc_version", - "time", - "tokio", - "tokio-buf", - "tokio-executor", - "tokio-io", - "tokio-reactor", - "tokio-tcp", - "tokio-threadpool", - "tokio-timer", - "want 0.2.0", -] - -[[package]] -name = "hyper-tls" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a800d6aa50af4b5850b2b0f659625ce9504df908e9733b635720483be26174f" -dependencies = [ - "bytes", - "futures", - "hyper 0.12.36", - "native-tls", - "tokio-io", + "want", ] [[package]] @@ -1126,17 +1028,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "idna" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89829a5d69c23d348314a7ac337fe39173b61149a9864deabd260983aed48c21" -dependencies = [ - "matches", - "unicode-bidi", - "unicode-normalization", -] - [[package]] name = "indexmap" version = "1.6.2" @@ -1175,7 +1066,7 @@ dependencies = [ "socket2", "widestring", "winapi 0.3.9", - "winreg 0.5.1", + "winreg", ] [[package]] @@ -1218,6 +1109,18 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56d855069fafbb9b344c0f962150cd2c1187975cb1c22c1522c240d8c4986714" +[[package]] +name = "libz-sys" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "602113192b08db8f38796c4e85c39e960c145965140e918018bcde1952429655" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "linked-hash-map" version = "0.5.4" @@ -1405,24 +1308,6 @@ dependencies = [ "ws2_32-sys", ] -[[package]] -name = "native-tls" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8d96b2e1c8da3957d58100b09f102c6d9cfdfced01b7ec5a8974044bb09dbd4" -dependencies = [ - "lazy_static", - "libc", - "log 0.4.14", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "net2" version = "0.2.37" @@ -1488,32 +1373,12 @@ version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4" -[[package]] -name = "once_cell" -version = "1.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" - [[package]] name = "opaque-debug" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" -[[package]] -name = "openssl" -version = "0.10.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a61075b62a23fef5a29815de7536d940aa35ce96d18ce0cc5076272db678a577" -dependencies = [ - "bitflags 1.2.1", - "cfg-if 1.0.0", - "foreign-types", - "libc", - "once_cell", - "openssl-sys", -] - [[package]] name = "openssl-probe" version = "0.1.2" @@ -1704,16 +1569,6 @@ dependencies = [ "unicode-xid 0.2.1", ] -[[package]] -name = "publicsuffix" -version = "1.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95b4ce31ff0a27d93c8de1849cf58162283752f065a90d508f1105fa6c9a213f" -dependencies = [ - "idna 0.2.2", - "url 2.2.1", -] - [[package]] name = "pulldown-cmark" version = "0.1.2" @@ -2006,49 +1861,6 @@ dependencies = [ "futures", ] -[[package]] -name = "remove_dir_all" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi 0.3.9", -] - -[[package]] -name = "reqwest" -version = "0.9.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f88643aea3c1343c804950d7bf983bd2067f5ab59db6d613a08e05572f2714ab" -dependencies = [ - "base64 0.10.1", - "bytes", - "cookie 0.12.0", - "cookie_store", - "encoding_rs", - "flate2", - "futures", - "http", - "hyper 0.12.36", - "hyper-tls", - "log 0.4.14", - "mime", - "mime_guess", - "native-tls", - "serde", - "serde_json", - "serde_urlencoded", - "time", - "tokio", - "tokio-executor", - "tokio-io", - "tokio-threadpool", - "tokio-timer", - "url 1.7.2", - "uuid", - "winreg 0.6.2", -] - [[package]] name = "resolv-conf" version = "0.6.3" @@ -2123,29 +1935,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" -[[package]] -name = "security-framework" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3670b1d2fdf6084d192bc71ead7aabe6c06aa2ea3fbd9cc3ac111fa5c2b1bd84" -dependencies = [ - "bitflags 1.2.1", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3676258fd3cfe2c9a0ec99ce3038798d847ce3e4bb17746373eb9f0f1ac16339" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "semver" version = "0.9.0" @@ -2166,9 +1955,6 @@ name = "serde" version = "1.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "558dc50e1a5a5fa7112ca2ce4effcb321b0300c0d4ccf0776a9f60cd89031171" -dependencies = [ - "serde_derive", -] [[package]] name = "serde_derive" @@ -2201,7 +1987,7 @@ dependencies = [ "dtoa", "itoa", "serde", - "url 1.7.2", + "url", ] [[package]] @@ -2374,20 +2160,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b157868d8ac1f56b64604539990685fa7611d8fa9e5476cf0c02cf34d32917c5" -[[package]] -name = "tempfile" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "rand 0.8.3", - "redox_syscall 0.2.5", - "remove_dir_all", - "winapi 0.3.9", -] - [[package]] name = "termcolor" version = "1.1.2" @@ -2455,17 +2227,6 @@ dependencies = [ "tokio-uds", ] -[[package]] -name = "tokio-buf" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fb220f46c53859a4b7ec083e41dec9778ff0b1851c0942b211edb89e0ccdc46" -dependencies = [ - "bytes", - "either", - "futures", -] - [[package]] name = "tokio-codec" version = "0.1.2" @@ -2705,7 +2466,7 @@ dependencies = [ "byteorder", "failure", "futures", - "idna 0.1.5", + "idna", "lazy_static", "log 0.4.14", "rand 0.5.6", @@ -2717,7 +2478,7 @@ dependencies = [ "tokio-tcp", "tokio-timer", "tokio-udp", - "url 1.7.2", + "url", ] [[package]] @@ -2729,7 +2490,7 @@ dependencies = [ "byteorder", "failure", "futures", - "idna 0.1.5", + "idna", "lazy_static", "log 0.4.14", "rand 0.5.6", @@ -2741,7 +2502,7 @@ dependencies = [ "tokio-tcp", "tokio-timer", "tokio-udp", - "url 1.7.2", + "url", ] [[package]] @@ -2769,21 +2530,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee2aa4715743892880f70885373966c83d73ef1b0838a664ef0c76fffd35e7c2" -[[package]] -name = "try-lock" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" - -[[package]] -name = "try_from" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "283d3b89e1368717881a9d51dad843cc435380d8109c9e47d38780a324698d8b" -dependencies = [ - "cfg-if 0.1.10", -] - [[package]] name = "twoway" version = "0.1.8" @@ -2879,23 +2625,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" dependencies = [ "encoding", - "idna 0.1.5", + "idna", "matches", "percent-encoding 1.0.1", ] -[[package]] -name = "url" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b" -dependencies = [ - "form_urlencoded", - "idna 0.2.2", - "matches", - "percent-encoding 2.1.0", -] - [[package]] name = "url_serde" version = "0.2.0" @@ -2903,7 +2637,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74e7d099f1ee52f823d4bdd60c93c3602043c728f5db3b97bdb548467f7bddea" dependencies = [ "serde", - "url 1.7.2", + "url", ] [[package]] @@ -2978,18 +2712,7 @@ checksum = "a05d9d966753fa4b5c8db73fcab5eed4549cfe0e1e4e66911e5564a0085c35d1" dependencies = [ "futures", "log 0.4.14", - "try-lock 0.1.0", -] - -[[package]] -name = "want" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6395efa4784b027708f7451087e647ec73cc74f5d9bc2e418404248d679a230" -dependencies = [ - "futures", - "log 0.4.14", - "try-lock 0.2.3", + "try-lock", ] [[package]] @@ -3056,15 +2779,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "winreg" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9" -dependencies = [ - "winapi 0.3.9", -] - [[package]] name = "ws2_32-sys" version = "0.2.1" diff --git a/web/converse/Cargo.toml b/web/converse/Cargo.toml index 5ace4dabe1c2..c49f1c4c6a4d 100644 --- a/web/converse/Cargo.toml +++ b/web/converse/Cargo.toml @@ -10,6 +10,7 @@ actix-web = "0.7" askama = "0.6" chrono = { version = "0.4", features = ["serde"] } comrak = "0.2" +crimp = "0.2" diesel = { version = "1.2", features = ["postgres", "chrono", "r2d2"]} env_logger = "0.5" failure = "0.1" @@ -21,7 +22,6 @@ mime_guess = "2.0.0-alpha" pq-sys = "=0.4.4" r2d2 = "0.8" rand = "0.4" -reqwest = "0.9" serde = "1.0" serde_derive = "1.0" serde_json = "1.0" @@ -29,6 +29,7 @@ tokio = "0.1" tokio-timer = "0.2" url = "1.7" url_serde = "0.2" +curl = "*" # bounded by crimp [build-dependencies] pulldown-cmark = "0.1" diff --git a/web/converse/src/errors.rs b/web/converse/src/errors.rs index 6b22f8d39aa5..b079f41c4fff 100644 --- a/web/converse/src/errors.rs +++ b/web/converse/src/errors.rs @@ -31,7 +31,6 @@ use actix_web; use askama; use diesel; use r2d2; -use reqwest; use tokio_timer; pub type Result = result::Result; @@ -62,6 +61,9 @@ pub enum ConverseError { #[fail(display = "thread {} is closed and can not be responded to", id)] ThreadClosed { id: i32 }, + #[fail(display = "JSON serialisation failed: {}", error)] + Serialisation { error: serde_json::Error }, + // This variant is used as a catch-all for wrapping // actix-web-compatible response errors, such as the errors it // throws itself. @@ -103,10 +105,16 @@ impl From for ConverseError { } } -impl From for ConverseError { - fn from(error: reqwest::Error) -> ConverseError { +impl From for ConverseError { + fn from(error: serde_json::Error) -> ConverseError { + ConverseError::Serialisation { error } + } +} + +impl From for ConverseError { + fn from(error: curl::Error) -> ConverseError { ConverseError::InternalError { - reason: format!("Failed to make HTTP request: {}", error), + reason: format!("error during HTTP request: {}", error), } } } diff --git a/web/converse/src/main.rs b/web/converse/src/main.rs index 061cfa6e7baf..177bdf025ede 100644 --- a/web/converse/src/main.rs +++ b/web/converse/src/main.rs @@ -35,6 +35,8 @@ extern crate actix; extern crate actix_web; extern crate chrono; extern crate comrak; +extern crate crimp; +extern crate curl; extern crate env_logger; extern crate futures; extern crate hyper; @@ -42,7 +44,6 @@ extern crate md5; extern crate mime_guess; extern crate r2d2; extern crate rand; -extern crate reqwest; extern crate serde; extern crate serde_json; extern crate tokio; diff --git a/web/converse/src/oidc.rs b/web/converse/src/oidc.rs index baa6e626c0ac..9f566c04a71a 100644 --- a/web/converse/src/oidc.rs +++ b/web/converse/src/oidc.rs @@ -23,10 +23,11 @@ //! this has so far only been tested with Office365. use actix::prelude::*; -use reqwest; +use crate::errors::*; +use crimp::Request; use url::Url; use url_serde; -use crate::errors::*; +use curl::easy::Form; /// This structure represents the contents of an OIDC discovery /// document. @@ -111,26 +112,37 @@ impl Handler for OidcExecutor { fn handle(&mut self, msg: RetrieveToken, _: &mut Self::Context) -> Self::Result { debug!("Received OAuth2 code, requesting access_token"); - let client = reqwest::Client::new(); - let params: [(&str, &str); 5] = [ - ("client_id", &self.client_id), - ("client_secret", &self.client_secret), - ("grant_type", "authorization_code"), - ("code", &msg.0.code), - ("redirect_uri", &self.redirect_uri), - ]; - - let mut response = client.post(&self.oidc_config.token_endpoint) - .form(¶ms) + + let mut form = Form::new(); + form.part("client_id").contents(&self.client_id.as_bytes()) + .add().expect("critical error: invalid form data"); + + form.part("client_secret").contents(&self.client_secret.as_bytes()) + .add().expect("critical error: invalid form data"); + + form.part("grant_type").contents("authorization_code".as_bytes()) + .add().expect("critical error: invalid form data"); + + form.part("code").contents(&msg.0.code.as_bytes()) + .add().expect("critical error: invalid form data"); + + form.part("redirect_uri").contents(&self.redirect_uri.as_bytes()) + .add().expect("critical error: invalid form data"); + + let response = Request::post(&self.oidc_config.token_endpoint) + .user_agent(concat!("converse-", env!("CARGO_PKG_VERSION")))? + .form(form) .send()?; debug!("Received token response: {:?}", response); - let token: TokenResponse = response.json()?; + let token: TokenResponse = response.as_json()?.body; - let user: Userinfo = client.get(&self.oidc_config.userinfo_endpoint) - .header("Authorization", format!("Bearer {}", token.access_token )) + let bearer = format!("Bearer {}", token.access_token); + let user: Userinfo = Request::get(&self.oidc_config.userinfo_endpoint) + .user_agent(concat!("converse-", env!("CARGO_PKG_VERSION")))? + .header("Authorization", &bearer)? .send()? - .json()?; + .as_json()?.body; Ok(Author { name: user.name, @@ -142,6 +154,6 @@ impl Handler for OidcExecutor { /// Convenience function to attempt loading an OIDC discovery document /// from a specified URL: pub fn load_oidc(url: &str) -> Result { - let config: OidcConfig = reqwest::get(url)?.json()?; + let config: OidcConfig = Request::get(url).send()?.as_json()?.body; Ok(config) } -- cgit 1.4.1