Compare commits
3
Commits
de36e7bfd1
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
295bd12877 | ||
|
|
4789d6b280 | ||
|
|
80978abefc |
@@ -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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
@@ -1,49 +1,84 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using xModels.Dtos;
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
|
using xIdentityModels.Dtos;
|
||||||
using xIdentityModels.Models;
|
using xIdentityModels.Models;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using xIdentityModels.Descriptors;
|
using xIdentityModels.Descriptors;
|
||||||
using xIdentityModels.Navigations;
|
using xIdentityModels.Navigations;
|
||||||
|
|
||||||
namespace xIdentityModels.Extensions {
|
namespace xIdentityModels.Extensions
|
||||||
public static class XModelExtensions {
|
{
|
||||||
|
public static class XModelExtensions
|
||||||
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// /// Convert XIdentityUserDescriptor instance to XUser
|
/// /// Convert XIdentityUserDescriptor instance to XUser
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source"></param>
|
/// <param name="source"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static XUser ToXUser (this XIdentityUserDescriptor source) {
|
public static XUser ToXUser(this XIdentityUserDescriptor source)
|
||||||
return new XUser {
|
{
|
||||||
|
return new XUser
|
||||||
|
{
|
||||||
Id = source.Id,
|
Id = source.Id,
|
||||||
FirstName = source.FirstName,
|
FirstName = source.FirstName,
|
||||||
LastName = source.LastName,
|
LastName = source.LastName,
|
||||||
UserName = source.UserName,
|
UserName = source.UserName,
|
||||||
Email = source.Email,
|
Email = source.Email,
|
||||||
EmailConfirmed = source.EmailConfirmed,
|
EmailConfirmed = source.EmailConfirmed,
|
||||||
PhoneNumber = source.PhoneNumber,
|
PhoneNumber = source.PhoneNumber,
|
||||||
PhoneNumberConfirmed = source.PhoneNumberConfirmed,
|
PhoneNumberConfirmed = source.PhoneNumberConfirmed,
|
||||||
IsEnable = true,
|
IsEnable = true,
|
||||||
IsBanned = false,
|
IsBanned = false,
|
||||||
CreationDate = DateTime.UtcNow,
|
CreationDate = DateTime.UtcNow,
|
||||||
DateOfBirth = DateTime.Parse (source.DateOfBirth)
|
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>
|
/// <summary>
|
||||||
/// Check a User is Same as Descriptor User
|
/// Check a User is Same as Descriptor User
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source"></param>
|
/// <param name="source"></param>
|
||||||
/// <param name="dest"></param>
|
/// <param name="dest"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool IsSameAs (this XUser source, XIdentityUserDescriptor dest) {
|
public static bool IsSameAs(this XUser source, XIdentityUserDescriptor dest)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
if (source.IsNull () ||
|
if (source.IsNull() ||
|
||||||
dest.IsNull ()) {
|
dest.IsNull())
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
var isSame = source.IsSameContent (dest, propertyWhiteList : new [] {
|
var isSame = source.IsSameContent(dest, propertyWhiteList: new[] {
|
||||||
nameof (XIdentityUserDescriptor.FirstName),
|
nameof (XIdentityUserDescriptor.FirstName),
|
||||||
nameof (XIdentityUserDescriptor.LastName),
|
nameof (XIdentityUserDescriptor.LastName),
|
||||||
nameof (XIdentityUserDescriptor.UserName),
|
nameof (XIdentityUserDescriptor.UserName),
|
||||||
@@ -55,7 +90,7 @@ namespace xIdentityModels.Extensions {
|
|||||||
nameof (XIdentityUserDescriptor.IsBanned),
|
nameof (XIdentityUserDescriptor.IsBanned),
|
||||||
nameof (XIdentityUserDescriptor.DateOfBirth)
|
nameof (XIdentityUserDescriptor.DateOfBirth)
|
||||||
},
|
},
|
||||||
propertyValueCheckers : new [] {
|
propertyValueCheckers: new[] {
|
||||||
new KeyValuePair<string, Func<XUser, XIdentityUserDescriptor, bool>> (
|
new KeyValuePair<string, Func<XUser, XIdentityUserDescriptor, bool>> (
|
||||||
nameof (XIdentityUserDescriptor.DateOfBirth),
|
nameof (XIdentityUserDescriptor.DateOfBirth),
|
||||||
(user, descriptorUser) => {
|
(user, descriptorUser) => {
|
||||||
@@ -76,18 +111,20 @@ namespace xIdentityModels.Extensions {
|
|||||||
/// <param name="source"></param>
|
/// <param name="source"></param>
|
||||||
/// <param name="dest"></param>
|
/// <param name="dest"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool IsSameAs (this XDevice source, XDevice dest) {
|
public static bool IsSameAs(this XDevice source, XDevice dest)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
if (source.IsNull () ||
|
if (source.IsNull() ||
|
||||||
dest.IsNull ()) {
|
dest.IsNull())
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
var isSame = source.Os.ToNormalString () == dest.Os.ToNormalString () &&
|
var isSame = source.Os.ToNormalString() == dest.Os.ToNormalString() &&
|
||||||
source.OsVersion.ToNormalString () == dest.OsVersion.ToNormalString () &&
|
source.OsVersion.ToNormalString() == dest.OsVersion.ToNormalString() &&
|
||||||
source.Browser.ToNormalString () == dest.Browser.ToNormalString () &&
|
source.Browser.ToNormalString() == dest.Browser.ToNormalString() &&
|
||||||
source.UserAgent.ToNormalString () == dest.UserAgent.ToNormalString () &&
|
source.UserAgent.ToNormalString() == dest.UserAgent.ToNormalString() &&
|
||||||
source.DeviceType == dest.DeviceType;
|
source.DeviceType == dest.DeviceType;
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -99,15 +136,18 @@ namespace xIdentityModels.Extensions {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source"></param>
|
/// <param name="source"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static XTokenResponse ToXTokenResponse (this XUserClaimsInfoDto source) {
|
public static XTokenResponse ToXTokenResponse(this XUserClaimsInfoDto source)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
if (source.IsNull () ||
|
if (source.IsNull() ||
|
||||||
(source.AccessToken.IsNullOrEmpty () && source.RefreshToken.IsNullOrEmpty ())) {
|
(source.AccessToken.IsNullOrEmpty() && source.RefreshToken.IsNullOrEmpty()))
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
var result = new XTokenResponse {
|
var result = new XTokenResponse
|
||||||
|
{
|
||||||
AccessToken = source.AccessToken,
|
AccessToken = source.AccessToken,
|
||||||
RefreshToken = source.RefreshToken,
|
RefreshToken = source.RefreshToken,
|
||||||
ExpiresAt = source.ExpiresAt
|
ExpiresAt = source.ExpiresAt
|
||||||
@@ -116,5 +156,109 @@ namespace xIdentityModels.Extensions {
|
|||||||
//
|
//
|
||||||
return result;
|
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,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
using xIdentityModels.Dtos;
|
using xIdentityModels.Dtos;
|
||||||
@@ -5,8 +6,6 @@ using xIdentityModels.Models;
|
|||||||
using xIdentityModels.Constants;
|
using xIdentityModels.Constants;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using xIdentityModels.Configurations;
|
using xIdentityModels.Configurations;
|
||||||
using Microsoft.OpenApi.Expressions;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace xIdentityModels.Extensions
|
namespace xIdentityModels.Extensions
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user