From 8cbfa61766fbf1210881dc55c54245505a25af05 Mon Sep 17 00:00:00 2001 From: GoldenBIOS Date: Thu, 9 Apr 2026 14:22:47 +0200 Subject: [PATCH] Implement AuthService and ApiClient core logic --- Core/ApiClient.cs | 36 +++++++++ Core/ChateniumClient.cs | 6 +- Core/EnvironmentConfig.cs | 4 +- Core/HttpClientFactory.cs | 2 +- Core/WebSocketHandler.cs | 10 +-- Models/AuthModels.cs | 125 +++++++++++++++++++++++++++++ Models/BroadcastModels.cs | 9 +++ Models/CallServiceModels.cs | 9 +++ Models/ChatModels.cs | 24 ++++++ Models/CommonModels.cs | 32 ++++++++ Models/DMServiceModels.cs | 29 +++++++ Models/FileTransferModels.cs | 17 ++++ Models/FileUploadModels.cs | 20 +++++ Models/NetworkHttpsModels.cs | 5 ++ Models/NetworkModels.cs | 16 ++++ Models/PictureModels.cs | 21 +++++ Models/SessionManagerModels.cs | 4 + Models/SessionModels.cs | 12 +++ Models/TextChannelServiceModels.cs | 27 +++++++ Models/UserModels.cs | 11 +++ Models/WebSocketModels.cs | 20 +++++ Services/AuthMethods.cs | 77 ++++++++++++++++++ 22 files changed, 503 insertions(+), 13 deletions(-) create mode 100644 Core/ApiClient.cs create mode 100644 Models/AuthModels.cs create mode 100644 Models/BroadcastModels.cs create mode 100644 Models/CallServiceModels.cs create mode 100644 Models/ChatModels.cs create mode 100644 Models/CommonModels.cs create mode 100644 Models/DMServiceModels.cs create mode 100644 Models/FileTransferModels.cs create mode 100644 Models/FileUploadModels.cs create mode 100644 Models/NetworkHttpsModels.cs create mode 100644 Models/NetworkModels.cs create mode 100644 Models/PictureModels.cs create mode 100644 Models/SessionManagerModels.cs create mode 100644 Models/SessionModels.cs create mode 100644 Models/TextChannelServiceModels.cs create mode 100644 Models/UserModels.cs create mode 100644 Models/WebSocketModels.cs create mode 100644 Services/AuthMethods.cs diff --git a/Core/ApiClient.cs b/Core/ApiClient.cs new file mode 100644 index 0000000..7e19851 --- /dev/null +++ b/Core/ApiClient.cs @@ -0,0 +1,36 @@ +using Newtonsoft.Json; +using System; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace Chtn.CSharp.SDK.Core +{ + public class ApiClient + { + private readonly HttpClient _httpClient; + private readonly string _baseUrl; + + public ApiClient(string baseUrl) + { + _baseUrl = baseUrl.EndsWith("/") ? baseUrl : baseUrl + "/"; + _httpClient = new HttpClient(); + } + + public async Task PostAsync(string endpoint, TRequest data) + { + var json = JsonConvert.SerializeObject(data); + var content = new StringContent(json, Encoding.UTF8, "application/json"); + + var response = await _httpClient.PostAsync(_baseUrl + endpoint, content); + var responseJson = await response.Content.ReadAsStringAsync(); + + if (!response.IsSuccessStatusCode) + { + throw new Exception($"API Hiba ({response.StatusCode}): {responseJson}"); + } + + return JsonConvert.DeserializeObject(responseJson); + } + } +} \ No newline at end of file diff --git a/Core/ChateniumClient.cs b/Core/ChateniumClient.cs index 9d4d2c6..40eb914 100644 --- a/Core/ChateniumClient.cs +++ b/Core/ChateniumClient.cs @@ -1,8 +1,6 @@ -using System; -using System.Globalization; -using System.Net.WebSockets; +using Chtn.CSharpSDK.Interfaces; +using System; using System.Threading.Tasks; -using Chtn.CSharpSDK.Interfaces; namespace Chtn.CSharpSDK.Core diff --git a/Core/EnvironmentConfig.cs b/Core/EnvironmentConfig.cs index 25bd23c..fd91e00 100644 --- a/Core/EnvironmentConfig.cs +++ b/Core/EnvironmentConfig.cs @@ -1,7 +1,7 @@ namespace Chtn.CSharp.SDK.Core { public class SDKConfig - { + { public string ApiUrl { get; set; } = "https://api.chatenium.hu"; public string CdnUrl { get; set; } = "https://cdn.chatenium.hu"; public string WsUrl { get; set; } = "wss://api.chatenium.hu"; @@ -10,6 +10,6 @@ public static class EnvironmentConfig { private static SDKConfig _currentConfig = new SDKConfig(); - public static SDKConfig Get() => _currentConfig; + public static SDKConfig Get() => _currentConfig; } } \ No newline at end of file diff --git a/Core/HttpClientFactory.cs b/Core/HttpClientFactory.cs index bcebd3b..3e009bd 100644 --- a/Core/HttpClientFactory.cs +++ b/Core/HttpClientFactory.cs @@ -3,7 +3,7 @@ using System.Net.Http; namespace Chtn.CSharp.SDK.Core { - public static class HttpClientFactory + public static class HttpClientFactory { public static HttpClient CreateClient(bool isCdn = false) { diff --git a/Core/WebSocketHandler.cs b/Core/WebSocketHandler.cs index e425405..cad5d92 100644 --- a/Core/WebSocketHandler.cs +++ b/Core/WebSocketHandler.cs @@ -1,14 +1,12 @@ -using System; -using System.Collections.Generic; +using Chtn.CSharp.SDK.Core; +using Newtonsoft.Json; +using System; using System.Net.Http; +using System.Net.Http.Headers; using System.Net.WebSockets; using System.Text; using System.Threading; using System.Threading.Tasks; -using Newtonsoft.Json; -using System.Net.Http.Headers; -using Chtn.CSharpSDK.Interfaces; -using Chtn.CSharp.SDK.Core; namespace Chtn.CSharpSDK.Core { diff --git a/Models/AuthModels.cs b/Models/AuthModels.cs new file mode 100644 index 0000000..9e86aee --- /dev/null +++ b/Models/AuthModels.cs @@ -0,0 +1,125 @@ +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace Chtn.CSharp.SDK.Models.Auth +{ + public class LoginPasswordAuthReq + { + [JsonProperty("unameMailPhone")] public string UnameMailPhone { get; set; } + [JsonProperty("password")] public string Password { get; set; } + [JsonProperty("os")] public string Os { get; set; } + [JsonProperty("language")] public string Language { get; set; } + } + + public class SignInSuccessResp + { + [JsonProperty("token")] public string Token { get; set; } + [JsonProperty("userid")] public string UserId { get; set; } + [JsonProperty("username")] public string Username { get; set; } + + } + + public class GetAuthMethods + { + [JsonProperty("identifier")] public string Identifier { get; set; } + } + + public class AuthMethods + { + [JsonProperty("methods")] public List Methods { get; set; } + } + + public class OtpPleSendCodeReq + { + [JsonProperty("identifier")] public List Identifier { get; set; } + } + + public class OtpPleVerifyCodeReq + { + [JsonProperty("identifier")] public string Identifier { get; set; } + [JsonProperty("code")] public string Code { get; set; } + } + + public class UnameUsageReq + { + [JsonProperty("username")] public string Username { get; set; } + } + + public class EmailUsageReq + { + [JsonProperty("email")] public string Email { get; set; } + } + + public class PleSendVCodeReq + { + [JsonProperty("email")] public string Email { get; set; } + } + + public class PleVerifyVCodeReq + { + [JsonProperty("email")] public string Email { get; set; } + [JsonProperty("code")] public string Code { get; set; } + } + + public class PleVerifyCodeResp + { + [JsonProperty("verifyOk")] public string VerifyOk { get; set; } + [JsonProperty("tempToken")] public string TempToken { get; set; } + } + + public class FinishPleAccountReq + { + [JsonProperty("temptoken")] public string TempToken { get; set; } + [JsonProperty("username")] public string Username { get; set; } + [JsonProperty("password")] public string Password { get; set; } + } + + public class LoginWithGoogleReq + { + [JsonProperty("idToken")] public string IdToken { get; set; } + } + public class LoginWithAppleReq + { + [JsonProperty("idToken")] public string IdToken { get; set; } + [JsonProperty("firstName")] public string FirstName { get; set; } + [JsonProperty("lastName")] public string LastName { get; set; } + } + public class CheckloginReq + { + [JsonProperty("token")] public string Token { get; set; } + } + public class RegisterReq + { + [JsonProperty("username")] public string Username { get; set; } + [JsonProperty("email")] public string Email { get; set; } + [JsonProperty("password")] public string Password { get; set; } + } + public class ResetPasswordReq + { + [JsonProperty("identifier")] public string Identifier { get; set; } + } + public class ResetPasswordResp + { + [JsonProperty("success")] public string Success { get; set; } + } + public class VerifyPasswordResetReq + { + [JsonProperty("identifier")] public string Identifier { get; set; } + [JsonProperty("code")] public string Code { get; set; } + [JsonProperty("newPassword")] public string NewPassword { get; set; } + } + public class UserDataValidationResp + { + [JsonProperty("available")] public string Available { get; set; } + } + public class GetAuthMethodsReq + { + public string Identifier { get; set; } + } + public class PleVerifyCodeReq + { + public string Email { get; set; } + public string Code { get; set; } + } + +} \ No newline at end of file diff --git a/Models/BroadcastModels.cs b/Models/BroadcastModels.cs new file mode 100644 index 0000000..2bfa894 --- /dev/null +++ b/Models/BroadcastModels.cs @@ -0,0 +1,9 @@ +namespace Chtn.CSharp.SDK.Models.Call +{ + public class StreamRegistry + { + public string StreamKey { get; set; } + public string Status { get; set; } + public string StreamUrl { get; set; } + } +} \ No newline at end of file diff --git a/Models/CallServiceModels.cs b/Models/CallServiceModels.cs new file mode 100644 index 0000000..824d12e --- /dev/null +++ b/Models/CallServiceModels.cs @@ -0,0 +1,9 @@ +namespace Chtn.CSharp.SDK.Models.Call +{ + public class InviteToCallReq + { + public string UserId { get; set; } + public string ChatId { get; set; } + public string TargetId { get; set; } + } +} \ No newline at end of file diff --git a/Models/ChatModels.cs b/Models/ChatModels.cs new file mode 100644 index 0000000..3d7196b --- /dev/null +++ b/Models/ChatModels.cs @@ -0,0 +1,24 @@ +using Chtn.CSharp.SDK.Models.Common; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace Chtn.CSharp.SDK.Models.Chat +{ + public class Chat + { + [JsonProperty("chatid")] public string ChatId { get; set; } + [JsonProperty("displayName")] public string DisplayName { get; set; } + [JsonProperty("latestMessage")] public LatestMessage Latest { get; set; } + } + + public class Message + { + [JsonProperty("msgid")] public string MsgId { get; set; } + [JsonProperty("author")] public string Author { get; set; } + [JsonProperty("message")] public string Content { get; set; } + [JsonProperty("sent_at")] public TimeStamp SentAt { get; set; } + [JsonProperty("files")] public List Files { get; set; } + } + + public class LatestMessage { public string Message { get; set; } public string MsgId { get; set; } } +} \ No newline at end of file diff --git a/Models/CommonModels.cs b/Models/CommonModels.cs new file mode 100644 index 0000000..f65bab9 --- /dev/null +++ b/Models/CommonModels.cs @@ -0,0 +1,32 @@ +using Newtonsoft.Json; + +namespace Chtn.CSharp.SDK.Models.Common +{ + public class RGB + { + public int R { get; set; } + public int G { get; set; } + public int B { get; set; } + } + + public class TimeStamp + { + [JsonProperty("T")] public long T { get; set; } + [JsonProperty("I")] public int I { get; set; } + } + public class PublicUserData + { + [JsonProperty("pfp")] public string Pfp { get; set; } + [JsonProperty("displayName")] public string DisplayName { get; set; } + [JsonProperty("username")] public string Username { get; set; } + [JsonProperty("userid")] public string UserId { get; set; } + } + + public class Attachment + { + public string FileId { get; set; } + public string FileName { get; set; } + public string Path { get; set; } + public string Type { get; set; } + } +} \ No newline at end of file diff --git a/Models/DMServiceModels.cs b/Models/DMServiceModels.cs new file mode 100644 index 0000000..776c23d --- /dev/null +++ b/Models/DMServiceModels.cs @@ -0,0 +1,29 @@ +using Chtn.CSharp.SDK.Models.Common; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace Chtn.CSharp.SDK.Models.Chat.DM +{ + public class DmMessage + { + [JsonProperty("msgid")] public string MsgId { get; set; } + [JsonProperty("author")] public string Author { get; set; } + [JsonProperty("message")] public string Content { get; set; } + [JsonProperty("sent_at")] public TimeStamp SentAt { get; set; } + [JsonProperty("files")] public List Files { get; set; } + } + + public class DmPinMessageReq + { + [JsonProperty("chatid")] public string ChatId { get; set; } + [JsonProperty("messageId")] public string MessageId { get; set; } + [JsonProperty("userid")] public string UserId { get; set; } + } + + public class DmJoinWsRoomReq + { + [JsonProperty("connId")] public string ConnId { get; set; } + [JsonProperty("chatid")] public string ChatId { get; set; } + [JsonProperty("userid")] public string UserId { get; set; } + } +} \ No newline at end of file diff --git a/Models/FileTransferModels.cs b/Models/FileTransferModels.cs new file mode 100644 index 0000000..4800ded --- /dev/null +++ b/Models/FileTransferModels.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace Chtn.CSharp.SDK.Models.Media +{ + public class StartNewFileTransferReq + { + public string UserId { get; set; } + public string TargetUserId { get; set; } + public List Metadata { get; set; } + } + public class TransferableFileMetadata + { + public string FileId { get; set; } + public string Name { get; set; } + public long Size { get; set; } + } +} \ No newline at end of file diff --git a/Models/FileUploadModels.cs b/Models/FileUploadModels.cs new file mode 100644 index 0000000..e838a6d --- /dev/null +++ b/Models/FileUploadModels.cs @@ -0,0 +1,20 @@ +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace Chtn.CSharp.SDK.Models.Media +{ + public class RegisterUploadReq + { + [JsonProperty("roomId")] public string RoomId { get; set; } + [JsonProperty("userid")] public string UserId { get; set; } + [JsonProperty("files")] public List Files { get; set; } + } + public class FileUploadRegistration + { + [JsonProperty("size")] public long Size { get; set; } + [JsonProperty("type")] public string Type { get; set; } + [JsonProperty("name")] public string Name { get; set; } + [JsonProperty("fileId")] public string FileId { get; set; } + } + public class RegisterUploadResp { public string UploadId { get; set; } } +} \ No newline at end of file diff --git a/Models/NetworkHttpsModels.cs b/Models/NetworkHttpsModels.cs new file mode 100644 index 0000000..14b5ca0 --- /dev/null +++ b/Models/NetworkHttpsModels.cs @@ -0,0 +1,5 @@ +namespace Chtn.CSharp.SDK.Models.Network +{ + public class GenericErrorBody { public string Error { get; set; } } + public class GenericSuccessBody { public string Response { get; set; } } +} \ No newline at end of file diff --git a/Models/NetworkModels.cs b/Models/NetworkModels.cs new file mode 100644 index 0000000..2d51f42 --- /dev/null +++ b/Models/NetworkModels.cs @@ -0,0 +1,16 @@ +namespace Chtn.CSharp.SDK.Models.Network +{ + public class CreateNetworkReq + { + public string Name { get; set; } + public string Visibility { get; set; } + public string UserId { get; set; } + } + + public class NetworkChannel + { + public string ChannelId { get; set; } + public string Name { get; set; } + public string Desc { get; set; } + } +} \ No newline at end of file diff --git a/Models/PictureModels.cs b/Models/PictureModels.cs new file mode 100644 index 0000000..c8798a2 --- /dev/null +++ b/Models/PictureModels.cs @@ -0,0 +1,21 @@ +using Chtn.CSharp.SDK.Models.Common; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace Chtn.CSharp.SDK.Models.Media +{ + public class Album + { + [JsonProperty("albumId")] public string ImageId { get; set; } + [JsonProperty("name")] public string Name { get; set; } + [JsonProperty("images")] public List Images { get; set; } + } + public class Image + { + [JsonProperty("imageId")] public string ImageId { get; set; } + [JsonProperty("path")] public string Path { get; set; } + [JsonProperty("title")] public string Title { get; set; } + [JsonProperty("uploaded_at")] public TimeStamp UploadedAt { get; set; } + + } +} \ No newline at end of file diff --git a/Models/SessionManagerModels.cs b/Models/SessionManagerModels.cs new file mode 100644 index 0000000..b40d812 --- /dev/null +++ b/Models/SessionManagerModels.cs @@ -0,0 +1,4 @@ +namespace Chtn.CSharp.SDK.Models.Session +{ + public class ValidateSessionReq { public string Token { get; set; } } +} \ No newline at end of file diff --git a/Models/SessionModels.cs b/Models/SessionModels.cs new file mode 100644 index 0000000..1d0fc20 --- /dev/null +++ b/Models/SessionModels.cs @@ -0,0 +1,12 @@ +using Chtn.CSharp.SDK.Models.User; +using Newtonsoft.Json; + +namespace Chtn.CSharp.SDK.Models.Session +{ + public class Session + { + [JsonProperty("userData")] public PersonalUserData UserData { get; set; } + [JsonProperty("token")] public string Token { get; set; } + } + public class ValidateSessionResp { public bool ValidationOk { get; set; } } +} \ No newline at end of file diff --git a/Models/TextChannelServiceModels.cs b/Models/TextChannelServiceModels.cs new file mode 100644 index 0000000..984f6cd --- /dev/null +++ b/Models/TextChannelServiceModels.cs @@ -0,0 +1,27 @@ +using Chtn.CSharp.SDK.Models.Common; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace Chtn.CSharp.SDK.Models.Chat.TextChannel +{ + public class ChannelMessage + { + [JsonProperty("msgid")] public string MsgId { get; set; } + [JsonProperty("author")] public PublicUserData Author { get; set; } + [JsonProperty("message")] public string Message { get; set; } + [JsonProperty("channelId")] public string ChannelId { get; set; } + [JsonProperty("files")] public List Files { get; set; } + } + + public class ChannelPinMessageReq + { + [JsonProperty("channelId")] public string ChannelId { get; set; } + [JsonProperty("messageId")] public string MessageId { get; set; } + } + + public class ChannelJoinWsRoomReq + { + [JsonProperty("connId")] public string ConnId { get; set; } + [JsonProperty("channelId")] public string ChannelId { get; set; } + } +} \ No newline at end of file diff --git a/Models/UserModels.cs b/Models/UserModels.cs new file mode 100644 index 0000000..e12b672 --- /dev/null +++ b/Models/UserModels.cs @@ -0,0 +1,11 @@ +using Newtonsoft.Json; + +namespace Chtn.CSharp.SDK.Models.User +{ + public class PersonalUserData + { + [JsonProperty("userid")] public string UserId { get; set; } + [JsonProperty("username")] public string Username { get; set; } + [JsonProperty("email")] public string Email { get; set; } + } +} \ No newline at end of file diff --git a/Models/WebSocketModels.cs b/Models/WebSocketModels.cs new file mode 100644 index 0000000..3710b1f --- /dev/null +++ b/Models/WebSocketModels.cs @@ -0,0 +1,20 @@ +using Newtonsoft.Json; + +namespace Chtn.CSharp.SDK.Models.Websocket +{ + public class WSMessagePayload + { + [JsonProperty("action")] public string Action { get; set; } + [JsonProperty("data")] public string Data { get; set; } + } + + public class WSMakeTokenReq + { + [JsonProperty("userid")] public string UserId { get; set; } + } + + public class WSMakeTokenResp + { + [JsonProperty("token")] public string Token { get; set; } + } +} \ No newline at end of file diff --git a/Services/AuthMethods.cs b/Services/AuthMethods.cs new file mode 100644 index 0000000..4e27e3d --- /dev/null +++ b/Services/AuthMethods.cs @@ -0,0 +1,77 @@ +using System; +using System.Threading.Tasks; +using Chtn.CSharp.SDK.Models.Auth; +using Chtn.CSharp.SDK.Core; + +namespace Chtn.CSharp.SDK.Services +{ + public interface IAuthService + { + Task GetAuthMethods(GetAuthMethodsReq req); + Task OtpSendCode(OtpPleSendCodeReq req); + Task OtpVerifyCode(OtpPleVerifyCodeReq req); + Task LoginPasswordAuth(LoginPasswordAuthReq req); + Task IsUsernameUsed(UnameUsageReq req); + Task IsEmailUsed(EmailUsageReq req); + Task PleSendVCode(PleSendVCodeReq req); + Task PleVerifyCode(PleVerifyCodeReq req); + Task FinishPLEAccount(FinishPleAccountReq req); + Task LoginWithGoogle(LoginWithGoogleReq req); + Task LoginWithApple(LoginWithAppleReq req); + Task Register(RegisterReq req); + Task ResetPassword(ResetPasswordReq req); + Task VerifyResetCode(VerifyPasswordResetReq req); + } + + public class AuthServiceProvider : IAuthService + { + private readonly ApiClient _apiClient; + + public AuthServiceProvider(ApiClient apiClient) + { + _apiClient = apiClient; + } + + public async Task GetAuthMethods(GetAuthMethodsReq req) => + await _apiClient.PostAsync("auth/get-auth-methods", req); + + public async Task OtpSendCode(OtpPleSendCodeReq req) => + await _apiClient.PostAsync("auth/otp-send-code", req); + + public async Task OtpVerifyCode(OtpPleVerifyCodeReq req) => + await _apiClient.PostAsync("auth/otp-verify-code", req); + + public async Task LoginPasswordAuth(LoginPasswordAuthReq req) => + await _apiClient.PostAsync("auth/login-password-auth", req); + + public async Task IsUsernameUsed(UnameUsageReq req) => + await _apiClient.PostAsync("auth/is-username-used", req); + + public async Task IsEmailUsed(EmailUsageReq req) => + await _apiClient.PostAsync("auth/is-email-used", req); + + public async Task PleSendVCode(PleSendVCodeReq req) => + await _apiClient.PostAsync("auth/ple-send-vcode", req); + + public async Task PleVerifyCode(PleVerifyCodeReq req) => + await _apiClient.PostAsync("auth/ple-verify-code", req); + + public async Task FinishPLEAccount(FinishPleAccountReq req) => + await _apiClient.PostAsync("auth/finish-ple-account", req); + + public async Task LoginWithGoogle(LoginWithGoogleReq req) => + await _apiClient.PostAsync("auth/login-with-google", req); + + public async Task LoginWithApple(LoginWithAppleReq req) => + await _apiClient.PostAsync("auth/login-with-apple", req); + + public async Task Register(RegisterReq req) => + await _apiClient.PostAsync("auth/register", req); + + public async Task ResetPassword(ResetPasswordReq req) => + await _apiClient.PostAsync("auth/reset-password", req); + + public async Task VerifyResetCode(VerifyPasswordResetReq req) => + await _apiClient.PostAsync("auth/verify-reset-code", req); + } +} \ No newline at end of file