Skip to content

Commit

Permalink
adjust login flow
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDavenport committed Feb 1, 2024
1 parent 0ddddc0 commit fbfdfaf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 127 deletions.
25 changes: 6 additions & 19 deletions gamercade_interface/proto/auth.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
120 changes: 12 additions & 108 deletions gamercade_interface/src/output/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -148,7 +130,7 @@ pub mod auth_service_client {
&mut self,
request: impl tonic::IntoRequest<super::SignUpRequest>,
) -> std::result::Result<
tonic::Response<super::super::common::Empty>,
tonic::Response<super::SessionResponse>,
tonic::Status,
> {
self.inner
Expand All @@ -169,27 +151,8 @@ pub mod auth_service_client {
pub async fn login(
&mut self,
request: impl tonic::IntoRequest<super::LoginRequest>,
) -> std::result::Result<tonic::Response<super::LoginResponse>, 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<super::RefreshTokenRequest>,
) -> std::result::Result<
tonic::Response<super::RefreshTokenResponse>,
tonic::Response<super::SessionResponse>,
tonic::Status,
> {
self.inner
Expand All @@ -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(
Expand Down Expand Up @@ -247,21 +207,11 @@ pub mod auth_service_server {
async fn sign_up(
&self,
request: tonic::Request<super::SignUpRequest>,
) -> std::result::Result<
tonic::Response<super::super::common::Empty>,
tonic::Status,
>;
) -> std::result::Result<tonic::Response<super::SessionResponse>, tonic::Status>;
async fn login(
&self,
request: tonic::Request<super::LoginRequest>,
) -> std::result::Result<tonic::Response<super::LoginResponse>, tonic::Status>;
async fn refresh_token(
&self,
request: tonic::Request<super::RefreshTokenRequest>,
) -> std::result::Result<
tonic::Response<super::RefreshTokenResponse>,
tonic::Status,
>;
) -> std::result::Result<tonic::Response<super::SessionResponse>, tonic::Status>;
async fn update_password(
&self,
request: tonic::Request<super::UpdatePasswordRequest>,
Expand Down Expand Up @@ -356,7 +306,7 @@ pub mod auth_service_server {
T: AuthService,
> tonic::server::UnaryService<super::SignUpRequest>
for SignUpSvc<T> {
type Response = super::super::common::Empty;
type Response = super::SessionResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
Expand Down Expand Up @@ -400,7 +350,7 @@ pub mod auth_service_server {
struct LoginSvc<T: AuthService>(pub Arc<T>);
impl<T: AuthService> tonic::server::UnaryService<super::LoginRequest>
for LoginSvc<T> {
type Response = super::LoginResponse;
type Response = super::SessionResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
Expand Down Expand Up @@ -439,52 +389,6 @@ pub mod auth_service_server {
};
Box::pin(fut)
}
"/auth.AuthService/RefreshToken" => {
#[allow(non_camel_case_types)]
struct RefreshTokenSvc<T: AuthService>(pub Arc<T>);
impl<
T: AuthService,
> tonic::server::UnaryService<super::RefreshTokenRequest>
for RefreshTokenSvc<T> {
type Response = super::RefreshTokenResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::RefreshTokenRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as AuthService>::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<T: AuthService>(pub Arc<T>);
Expand Down

0 comments on commit fbfdfaf

Please sign in to comment.