Add /generate-user-server-key-2 prototype
This commit is contained in:
parent
f42c7109fb
commit
0a5ab5a199
1 changed files with 42 additions and 3 deletions
|
@ -9,14 +9,18 @@ use secrecy::ExposeSecret;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tracing::{event, instrument, Level};
|
use tracing::{event, instrument, Level};
|
||||||
|
|
||||||
use crate::auth::AuthenticationError;
|
use crate::auth::{AuthenticationError, UserServerKeyGenerator};
|
||||||
use crate::secrets::{Password, UserToken};
|
use crate::secrets::{Password, ServerHash, UserToken};
|
||||||
|
|
||||||
#[instrument]
|
#[instrument]
|
||||||
pub async fn run() -> color_eyre::Result<()> {
|
pub async fn run() -> color_eyre::Result<()> {
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/tls-check/success", get(|| async { "OK" }))
|
.route("/tls-check/success", get(|| async { "OK" }))
|
||||||
.route("/api-login", post(api_login));
|
.route("/api-login", post(api_login))
|
||||||
|
.route(
|
||||||
|
"/generate-user-server-key-2",
|
||||||
|
post(generate_user_server_key_2),
|
||||||
|
);
|
||||||
let listener = tokio::net::TcpListener::bind("[::]:8080").await?;
|
let listener = tokio::net::TcpListener::bind("[::]:8080").await?;
|
||||||
axum::serve(listener, app).await?;
|
axum::serve(listener, app).await?;
|
||||||
|
|
||||||
|
@ -79,3 +83,38 @@ async fn api_login(
|
||||||
token: user_token.0.expose_secret().to_owned(),
|
token: user_token.0.expose_secret().to_owned(),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
|
struct UserServerKeyRequest {
|
||||||
|
username: String,
|
||||||
|
token: UserToken,
|
||||||
|
server_hash: ServerHash,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
struct UserServerKeyResponse {
|
||||||
|
server_key: String,
|
||||||
|
server_key_timestamp: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[instrument]
|
||||||
|
async fn generate_user_server_key_2(
|
||||||
|
Query(ApiVersion { api_version }): Query<ApiVersion>,
|
||||||
|
Form(UserServerKeyRequest {
|
||||||
|
username,
|
||||||
|
token,
|
||||||
|
server_hash,
|
||||||
|
}): Form<UserServerKeyRequest>,
|
||||||
|
) -> ApiResult<Json<UserServerKeyResponse>> {
|
||||||
|
event!(Level::WARN, "Creating dummy user_server_key");
|
||||||
|
|
||||||
|
let generator: UserServerKeyGenerator = todo!();
|
||||||
|
let (server_key, server_key_timestamp) = generator
|
||||||
|
.generate_user_server_key(&username, &token, &server_hash)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(Json(UserServerKeyResponse {
|
||||||
|
server_key: server_key.0.expose_secret().to_owned(),
|
||||||
|
server_key_timestamp,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue