From 88b47a7d86426090506c3545e5e6f48667ec5ce5 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Thu, 17 Jul 2025 04:39:41 +0330 Subject: [PATCH] Add Open Actions Dtos here ... --- Dtos/XOpenActionDto.cs | 100 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 Dtos/XOpenActionDto.cs diff --git a/Dtos/XOpenActionDto.cs b/Dtos/XOpenActionDto.cs new file mode 100644 index 0000000..41f3b66 --- /dev/null +++ b/Dtos/XOpenActionDto.cs @@ -0,0 +1,100 @@ +using System; +using xCommons.Extensions; +using xModels.Base; +using xModels.Dtos; + +namespace xIdentityModels.Dtos +{ + public class XOpenActionDto + { + /// + /// a List of Available Open Actions ... + /// + public struct XOpenActions + { + public const string HandShake = "HandShake"; + public const string GetUserInfo = "GetUserInfo"; + } + + /// + /// Open Actions Request Model ... + /// + public class XOpenActionRequestDto : XBaseDto + { + // + public string Action { get; set; } + public string Payload { get; set; } + public string Checksum { get; set; } + public XDeviceDto Device { get; set; } + public DateTime Timestamp { get; set; } + + /// + /// Validate Model ... + /// + /// + public bool Validate() + { + // + var result = + !Device.IsNull() && + !Timestamp.IsNull() && + !Timestamp.IsExPired() && + !Action.IsNullOrEmpty() && + (Action == XOpenActions.HandShake || + Action == XOpenActions.GetUserInfo); + + // + return result; + } + + /// + /// Checksum Digest Model ... + /// + /// + public string ToOpenActionToken() + { + // + var result = string.Empty; + if (!Validate()) + { + return result; + } + + // + var tmp = this; + tmp.Checksum = string.Empty; + + // + result = $"{tmp.ToJSON()}" + .ToMd5String(); + return result; + } + + /// + /// Validate a Token is Correspond to Model or not ... + /// + /// + /// + public bool ValidateToken(string token) + { + // + var result = + Validate() && + !token.IsNullOrEmpty() && + token == ToOpenActionToken(); + + // + return result; + } + } + + /// + /// aa Dto which used between Api's ... + /// + public class XOpenActionInnerDto : XBaseDto + { + public string Token { get; set; } + public string Payload { get; set; } + } + } +} \ No newline at end of file