rbac from the server used in the client from now on
This commit is contained in:
@@ -7,6 +7,7 @@ import "common.proto";
|
|||||||
service AuthService {
|
service AuthService {
|
||||||
rpc Register(RegisterRequest) returns (AuthResponse);
|
rpc Register(RegisterRequest) returns (AuthResponse);
|
||||||
rpc Login(LoginRequest) returns (LoginResponse);
|
rpc Login(LoginRequest) returns (LoginResponse);
|
||||||
|
rpc GetAuthorization(GetAuthorizationRequest) returns (AuthorizationSnapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
message RegisterRequest {
|
message RegisterRequest {
|
||||||
@@ -36,4 +37,17 @@ message LoginResponse {
|
|||||||
string user_id = 4; // User's UUID in string format
|
string user_id = 4; // User's UUID in string format
|
||||||
string role = 5; // User's role
|
string role = 5; // User's role
|
||||||
string username = 6;
|
string username = 6;
|
||||||
|
AuthorizationSnapshot authorization = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetAuthorizationRequest {}
|
||||||
|
|
||||||
|
message Permission {
|
||||||
|
string resource = 1;
|
||||||
|
string action = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message AuthorizationSnapshot {
|
||||||
|
string role = 1;
|
||||||
|
repeated Permission permissions = 2;
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -35,7 +35,7 @@ pub struct LoginRequest {
|
|||||||
#[prost(string, tag = "2")]
|
#[prost(string, tag = "2")]
|
||||||
pub password: ::prost::alloc::string::String,
|
pub password: ::prost::alloc::string::String,
|
||||||
}
|
}
|
||||||
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||||
pub struct LoginResponse {
|
pub struct LoginResponse {
|
||||||
/// JWT token
|
/// JWT token
|
||||||
#[prost(string, tag = "1")]
|
#[prost(string, tag = "1")]
|
||||||
@@ -54,6 +54,24 @@ pub struct LoginResponse {
|
|||||||
pub role: ::prost::alloc::string::String,
|
pub role: ::prost::alloc::string::String,
|
||||||
#[prost(string, tag = "6")]
|
#[prost(string, tag = "6")]
|
||||||
pub username: ::prost::alloc::string::String,
|
pub username: ::prost::alloc::string::String,
|
||||||
|
#[prost(message, optional, tag = "7")]
|
||||||
|
pub authorization: ::core::option::Option<AuthorizationSnapshot>,
|
||||||
|
}
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
|
||||||
|
pub struct GetAuthorizationRequest {}
|
||||||
|
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
|
||||||
|
pub struct Permission {
|
||||||
|
#[prost(string, tag = "1")]
|
||||||
|
pub resource: ::prost::alloc::string::String,
|
||||||
|
#[prost(string, tag = "2")]
|
||||||
|
pub action: ::prost::alloc::string::String,
|
||||||
|
}
|
||||||
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||||
|
pub struct AuthorizationSnapshot {
|
||||||
|
#[prost(string, tag = "1")]
|
||||||
|
pub role: ::prost::alloc::string::String,
|
||||||
|
#[prost(message, repeated, tag = "2")]
|
||||||
|
pub permissions: ::prost::alloc::vec::Vec<Permission>,
|
||||||
}
|
}
|
||||||
/// Generated client implementations.
|
/// Generated client implementations.
|
||||||
pub mod auth_service_client {
|
pub mod auth_service_client {
|
||||||
@@ -188,6 +206,30 @@ pub mod auth_service_client {
|
|||||||
.insert(GrpcMethod::new("komp_ac.auth.AuthService", "Login"));
|
.insert(GrpcMethod::new("komp_ac.auth.AuthService", "Login"));
|
||||||
self.inner.unary(req, path, codec).await
|
self.inner.unary(req, path, codec).await
|
||||||
}
|
}
|
||||||
|
pub async fn get_authorization(
|
||||||
|
&mut self,
|
||||||
|
request: impl tonic::IntoRequest<super::GetAuthorizationRequest>,
|
||||||
|
) -> std::result::Result<
|
||||||
|
tonic::Response<super::AuthorizationSnapshot>,
|
||||||
|
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/GetAuthorization",
|
||||||
|
);
|
||||||
|
let mut req = request.into_request();
|
||||||
|
req.extensions_mut()
|
||||||
|
.insert(GrpcMethod::new("komp_ac.auth.AuthService", "GetAuthorization"));
|
||||||
|
self.inner.unary(req, path, codec).await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Generated server implementations.
|
/// Generated server implementations.
|
||||||
@@ -211,6 +253,13 @@ pub mod auth_service_server {
|
|||||||
&self,
|
&self,
|
||||||
request: tonic::Request<super::LoginRequest>,
|
request: tonic::Request<super::LoginRequest>,
|
||||||
) -> std::result::Result<tonic::Response<super::LoginResponse>, tonic::Status>;
|
) -> std::result::Result<tonic::Response<super::LoginResponse>, tonic::Status>;
|
||||||
|
async fn get_authorization(
|
||||||
|
&self,
|
||||||
|
request: tonic::Request<super::GetAuthorizationRequest>,
|
||||||
|
) -> std::result::Result<
|
||||||
|
tonic::Response<super::AuthorizationSnapshot>,
|
||||||
|
tonic::Status,
|
||||||
|
>;
|
||||||
}
|
}
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct AuthServiceServer<T> {
|
pub struct AuthServiceServer<T> {
|
||||||
@@ -376,6 +425,51 @@ pub mod auth_service_server {
|
|||||||
};
|
};
|
||||||
Box::pin(fut)
|
Box::pin(fut)
|
||||||
}
|
}
|
||||||
|
"/komp_ac.auth.AuthService/GetAuthorization" => {
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
struct GetAuthorizationSvc<T: AuthService>(pub Arc<T>);
|
||||||
|
impl<
|
||||||
|
T: AuthService,
|
||||||
|
> tonic::server::UnaryService<super::GetAuthorizationRequest>
|
||||||
|
for GetAuthorizationSvc<T> {
|
||||||
|
type Response = super::AuthorizationSnapshot;
|
||||||
|
type Future = BoxFuture<
|
||||||
|
tonic::Response<Self::Response>,
|
||||||
|
tonic::Status,
|
||||||
|
>;
|
||||||
|
fn call(
|
||||||
|
&mut self,
|
||||||
|
request: tonic::Request<super::GetAuthorizationRequest>,
|
||||||
|
) -> Self::Future {
|
||||||
|
let inner = Arc::clone(&self.0);
|
||||||
|
let fut = async move {
|
||||||
|
<T as AuthService>::get_authorization(&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 = GetAuthorizationSvc(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)
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let mut response = http::Response::new(
|
let mut response = http::Response::new(
|
||||||
|
|||||||
Reference in New Issue
Block a user