use crate::{ protobufs::{ custom::CAuthentication_BeginAuthSessionViaCredentials_Request_BinaryGuardData, steammessages_auth_steamclient::*, }, token::Jwt, transport::Transport, }; const SERVICE_NAME: &str = "IAuthenticationService"; use super::{ApiRequest, ApiResponse, BuildableRequest}; #[derive(Debug)] pub struct AuthenticationClient where T: Transport, { transport: T, } impl AuthenticationClient where T: Transport, { #[must_use] pub fn new(transport: T) -> Self { Self { transport } } pub fn begin_auth_session_via_credentials( &mut self, req: CAuthentication_BeginAuthSessionViaCredentials_Request_BinaryGuardData, ) -> anyhow::Result> { let req = ApiRequest::new(SERVICE_NAME, "BeginAuthSessionViaCredentials", 1u32, req); let resp = self.transport.send_request::< CAuthentication_BeginAuthSessionViaCredentials_Request_BinaryGuardData, CAuthentication_BeginAuthSessionViaCredentials_Response>(req)?; Ok(resp) } pub fn begin_auth_session_via_qr( &mut self, req: CAuthentication_BeginAuthSessionViaQR_Request, ) -> anyhow::Result> { let req = ApiRequest::new(SERVICE_NAME, "BeginAuthSessionViaQR", 1u32, req); let resp = self .transport .send_request::( req, )?; Ok(resp) } pub fn generate_access_token( &mut self, req: CAuthentication_AccessToken_GenerateForApp_Request, access_token: &Jwt, ) -> anyhow::Result> { let req = ApiRequest::new(SERVICE_NAME, "GenerateAccessTokenForApp", 1u32, req) .with_access_token(access_token); let resp = self .transport .send_request::( req, )?; Ok(resp) } pub fn fetch_rsa_key( &mut self, account_name: String, ) -> anyhow::Result> { let mut inner = CAuthentication_GetPasswordRSAPublicKey_Request::new(); inner.set_account_name(account_name); let req = ApiRequest::new(SERVICE_NAME, "GetPasswordRSAPublicKey", 1u32, inner); let resp = self .transport .send_request::( req, )?; Ok(resp) } pub fn migrate_mobile_session( &mut self, req: CAuthentication_MigrateMobileSession_Request, ) -> anyhow::Result> { let req = ApiRequest::new(SERVICE_NAME, "MigrateMobileSession", 1u32, req); let resp = self .transport .send_request::( req, )?; Ok(resp) } pub fn poll_auth_session( &mut self, req: CAuthentication_PollAuthSessionStatus_Request, ) -> anyhow::Result> { let req = ApiRequest::new(SERVICE_NAME, "PollAuthSessionStatus", 1u32, req); let resp = self .transport .send_request::( req, )?; Ok(resp) } pub fn revoke_refresh_token( &mut self, req: CAuthentication_RefreshToken_Revoke_Request, ) -> anyhow::Result> { let req = ApiRequest::new(SERVICE_NAME, "RevokeRefreshToken", 1u32, req); let resp = self .transport .send_request::( req, )?; Ok(resp) } pub fn revoke_access_token( &mut self, req: CAuthenticationSupport_RevokeToken_Request, ) -> anyhow::Result> { let req = ApiRequest::new(SERVICE_NAME, "RevokeToken", 1u32, req); let resp = self .transport .send_request::( req, )?; Ok(resp) } pub fn update_session_with_mobile_confirmation( &mut self, req: CAuthentication_UpdateAuthSessionWithMobileConfirmation_Request, ) -> anyhow::Result> { let req = ApiRequest::new( SERVICE_NAME, "UpdateAuthSessionWithMobileConfirmation", 1u32, req, ); let resp = self .transport .send_request::( req, )?; Ok(resp) } pub fn update_session_with_steam_guard_code( &mut self, req: CAuthentication_UpdateAuthSessionWithSteamGuardCode_Request, ) -> anyhow::Result> { let req = ApiRequest::new( SERVICE_NAME, "UpdateAuthSessionWithSteamGuardCode", 1u32, req, ); let resp = self .transport .send_request::( req, )?; Ok(resp) } } macro_rules! impl_buildable_req { ($type:ty, $needs_auth:literal) => { impl BuildableRequest for $type { fn method() -> reqwest::Method { reqwest::Method::POST } fn requires_access_token() -> bool { $needs_auth } } }; } impl_buildable_req!( CAuthentication_BeginAuthSessionViaCredentials_Request, false ); impl_buildable_req!( CAuthentication_BeginAuthSessionViaCredentials_Request_BinaryGuardData, false ); impl_buildable_req!(CAuthentication_BeginAuthSessionViaQR_Request, false); impl_buildable_req!(CAuthentication_AccessToken_GenerateForApp_Request, true); impl BuildableRequest for CAuthentication_GetPasswordRSAPublicKey_Request { fn method() -> reqwest::Method { reqwest::Method::GET } fn requires_access_token() -> bool { false } } impl_buildable_req!(CAuthentication_GetAuthSessionInfo_Request, true); impl_buildable_req!(CAuthentication_MigrateMobileSession_Request, false); impl_buildable_req!(CAuthentication_PollAuthSessionStatus_Request, false); impl_buildable_req!(CAuthentication_RefreshToken_Revoke_Request, true); impl_buildable_req!(CAuthenticationSupport_RevokeToken_Request, true); impl_buildable_req!( CAuthentication_UpdateAuthSessionWithMobileConfirmation_Request, false ); impl_buildable_req!( CAuthentication_UpdateAuthSessionWithSteamGuardCode_Request, false ); impl EAuthSessionGuardType { pub fn requires_prompt(self) -> bool { match self { EAuthSessionGuardType::k_EAuthSessionGuardType_DeviceCode => true, EAuthSessionGuardType::k_EAuthSessionGuardType_EmailCode => true, EAuthSessionGuardType::k_EAuthSessionGuardType_DeviceConfirmation => false, EAuthSessionGuardType::k_EAuthSessionGuardType_EmailConfirmation => false, _ => false, } } }