aboutsummaryrefslogtreecommitdiff
path: root/src/api/identity.rs
diff options
context:
space:
mode:
authorDaniel García <[email protected]>2018-10-10 20:40:39 +0200
committerDaniel García <[email protected]>2018-11-01 19:25:09 +0100
commitc67337010338db793fd0e1418d1235d4ecf65f2c (patch)
treeff21329804276c35d7d04ec54c1504068dc3b01c /src/api/identity.rs
parentf1b10006002414b861a2c8930ff3e60619a20059 (diff)
downloadvaultwarden-c67337010338db793fd0e1418d1235d4ecf65f2c.tar.gz
vaultwarden-c67337010338db793fd0e1418d1235d4ecf65f2c.zip
Updated bw_rs to Rocket version 0.4-rc1
Diffstat (limited to 'src/api/identity.rs')
-rw-r--r--src/api/identity.rs21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/api/identity.rs b/src/api/identity.rs
index 175c5afc..1493692d 100644
--- a/src/api/identity.rs
+++ b/src/api/identity.rs
@@ -4,7 +4,8 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use rocket::request::{self, Form, FormItems, FromForm, FromRequest, Request};
use rocket::{Outcome, Route};
-use rocket_contrib::{Json, Value};
+use rocket_contrib::json::Json;
+use serde_json::Value;
use num_traits::FromPrimitive;
@@ -21,9 +22,9 @@ pub fn routes() -> Vec<Route> {
routes![login]
}
-#[post("/connect/token", data = "<connect_data>")]
-fn login(connect_data: Form<ConnectData>, device_type: DeviceType, conn: DbConn, socket: Option<SocketAddr>) -> JsonResult {
- let data = connect_data.get();
+#[post("/connect/token", data = "<data>")]
+fn login(data: Form<ConnectData>, device_type: DeviceType, conn: DbConn, socket: Option<SocketAddr>) -> JsonResult {
+ let data: ConnectData = data.into_inner();
match data.grant_type {
GrantType::RefreshToken => _refresh_login(data, device_type, conn),
@@ -31,7 +32,7 @@ fn login(connect_data: Form<ConnectData>, device_type: DeviceType, conn: DbConn,
}
}
-fn _refresh_login(data: &ConnectData, _device_type: DeviceType, conn: DbConn) -> JsonResult {
+fn _refresh_login(data: ConnectData, _device_type: DeviceType, conn: DbConn) -> JsonResult {
// Extract token
let token = data.get("refresh_token");
@@ -59,7 +60,7 @@ fn _refresh_login(data: &ConnectData, _device_type: DeviceType, conn: DbConn) ->
}
}
-fn _password_login(data: &ConnectData, device_type: DeviceType, conn: DbConn, remote: Option<SocketAddr>) -> JsonResult {
+fn _password_login(data: ConnectData, device_type: DeviceType, conn: DbConn, remote: Option<SocketAddr>) -> JsonResult {
// Get the ip for error reporting
let ip = match remote {
Some(ip) => ip.ip(),
@@ -319,11 +320,9 @@ impl<'f> FromForm<'f> for ConnectData {
let mut data = HashMap::new();
// Insert data into map
- for (key, value) in items {
- match (key.url_decode(), value.url_decode()) {
- (Ok(key), Ok(value)) => data.insert(key.to_lowercase(), value),
- _ => return Err("Error decoding key or value".to_string()),
- };
+ for item in items {
+ let (key, value) = item.key_value_decoded();
+ data.insert(key.to_lowercase(), value);
}
// Validate needed values