From fbfdfaf740e037015065b72b1ca92e4479eb4e9b Mon Sep 17 00:00:00 2001 From: RobDavenport Date: Thu, 1 Feb 2024 16:06:22 +0900 Subject: [PATCH] adjust login flow --- gamercade_interface/proto/auth.proto | 25 ++---- gamercade_interface/src/output/auth.rs | 120 +++---------------------- 2 files changed, 18 insertions(+), 127 deletions(-) diff --git a/gamercade_interface/proto/auth.proto b/gamercade_interface/proto/auth.proto index 9f1522d8..26f7264f 100644 --- a/gamercade_interface/proto/auth.proto +++ b/gamercade_interface/proto/auth.proto @@ -5,11 +5,9 @@ import "common.proto"; package auth; service AuthService { - rpc SignUp(SignUpRequest) returns (common.Empty); - rpc Login(LoginRequest) returns (LoginResponse); - rpc RefreshToken(RefreshTokenRequest) returns (RefreshTokenResponse); + rpc SignUp(SignUpRequest) returns (SessionResponse); + rpc Login(LoginRequest) returns (SessionResponse); rpc UpdatePassword(UpdatePasswordRequest) returns (common.Empty); - // TODO: handle refresh tokens? } message SignUpRequest { @@ -26,22 +24,11 @@ message LoginRequest { }; } -message LoginResponse { - string access_token = 1; - string refresh_token = 2; - uint64 expires_at = 3; -} - -message RefreshTokenRequest { - string refresh_token = 1; -} - -message RefreshTokenResponse { - string access_token = 1; - string refresh_token = 2; - uint64 expires_at = 3; +message SessionResponse { + string session = 1; } message UpdatePasswordRequest { - string new_password = 1; + string previous_password = 1; + string new_password = 2; } \ No newline at end of file diff --git a/gamercade_interface/src/output/auth.rs b/gamercade_interface/src/output/auth.rs index 9940460f..8721c797 100644 --- a/gamercade_interface/src/output/auth.rs +++ b/gamercade_interface/src/output/auth.rs @@ -29,34 +29,16 @@ pub mod login_request { } #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] -pub struct LoginResponse { +pub struct SessionResponse { #[prost(string, tag = "1")] - pub access_token: ::prost::alloc::string::String, - #[prost(string, tag = "2")] - pub refresh_token: ::prost::alloc::string::String, - #[prost(uint64, tag = "3")] - pub expires_at: u64, -} -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct RefreshTokenRequest { - #[prost(string, tag = "1")] - pub refresh_token: ::prost::alloc::string::String, -} -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct RefreshTokenResponse { - #[prost(string, tag = "1")] - pub access_token: ::prost::alloc::string::String, - #[prost(string, tag = "2")] - pub refresh_token: ::prost::alloc::string::String, - #[prost(uint64, tag = "3")] - pub expires_at: u64, + pub session: ::prost::alloc::string::String, } #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct UpdatePasswordRequest { #[prost(string, tag = "1")] + pub previous_password: ::prost::alloc::string::String, + #[prost(string, tag = "2")] pub new_password: ::prost::alloc::string::String, } /// Generated client implementations. @@ -148,7 +130,7 @@ pub mod auth_service_client { &mut self, request: impl tonic::IntoRequest, ) -> std::result::Result< - tonic::Response, + tonic::Response, tonic::Status, > { self.inner @@ -169,27 +151,8 @@ pub mod auth_service_client { pub async fn login( &mut self, request: impl tonic::IntoRequest, - ) -> std::result::Result, tonic::Status> { - self.inner - .ready() - .await - .map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; - let codec = tonic::codec::ProstCodec::default(); - let path = http::uri::PathAndQuery::from_static("/auth.AuthService/Login"); - let mut req = request.into_request(); - req.extensions_mut().insert(GrpcMethod::new("auth.AuthService", "Login")); - self.inner.unary(req, path, codec).await - } - pub async fn refresh_token( - &mut self, - request: impl tonic::IntoRequest, ) -> std::result::Result< - tonic::Response, + tonic::Response, tonic::Status, > { self.inner @@ -202,12 +165,9 @@ pub mod auth_service_client { ) })?; let codec = tonic::codec::ProstCodec::default(); - let path = http::uri::PathAndQuery::from_static( - "/auth.AuthService/RefreshToken", - ); + let path = http::uri::PathAndQuery::from_static("/auth.AuthService/Login"); let mut req = request.into_request(); - req.extensions_mut() - .insert(GrpcMethod::new("auth.AuthService", "RefreshToken")); + req.extensions_mut().insert(GrpcMethod::new("auth.AuthService", "Login")); self.inner.unary(req, path, codec).await } pub async fn update_password( @@ -247,21 +207,11 @@ pub mod auth_service_server { async fn sign_up( &self, request: tonic::Request, - ) -> std::result::Result< - tonic::Response, - tonic::Status, - >; + ) -> std::result::Result, tonic::Status>; async fn login( &self, request: tonic::Request, - ) -> std::result::Result, tonic::Status>; - async fn refresh_token( - &self, - request: tonic::Request, - ) -> std::result::Result< - tonic::Response, - tonic::Status, - >; + ) -> std::result::Result, tonic::Status>; async fn update_password( &self, request: tonic::Request, @@ -356,7 +306,7 @@ pub mod auth_service_server { T: AuthService, > tonic::server::UnaryService for SignUpSvc { - type Response = super::super::common::Empty; + type Response = super::SessionResponse; type Future = BoxFuture< tonic::Response, tonic::Status, @@ -400,7 +350,7 @@ pub mod auth_service_server { struct LoginSvc(pub Arc); impl tonic::server::UnaryService for LoginSvc { - type Response = super::LoginResponse; + type Response = super::SessionResponse; type Future = BoxFuture< tonic::Response, tonic::Status, @@ -439,52 +389,6 @@ pub mod auth_service_server { }; Box::pin(fut) } - "/auth.AuthService/RefreshToken" => { - #[allow(non_camel_case_types)] - struct RefreshTokenSvc(pub Arc); - impl< - T: AuthService, - > tonic::server::UnaryService - for RefreshTokenSvc { - type Response = super::RefreshTokenResponse; - type Future = BoxFuture< - tonic::Response, - tonic::Status, - >; - fn call( - &mut self, - request: tonic::Request, - ) -> Self::Future { - let inner = Arc::clone(&self.0); - let fut = async move { - ::refresh_token(&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 inner = inner.0; - let method = RefreshTokenSvc(inner); - let codec = tonic::codec::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) - } "/auth.AuthService/UpdatePassword" => { #[allow(non_camel_case_types)] struct UpdatePasswordSvc(pub Arc);