Compare commits

..
3 Commits
Author SHA1 Message Date
saherelm 295bd12877 last ... 2026-10-05 22:30:42 +03:30
saherelm 4789d6b280 last ... 2026-10-05 17:36:42 +03:30
saherelm 80978abefc last ... 2026-10-04 22:02:30 +03:30
5 changed files with 342 additions and 33 deletions
+74
View File
@@ -0,0 +1,74 @@
using System;
using xModels.Base;
namespace xIdentityModels.Dtos
{
/// <summary>
/// an Specified Api Key ...
/// </summary>
public class XApiKeyDto : XBaseGuidIDEntityDto
{
/// <summary>
/// Related Application Id ...
/// </summary>
public int ApplicationId { get; set; }
/// <summary>
/// Hash ...
/// SHA256 of ApiKey ...
/// </summary>
public string KeyHash { get; set; }
/// <summary>
/// a Prefix ...
/// </summary>
public string KeyPrefix { get; set; }
/// <summary>
/// Expiration Type ...
/// </summary>
public DateTime ExpiresAt { get; set; }
/// <summary>
/// Cration Time ...
/// </summary>
public DateTime CreatedOn { get; set; }
/// <summary>
/// Last Usage Date ...
/// </summary>
public DateTime? LastUsedAt { get; set; }
/// <summary>
/// Revoked Time ...
/// </summary>
public DateTime? RevokedAt { get; set; }
/// <summary>
/// Revoker User Id ...
/// </summary>
public string RevokedBy { get; set; }
/// <summary>
/// a Json Array String ...
/// XApiKeyScope ...
/// </summary>
public string AllowedScopes { get; set; }
/// <summary>
/// a Comma-separated List which Specified White List IP ...
/// </summary>
public string AllowedIPs { get; set; }
/// <summary>
/// Rate Limit Per Minute ...
/// </summary>
public int RateLimitPerMinute { get; set; } = 60;
//
/// <summary>
/// Related Application ...
/// </summary>
public virtual XApplicationDto Application { get; set; }
}
}
+43
View File
@@ -0,0 +1,43 @@
using System;
using xModels.Base;
namespace xIdentityModels.Dtos
{
public class XApiKeyUsageDto : XBaseLongIDEntityDto
{
/// <summary>
/// Api Key Id ...
/// </summary>
public Guid ApiKeyId { get; set; }
/// <summary>
/// Called Endpoint ...
/// </summary>
public string Endpoint { get; set; }
/// <summary>
/// Called Http Method ...
/// </summary>
public string HttpMethod { get; set; }
/// <summary>
/// Client IP Address ...
/// </summary>
public string ClientIP { get; set; }
/// <summary>
/// Status Code ...
/// </summary>
public int StatusCode { get; set; }
/// <summary>
/// Request Time ...
/// </summary>
public DateTime RequestedOn { get; set; }
/// <summary>
/// Response Time in Milliseconds ...
/// </summary>
public long ResponseTimeMs { get; set; }
}
}
+49
View File
@@ -0,0 +1,49 @@
using System;
using xModels.Base;
using xModels.Dtos;
using xIdentityModels.Constants;
namespace xIdentityModels.Dtos
{
/// <summary>
/// an Application in xDashboard ...
/// </summary>
public class XApplicationDto : XBaseIntIDEntityDto
{
/// <summary>
/// Name ...
/// </summary>
public string Name { get; set; }
/// <summary>
/// Descriptor ...
/// </summary>
public string Description { get; set; }
/// <summary>
/// Owner Id ...
/// </summary>
public string OwnerId { get; set; }
public virtual XPersonDto Owner { get; set; }
/// <summary>
/// Application Type ...
/// </summary>
public XApplicationType Type { get; set; }
/// <summary>
/// Specified Application is Active or not ...
/// </summary>
public bool IsActive { get; set; } = true;
/// <summary>
/// Application Create Time ...
/// </summary>
public DateTime CreatedOn { get; set; }
/// <summary>
/// Application Update Type ...
/// </summary>
public DateTime UpdatedAt { get; set; }
}
}
+175 -31
View File
@@ -1,49 +1,84 @@
using System;
using xModels.Dtos;
using xCommons.Extensions;
using xIdentityModels.Dtos;
using xIdentityModels.Models;
using System.Collections.Generic;
using xIdentityModels.Descriptors;
using xIdentityModels.Navigations;
namespace xIdentityModels.Extensions {
public static class XModelExtensions {
namespace xIdentityModels.Extensions
{
public static class XModelExtensions
{
/// <summary>
/// /// Convert XIdentityUserDescriptor instance to XUser
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static XUser ToXUser (this XIdentityUserDescriptor source) {
return new XUser {
public static XUser ToXUser(this XIdentityUserDescriptor source)
{
return new XUser
{
Id = source.Id,
FirstName = source.FirstName,
LastName = source.LastName,
UserName = source.UserName,
Email = source.Email,
EmailConfirmed = source.EmailConfirmed,
PhoneNumber = source.PhoneNumber,
PhoneNumberConfirmed = source.PhoneNumberConfirmed,
IsEnable = true,
IsBanned = false,
CreationDate = DateTime.UtcNow,
DateOfBirth = DateTime.Parse (source.DateOfBirth)
FirstName = source.FirstName,
LastName = source.LastName,
UserName = source.UserName,
Email = source.Email,
EmailConfirmed = source.EmailConfirmed,
PhoneNumber = source.PhoneNumber,
PhoneNumberConfirmed = source.PhoneNumberConfirmed,
IsEnable = true,
IsBanned = false,
CreationDate = DateTime.UtcNow,
DateOfBirth = DateTime.Parse(source.DateOfBirth)
};
}
/// <summary>
/// Converts a User to Person ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static XPersonDto ToXPerson(this XUser source)
{
//
XPersonDto result = null;
//
if (!source.IsNullOrDefault())
{
//
result = new XPersonDto
{
Avatar = source.Avatar,
Username = source.UserName,
Lastname = source.LastName,
Firstname = source.FirstName,
};
}
//
return result;
}
/// <summary>
/// Check a User is Same as Descriptor User
/// </summary>
/// <param name="source"></param>
/// <param name="dest"></param>
/// <returns></returns>
public static bool IsSameAs (this XUser source, XIdentityUserDescriptor dest) {
public static bool IsSameAs(this XUser source, XIdentityUserDescriptor dest)
{
//
if (source.IsNull () ||
dest.IsNull ()) {
if (source.IsNull() ||
dest.IsNull())
{
return false;
}
//
var isSame = source.IsSameContent (dest, propertyWhiteList : new [] {
var isSame = source.IsSameContent(dest, propertyWhiteList: new[] {
nameof (XIdentityUserDescriptor.FirstName),
nameof (XIdentityUserDescriptor.LastName),
nameof (XIdentityUserDescriptor.UserName),
@@ -55,7 +90,7 @@ namespace xIdentityModels.Extensions {
nameof (XIdentityUserDescriptor.IsBanned),
nameof (XIdentityUserDescriptor.DateOfBirth)
},
propertyValueCheckers : new [] {
propertyValueCheckers: new[] {
new KeyValuePair<string, Func<XUser, XIdentityUserDescriptor, bool>> (
nameof (XIdentityUserDescriptor.DateOfBirth),
(user, descriptorUser) => {
@@ -76,18 +111,20 @@ namespace xIdentityModels.Extensions {
/// <param name="source"></param>
/// <param name="dest"></param>
/// <returns></returns>
public static bool IsSameAs (this XDevice source, XDevice dest) {
public static bool IsSameAs(this XDevice source, XDevice dest)
{
//
if (source.IsNull () ||
dest.IsNull ()) {
if (source.IsNull() ||
dest.IsNull())
{
return false;
}
//
var isSame = source.Os.ToNormalString () == dest.Os.ToNormalString () &&
source.OsVersion.ToNormalString () == dest.OsVersion.ToNormalString () &&
source.Browser.ToNormalString () == dest.Browser.ToNormalString () &&
source.UserAgent.ToNormalString () == dest.UserAgent.ToNormalString () &&
var isSame = source.Os.ToNormalString() == dest.Os.ToNormalString() &&
source.OsVersion.ToNormalString() == dest.OsVersion.ToNormalString() &&
source.Browser.ToNormalString() == dest.Browser.ToNormalString() &&
source.UserAgent.ToNormalString() == dest.UserAgent.ToNormalString() &&
source.DeviceType == dest.DeviceType;
//
@@ -99,15 +136,18 @@ namespace xIdentityModels.Extensions {
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static XTokenResponse ToXTokenResponse (this XUserClaimsInfoDto source) {
public static XTokenResponse ToXTokenResponse(this XUserClaimsInfoDto source)
{
//
if (source.IsNull () ||
(source.AccessToken.IsNullOrEmpty () && source.RefreshToken.IsNullOrEmpty ())) {
if (source.IsNull() ||
(source.AccessToken.IsNullOrEmpty() && source.RefreshToken.IsNullOrEmpty()))
{
return null;
}
//
var result = new XTokenResponse {
var result = new XTokenResponse
{
AccessToken = source.AccessToken,
RefreshToken = source.RefreshToken,
ExpiresAt = source.ExpiresAt
@@ -116,5 +156,109 @@ namespace xIdentityModels.Extensions {
//
return result;
}
/// <summary>
/// Validate Item for Add or Update ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static bool IsValidForAdd(this XApplication source)
{
//
var result =
!source.IsNullOrDefault() &&
!source.Name.IsNullOrEmpty();
//
return result;
}
/// <summary>
/// Validate Item for Add or Update ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static bool IsValidForAdd(this XApplicationDto source)
{
//
var result =
!source.IsNullOrDefault() &&
!source.Name.IsNullOrEmpty();
//
return result;
}
/// <summary>
/// Validate Item for Add or Update ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static bool IsValidForAdd(this XApiKey source)
{
//
var result =
!source.IsNullOrDefault() &&
!source.ApplicationId.IsValidIntId() &&
!source.KeyHash.IsNullOrEmpty();
//
return result;
}
/// <summary>
/// Validate Item for Add or Update ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static bool IsValidForAdd(this XApiKeyDto source)
{
//
var result =
!source.IsNullOrDefault() &&
!source.ApplicationId.IsValidIntId() &&
!source.KeyHash.IsNullOrEmpty();
//
return result;
}
/// <summary>
/// Validate Item for Add or Update ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static bool IsValidForAdd(this XApiKeyUsage source)
{
//
var result =
!source.IsNullOrDefault() &&
!source.ApiKeyId.IsDefaultGuid() &&
!source.ClientIP.IsNullOrEmpty() &&
!source.Endpoint.IsNullOrEmpty() &&
!source.HttpMethod.IsNullOrEmpty();
//
return result;
}
/// <summary>
/// Validate Item for Add or Update ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static bool IsValidForAdd(this XApiKeyUsageDto source)
{
//
var result =
!source.IsNullOrDefault() &&
!source.ApiKeyId.IsDefaultGuid() &&
!source.ClientIP.IsNullOrEmpty() &&
!source.Endpoint.IsNullOrEmpty() &&
!source.HttpMethod.IsNullOrEmpty();
//
return result;
}
}
}
+1 -2
View File
@@ -1,3 +1,4 @@
using System;
using System.Linq;
using xCommons.Extensions;
using xIdentityModels.Dtos;
@@ -5,8 +6,6 @@ using xIdentityModels.Models;
using xIdentityModels.Constants;
using System.Collections.Generic;
using xIdentityModels.Configurations;
using Microsoft.OpenApi.Expressions;
using System;
namespace xIdentityModels.Extensions
{