Add Open Actions Dtos here ...
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using xCommons.Extensions;
|
||||
using xModels.Base;
|
||||
using xModels.Dtos;
|
||||
|
||||
namespace xIdentityModels.Dtos
|
||||
{
|
||||
public class XOpenActionDto
|
||||
{
|
||||
/// <summary>
|
||||
/// a List of Available Open Actions ...
|
||||
/// </summary>
|
||||
public struct XOpenActions
|
||||
{
|
||||
public const string HandShake = "HandShake";
|
||||
public const string GetUserInfo = "GetUserInfo";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Open Actions Request Model ...
|
||||
/// </summary>
|
||||
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; }
|
||||
|
||||
/// <summary>
|
||||
/// Validate Model ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool Validate()
|
||||
{
|
||||
//
|
||||
var result =
|
||||
!Device.IsNull() &&
|
||||
!Timestamp.IsNull() &&
|
||||
!Timestamp.IsExPired() &&
|
||||
!Action.IsNullOrEmpty() &&
|
||||
(Action == XOpenActions.HandShake ||
|
||||
Action == XOpenActions.GetUserInfo);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checksum Digest Model ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string ToOpenActionToken()
|
||||
{
|
||||
//
|
||||
var result = string.Empty;
|
||||
if (!Validate())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
var tmp = this;
|
||||
tmp.Checksum = string.Empty;
|
||||
|
||||
//
|
||||
result = $"{tmp.ToJSON()}"
|
||||
.ToMd5String();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate a Token is Correspond to Model or not ...
|
||||
/// </summary>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
public bool ValidateToken(string token)
|
||||
{
|
||||
//
|
||||
var result =
|
||||
Validate() &&
|
||||
!token.IsNullOrEmpty() &&
|
||||
token == ToOpenActionToken();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// aa Dto which used between Api's ...
|
||||
/// </summary>
|
||||
public class XOpenActionInnerDto : XBaseDto
|
||||
{
|
||||
public string Token { get; set; }
|
||||
public string Payload { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user