pws reset

This commit is contained in:
Priec
2026-08-11 08:40:49 +02:00
parent 8ddabf78f6
commit 71106a04cb
20 changed files with 323 additions and 136 deletions

View File

@@ -7,8 +7,8 @@ import "common.proto";
service AuthService {
rpc Register(RegisterRequest) returns (AuthResponse);
rpc Login(LoginRequest) returns (LoginResponse);
// Claims a bootstrap account that has never had a password set.
rpc SetInitialPassword(SetInitialPasswordRequest) returns (AuthResponse);
// Changes the authenticated user's password after verifying the current one.
rpc ChangePassword(ChangePasswordRequest) returns (PasswordOperationResponse);
rpc GetAuthorization(GetAuthorizationRequest) returns (AuthorizationSnapshot);
rpc SetTimezone(SetTimezoneRequest) returns (UserPreferences);
@@ -26,6 +26,8 @@ service AuthService {
// User administration.
rpc AssignUserRole(AssignUserRoleRequest) returns (UserSummary);
// Resets a lower-ranked user's password.
rpc ResetUserPassword(ResetUserPasswordRequest) returns (PasswordOperationResponse);
rpc ListUsers(ListUsersRequest) returns (ListUsersResponse);
}
@@ -45,12 +47,14 @@ message AuthResponse {
string role = 4; // Always 'guest' for a self-registration
}
message SetInitialPasswordRequest {
string username = 1;
string password = 2;
string password_confirmation = 3;
message ChangePasswordRequest {
string current_password = 1;
string new_password = 2;
string new_password_confirmation = 3;
}
message PasswordOperationResponse {}
message LoginRequest {
string identifier = 1; // Can be username or email
string password = 2;
@@ -175,6 +179,12 @@ message AssignUserRoleRequest {
string role = 2;
}
message ResetUserPasswordRequest {
string username = 1;
string new_password = 2;
string new_password_confirmation = 3;
}
message UserSummary {
string id = 1;
string username = 2;

Binary file not shown.

View File

@@ -32,14 +32,16 @@ pub struct AuthResponse {
pub role: ::prost::alloc::string::String,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct SetInitialPasswordRequest {
pub struct ChangePasswordRequest {
#[prost(string, tag = "1")]
pub username: ::prost::alloc::string::String,
pub current_password: ::prost::alloc::string::String,
#[prost(string, tag = "2")]
pub password: ::prost::alloc::string::String,
pub new_password: ::prost::alloc::string::String,
#[prost(string, tag = "3")]
pub password_confirmation: ::prost::alloc::string::String,
pub new_password_confirmation: ::prost::alloc::string::String,
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct PasswordOperationResponse {}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct LoginRequest {
/// Can be username or email
@@ -216,6 +218,15 @@ pub struct AssignUserRoleRequest {
pub role: ::prost::alloc::string::String,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct ResetUserPasswordRequest {
#[prost(string, tag = "1")]
pub username: ::prost::alloc::string::String,
#[prost(string, tag = "2")]
pub new_password: ::prost::alloc::string::String,
#[prost(string, tag = "3")]
pub new_password_confirmation: ::prost::alloc::string::String,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct UserSummary {
#[prost(string, tag = "1")]
pub id: ::prost::alloc::string::String,
@@ -366,11 +377,14 @@ pub mod auth_service_client {
.insert(GrpcMethod::new("komp_ac.auth.AuthService", "Login"));
self.inner.unary(req, path, codec).await
}
/// Claims a bootstrap account that has never had a password set.
pub async fn set_initial_password(
/// Changes the authenticated user's password after verifying the current one.
pub async fn change_password(
&mut self,
request: impl tonic::IntoRequest<super::SetInitialPasswordRequest>,
) -> std::result::Result<tonic::Response<super::AuthResponse>, tonic::Status> {
request: impl tonic::IntoRequest<super::ChangePasswordRequest>,
) -> std::result::Result<
tonic::Response<super::PasswordOperationResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
@@ -381,13 +395,11 @@ pub mod auth_service_client {
})?;
let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/komp_ac.auth.AuthService/SetInitialPassword",
"/komp_ac.auth.AuthService/ChangePassword",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new("komp_ac.auth.AuthService", "SetInitialPassword"),
);
.insert(GrpcMethod::new("komp_ac.auth.AuthService", "ChangePassword"));
self.inner.unary(req, path, codec).await
}
pub async fn get_authorization(
@@ -629,6 +641,33 @@ pub mod auth_service_client {
.insert(GrpcMethod::new("komp_ac.auth.AuthService", "AssignUserRole"));
self.inner.unary(req, path, codec).await
}
/// Resets a lower-ranked user's password.
pub async fn reset_user_password(
&mut self,
request: impl tonic::IntoRequest<super::ResetUserPasswordRequest>,
) -> std::result::Result<
tonic::Response<super::PasswordOperationResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/komp_ac.auth.AuthService/ResetUserPassword",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new("komp_ac.auth.AuthService", "ResetUserPassword"),
);
self.inner.unary(req, path, codec).await
}
pub async fn list_users(
&mut self,
request: impl tonic::IntoRequest<super::ListUsersRequest>,
@@ -676,11 +715,14 @@ pub mod auth_service_server {
&self,
request: tonic::Request<super::LoginRequest>,
) -> std::result::Result<tonic::Response<super::LoginResponse>, tonic::Status>;
/// Claims a bootstrap account that has never had a password set.
async fn set_initial_password(
/// Changes the authenticated user's password after verifying the current one.
async fn change_password(
&self,
request: tonic::Request<super::SetInitialPasswordRequest>,
) -> std::result::Result<tonic::Response<super::AuthResponse>, tonic::Status>;
request: tonic::Request<super::ChangePasswordRequest>,
) -> std::result::Result<
tonic::Response<super::PasswordOperationResponse>,
tonic::Status,
>;
async fn get_authorization(
&self,
request: tonic::Request<super::GetAuthorizationRequest>,
@@ -734,6 +776,14 @@ pub mod auth_service_server {
&self,
request: tonic::Request<super::AssignUserRoleRequest>,
) -> std::result::Result<tonic::Response<super::UserSummary>, tonic::Status>;
/// Resets a lower-ranked user's password.
async fn reset_user_password(
&self,
request: tonic::Request<super::ResetUserPasswordRequest>,
) -> std::result::Result<
tonic::Response<super::PasswordOperationResponse>,
tonic::Status,
>;
async fn list_users(
&self,
request: tonic::Request<super::ListUsersRequest>,
@@ -906,26 +956,25 @@ pub mod auth_service_server {
};
Box::pin(fut)
}
"/komp_ac.auth.AuthService/SetInitialPassword" => {
"/komp_ac.auth.AuthService/ChangePassword" => {
#[allow(non_camel_case_types)]
struct SetInitialPasswordSvc<T: AuthService>(pub Arc<T>);
struct ChangePasswordSvc<T: AuthService>(pub Arc<T>);
impl<
T: AuthService,
> tonic::server::UnaryService<super::SetInitialPasswordRequest>
for SetInitialPasswordSvc<T> {
type Response = super::AuthResponse;
> tonic::server::UnaryService<super::ChangePasswordRequest>
for ChangePasswordSvc<T> {
type Response = super::PasswordOperationResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::SetInitialPasswordRequest>,
request: tonic::Request<super::ChangePasswordRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as AuthService>::set_initial_password(&inner, request)
.await
<T as AuthService>::change_password(&inner, request).await
};
Box::pin(fut)
}
@@ -936,7 +985,7 @@ pub mod auth_service_server {
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let method = SetInitialPasswordSvc(inner);
let method = ChangePasswordSvc(inner);
let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
@@ -1404,6 +1453,52 @@ pub mod auth_service_server {
};
Box::pin(fut)
}
"/komp_ac.auth.AuthService/ResetUserPassword" => {
#[allow(non_camel_case_types)]
struct ResetUserPasswordSvc<T: AuthService>(pub Arc<T>);
impl<
T: AuthService,
> tonic::server::UnaryService<super::ResetUserPasswordRequest>
for ResetUserPasswordSvc<T> {
type Response = super::PasswordOperationResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::ResetUserPasswordRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as AuthService>::reset_user_password(&inner, request)
.await
};
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let method = ResetUserPasswordSvc(inner);
let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.unary(method, req).await;
Ok(res)
};
Box::pin(fut)
}
"/komp_ac.auth.AuthService/ListUsers" => {
#[allow(non_camel_case_types)]
struct ListUsersSvc<T: AuthService>(pub Arc<T>);