last ...
This commit is contained in:
@@ -0,0 +1,19 @@
|
|||||||
|
using xExceptions.Attributes;
|
||||||
|
|
||||||
|
namespace xIdentityModels.Constants
|
||||||
|
{
|
||||||
|
public enum XApiKeyScope
|
||||||
|
{
|
||||||
|
[StringValue("read")]
|
||||||
|
Read,
|
||||||
|
|
||||||
|
[StringValue("write")]
|
||||||
|
Write,
|
||||||
|
|
||||||
|
[StringValue("admin")]
|
||||||
|
Admin,
|
||||||
|
|
||||||
|
[StringValue("manage")]
|
||||||
|
Manage
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace xIdentityModels.Constants
|
||||||
|
{
|
||||||
|
public enum XApplicationType
|
||||||
|
{
|
||||||
|
Web, Mobile, Desktop, IoT, ThirdParty, Service
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,8 @@ 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
|
||||||
{
|
{
|
||||||
@@ -161,7 +163,7 @@ namespace xIdentityModels.Extensions
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
var result =
|
var result =
|
||||||
!source.IsNullOrDefault() &&
|
!source.IsNullOrDefault() &&
|
||||||
source.Roles
|
source.Roles
|
||||||
.Any(r => roles
|
.Any(r => roles
|
||||||
@@ -195,5 +197,54 @@ namespace xIdentityModels.Extensions
|
|||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check Specified Api Key is Revoked or not ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool IsRevoked(this XApiKey source)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result =
|
||||||
|
!source.IsNullOrDefault() &&
|
||||||
|
source.RevokedAt.HasValue;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check Specified Api Key is Expired or not ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool IsExpired(this XApiKey source)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result =
|
||||||
|
!source.IsNullOrDefault() &&
|
||||||
|
DateTime.UtcNow >= source.ExpiresAt;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check Specified Api Key is Active or not ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool IsActive(this XApiKey source)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result =
|
||||||
|
!source.IsNullOrDefault() &&
|
||||||
|
!source.IsRevoked() &&
|
||||||
|
!source.IsExpired();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
using System;
|
||||||
|
using xModels.Base;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace xIdentityModels.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// an Specified Api Key ...
|
||||||
|
/// </summary>
|
||||||
|
public class XApiKey : XBaseGuidIDEntity
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Related Application Id ...
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
public int ApplicationId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Hash ...
|
||||||
|
/// SHA256 of ApiKey ...
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[StringLength(512)]
|
||||||
|
public string KeyHash { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a Prefix ...
|
||||||
|
/// </summary>
|
||||||
|
[StringLength(100)]
|
||||||
|
public string KeyPrefix { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Expiration Type ...
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
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>
|
||||||
|
[StringLength(1000)]
|
||||||
|
public string AllowedScopes { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a Comma-separated List which Specified White List IP ...
|
||||||
|
/// </summary>
|
||||||
|
[StringLength(2000)]
|
||||||
|
public string AllowedIPs { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Rate Limit Per Minute ...
|
||||||
|
/// </summary>
|
||||||
|
public int RateLimitPerMinute { get; set; } = 60;
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Navigation ...
|
||||||
|
/// <summary>
|
||||||
|
/// Related Application ...
|
||||||
|
/// </summary>
|
||||||
|
public virtual XApplication Application { get; set; }
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
using System;
|
||||||
|
using xModels.Base;
|
||||||
|
|
||||||
|
namespace xIdentityModels.Models
|
||||||
|
{
|
||||||
|
public class XApiKeyUsage : XBaseLongIDEntity
|
||||||
|
{
|
||||||
|
/// <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,62 @@
|
|||||||
|
using System;
|
||||||
|
using xModels.Base;
|
||||||
|
using xIdentityModels.Constants;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace xIdentityModels.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// an Application in xDashboard ...
|
||||||
|
/// </summary>
|
||||||
|
public class XApplication : XBaseIntIDEntity
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Name ...
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[StringLength(255)]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Descriptor ...
|
||||||
|
/// </summary>
|
||||||
|
[StringLength(1000)]
|
||||||
|
public string Description { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Owner Id ...
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[StringLength(255)]
|
||||||
|
public string OwnerId { 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; }
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Navigation ...
|
||||||
|
/// <summary>
|
||||||
|
/// a Collection of ApiKeys which Related to this Application ...
|
||||||
|
/// </summary>
|
||||||
|
public virtual ICollection<XApiKey> ApiKeys { get; set; }
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user