summaryrefslogtreecommitdiff
path: root/src/oauth2.rs
diff options
context:
space:
mode:
authorArthur Taylor <codders@octomonkey.org.uk>2016-11-22 10:56:20 +0100
committerGitHub <noreply@github.com>2016-11-22 10:56:20 +0100
commit8e9d234dcfe03a24409829ddd31b51bd8f840345 (patch)
treed1d833d732faf4c8709e975a4bb6129acc3d0f76 /src/oauth2.rs
parent0167dce98692f707b74395977c478c2ca44fa0c7 (diff)
parent4b50e1cb0945adbbcc07dfcb65a9252e7523105d (diff)
downloadrvi_sota_client-8e9d234dcfe03a24409829ddd31b51bd8f840345.tar.gz
Merge pull request #9 from advancedtelematic/stableHEADmaster
Merge latest stable advancedtelematic
Diffstat (limited to 'src/oauth2.rs')
-rw-r--r--src/oauth2.rs11
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)))
}