110 lines
2.8 KiB
C#
110 lines
2.8 KiB
C#
using System;
|
|
using xCommons.Extensions;
|
|
using xModels.Base;
|
|
using xModels.Dtos;
|
|
|
|
namespace xIdentityModels.Dtos
|
|
{
|
|
/// <summary>
|
|
/// a List of Available Open Actions ...
|
|
/// </summary>
|
|
public struct XOpenActions
|
|
{
|
|
public const string HandShake = "HandShake";
|
|
public const string GetUserInfo = "GetUserInfo";
|
|
public const string GetUserInfos = "GetUserInfos";
|
|
}
|
|
|
|
/// <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 string Timestamp { get; set; }
|
|
|
|
/// <summary>
|
|
/// Validate Model ...
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool Validate()
|
|
{
|
|
//
|
|
var result =
|
|
!Device.IsNull() &&
|
|
!Timestamp.IsNull() &&
|
|
!Action.IsNullOrEmpty() &&
|
|
(Action == XOpenActions.HandShake ||
|
|
Action == XOpenActions.GetUserInfo ||
|
|
Action == XOpenActions.GetUserInfos) &&
|
|
!Int64.Parse(Timestamp).FromTimestamp().IsExPired();
|
|
|
|
//
|
|
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; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// User Info Providing in Open Actions ...
|
|
/// </summary>
|
|
public class XOpenActionUserInfoDto : XBaseDto
|
|
{
|
|
public string Username { get; set; }
|
|
public string Firstname { get; set; }
|
|
public string Lastname { get; set; }
|
|
public string Avatar { get; set; }
|
|
}
|
|
} |