diff options
author | Arthur Taylor <codders@octomonkey.org.uk> | 2016-11-22 10:56:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-22 10:56:20 +0100 |
commit | 8e9d234dcfe03a24409829ddd31b51bd8f840345 (patch) | |
tree | d1d833d732faf4c8709e975a4bb6129acc3d0f76 /src/oauth2.rs | |
parent | 0167dce98692f707b74395977c478c2ca44fa0c7 (diff) | |
parent | 4b50e1cb0945adbbcc07dfcb65a9252e7523105d (diff) | |
download | rvi_sota_client-8e9d234dcfe03a24409829ddd31b51bd8f840345.tar.gz |
Merge latest stable advancedtelematic
Diffstat (limited to 'src/oauth2.rs')
-rw-r--r-- | src/oauth2.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/oauth2.rs b/src/oauth2.rs index 0c5f152..e34e4c2 100644 --- a/src/oauth2.rs +++ b/src/oauth2.rs @@ -1,16 +1,19 @@ use rustc_serialize::json; use datatype::{AccessToken, Error, Url}; -use http::Client; +use http::{Client, Response}; /// Authenticate with the specified OAuth2 server to retrieve a new `AccessToken`. pub fn authenticate(server: Url, client: &Client) -> Result<AccessToken, Error> { debug!("authenticating at {}", server); - let resp_rx = client.post(server, None); + let resp_rx = client.post(server, Some(br#"grant_type=client_credentials"#.to_vec())); let resp = resp_rx.recv().expect("no authenticate response received"); - let data = try!(resp); - let body = try!(String::from_utf8(data)); + let body = match resp { + Response::Success(data) => try!(String::from_utf8(data.body)), + Response::Failed(data) => return Err(Error::from(data)), + Response::Error(err) => return Err(err) + }; Ok(try!(json::decode(&body))) } |