aboutsummaryrefslogtreecommitdiff
path: root/lockchain-http
diff options
context:
space:
mode:
Diffstat (limited to 'lockchain-http')
-rw-r--r--lockchain-http/src/handlers.rs51
-rw-r--r--lockchain-http/src/lib.rs8
-rw-r--r--lockchain-http/src/models/inputs.rs7
-rw-r--r--lockchain-http/src/models/responses.rs22
4 files changed, 39 insertions, 49 deletions
diff --git a/lockchain-http/src/handlers.rs b/lockchain-http/src/handlers.rs
index 369f888..2b220a2 100644
--- a/lockchain-http/src/handlers.rs
+++ b/lockchain-http/src/handlers.rs
@@ -174,43 +174,38 @@ where
}
/// PUT /authenticate
-pub fn authenticate<B, V>(_req: HttpRequestState<ApiState<B, V>>) -> impl Responder
-where
- B: Body,
- V: Vault<B>,
-{
- Json(OperationFailed {
- reason: "Not implemented".into(),
- code: 255,
- })
-}
-
-/// PUT /de-authenticate
-pub fn deauthenticate<B, V>(_req: HttpRequestState<ApiState<B, V>>) -> impl Responder
+pub fn authenticate<B, V>(
+ (item, req): (Json<Authenticate>, HttpRequestState<ApiState<B, V>>),
+) -> impl Responder
where
B: Body,
V: Vault<B>,
{
- Json(OperationFailed {
- reason: "Not implemented".into(),
- code: 255,
- })
-}
+ use lockchain::users::*;
+ let Authenticate { username, password } = item.into_inner();
-/// PUT /de-authenticate
-pub fn register<B, V>(_req: HttpRequestState<ApiState<B, V>>) -> impl Responder
-where
- B: Body,
- V: Vault<B>,
-{
- Json(OperationFailed {
- reason: "Not implemented".into(),
- code: 255,
+ Json(match pam_authenticate(&username, &password) {
+ Ok(()) => CarrierMessage {
+ error: Ok(()),
+ data: Some(TokenMessage {
+ username,
+ token: String::new(),
+ }),
+ },
+ Err(e) => CarrierMessage {
+ error: Err(e.into()),
+ data: Some(OperationFailed {
+ reason: "Meh!".into(),
+ code: 1,
+ }),
+ },
})
}
/// PUT /de-authenticate
-pub fn get_all_users<B, V>(_req: HttpRequestState<ApiState<B, V>>) -> impl Responder
+pub fn deauthenticate<B, V>(
+ (item, req): (Json<Deauthenticate>, HttpRequestState<ApiState<B, V>>),
+) -> impl Responder
where
B: Body,
V: Vault<B>,
diff --git a/lockchain-http/src/lib.rs b/lockchain-http/src/lib.rs
index 95d27d2..dfe1211 100644
--- a/lockchain-http/src/lib.rs
+++ b/lockchain-http/src/lib.rs
@@ -114,14 +114,6 @@ where
// Hand-in active auth token
r.method(http::Method::POST).with(handlers::deauthenticate)
})
- .resource("/users/register", |r| {
- // Register a new user (if allowed)
- r.method(http::Method::POST).with(handlers::register);
- })
- .resource("/users/", |r| {
- // Get all available users
- r.method(http::Method::GET).with(handlers::get_all_users);
- })
.resource("/api", |r| {
r.method(http::Method::GET).with(handlers::api_data);
}),
diff --git a/lockchain-http/src/models/inputs.rs b/lockchain-http/src/models/inputs.rs
index 172b204..4e1ae79 100644
--- a/lockchain-http/src/models/inputs.rs
+++ b/lockchain-http/src/models/inputs.rs
@@ -76,10 +76,3 @@ pub struct Authenticate {
pub struct Deauthenticate {
pub token: String,
}
-
-#[derive(Serialize, Deserialize)]
-pub struct Register {
- pub username: String,
- pub password: String,
- pub requested_role: Option<Role>,
-}
diff --git a/lockchain-http/src/models/responses.rs b/lockchain-http/src/models/responses.rs
index ac4e74b..436d3e6 100644
--- a/lockchain-http/src/models/responses.rs
+++ b/lockchain-http/src/models/responses.rs
@@ -1,7 +1,5 @@
-
-
-use lockchain::errors::Error as LockError;
use serde::{de::DeserializeOwned, Serialize};
+use std::error::Error;
/// A generic container that json/error wraps lockchain-types
///
@@ -9,8 +7,13 @@ use serde::{de::DeserializeOwned, Serialize};
/// to send both encrypted and cleartext data via the API endpoint, using
/// the same code.
#[derive(Serialize, Deserialize)]
-pub struct CarrierMessage<T: Serialize + DeserializeOwned> {
- pub error: Result<(), LockError>,
+pub struct CarrierMessage<T, E>
+where
+ T: Serialize + DeserializeOwned,
+ E: Error + Serialize + DeserializeOwned,
+{
+ #[serde(bound(deserialize = "E: Serialize + DeserializeOwned"))]
+ pub error: Result<(), E>,
#[serde(bound(deserialize = "T: Serialize + DeserializeOwned"))]
pub data: Option<T>,
}
@@ -22,6 +25,13 @@ pub struct OperationFailed {
pub code: u32,
}
+/// Message that returns a token
+#[derive(Serialize, Deserialize)]
+pub struct TokenMessage {
+ pub username: String,
+ pub token: String,
+}
+
/// **Returns** Api information
#[derive(Serialize, Deserialize)]
pub struct ApiInformation {
@@ -44,4 +54,4 @@ pub struct VaultCreateResponse {
pub name: String,
pub created: bool,
pub error: Option<String>,
-} \ No newline at end of file
+}