Skip to content

Commit 96e5052

Browse files
committed
upgraded to oauth v4
1 parent 2ee3842 commit 96e5052

File tree

3 files changed

+3
-64
lines changed

3 files changed

+3
-64
lines changed

tmc-langs-core/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ reqwest = { version = "0.10", default-features = false, features = ["blocking",
1010
thiserror = "1"
1111
serde = { version = "1", features = ["derive"] }
1212
http = "0.2"
13-
http1 = { package = "http", version = "0.1" }
1413
url = "2"
15-
url1 = { package = "url", version = "1" }
1614
log = "0.4"
17-
oauth2 = { version = "3", default-features = false }
15+
oauth2 = "4.0.0-alpha.1"
1816
tempfile = "3"
1917
dirs = "2"
2018
regex = "1"

tmc-langs-core/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use url::Url;
88

99
pub(crate) type Result<T> = std::result::Result<T, CoreError>;
1010
type TokenError = oauth2::RequestTokenError<
11-
CoreError,
11+
oauth2::reqwest::Error<reqwest::Error>,
1212
oauth2::StandardErrorResponse<oauth2::basic::BasicErrorResponseType>,
1313
>;
1414

tmc-langs-core/src/tmc_core.rs

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -104,65 +104,6 @@ impl TmcCore {
104104
email: String,
105105
password: String,
106106
) -> Result<()> {
107-
// required until oauth 4.x.x
108-
fn custom_client<'a>(
109-
client: &'a Client,
110-
) -> impl FnOnce(oauth2::HttpRequest) -> Result<oauth2::HttpResponse> + 'a {
111-
move |req| {
112-
// convert httprequest fields
113-
let method = http::method::Method::from_bytes(req.method.as_str().as_bytes())
114-
.expect("failed to convert method");
115-
let mut headers = http::HeaderMap::new();
116-
let mut next_key = None;
117-
for (key, val) in req.headers {
118-
// if key is none, keep using previous next key
119-
if key.is_some() {
120-
// update next key
121-
next_key = key;
122-
}
123-
let header_name = if let Some(name) = next_key.as_ref() {
124-
// use next key
125-
name
126-
} else {
127-
log::error!("invalid header map, found None key first");
128-
continue;
129-
};
130-
let header_name =
131-
http::header::HeaderName::from_bytes(header_name.as_str().as_bytes())
132-
.expect("failed to convert header name");
133-
let header_value = http::header::HeaderValue::from_bytes(val.as_bytes())
134-
.expect("failed to convert header value");
135-
headers.insert(header_name, header_value);
136-
}
137-
let res = client
138-
.request(method, req.url)
139-
.headers(headers)
140-
.body(req.body)
141-
.send()?;
142-
143-
// convert response to httpresponse
144-
let status_code = http1::StatusCode::from_bytes(res.status().as_str().as_bytes())
145-
.expect("failed to convert status code");
146-
let mut headers = http1::HeaderMap::new();
147-
for (key, val) in res.headers() {
148-
let header_name =
149-
http1::header::HeaderName::from_bytes(key.as_str().as_bytes())
150-
.expect("failed to convert header name");
151-
let header_value = http1::header::HeaderValue::from_bytes(val.as_bytes())
152-
.expect("failed to convert header value");
153-
headers.insert(header_name, header_value);
154-
}
155-
let body = res.bytes()?.to_vec();
156-
let res = oauth2::HttpResponse {
157-
status_code,
158-
headers,
159-
body,
160-
};
161-
162-
Ok(res)
163-
}
164-
}
165-
166107
if self.token.is_some() {
167108
return Err(CoreError::AlreadyAuthenticated);
168109
}
@@ -191,7 +132,7 @@ impl TmcCore {
191132
&ResourceOwnerUsername::new(email),
192133
&ResourceOwnerPassword::new(password),
193134
)
194-
.request(custom_client(&self.client))?;
135+
.request(oauth2::reqwest::http_client)?;
195136
self.token = Some(token);
196137
log::debug!("authenticated");
197138
Ok(())

0 commit comments

Comments
 (0)