Compare commits
7
Commits
ca6fbc2201
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
295bd12877 | ||
|
|
4789d6b280 | ||
|
|
80978abefc | ||
|
|
de36e7bfd1 | ||
|
|
efbeeb483d | ||
|
|
fada7e69ec | ||
|
|
7a1cca4e4e |
@@ -1,5 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using xIdentityModels.Dtos;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace xIdentityModels.Configurations {
|
||||
public class XIdentityConfiguration {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace xIdentityModels.Dtos
|
||||
{
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
using xIdentityModels.Constants;
|
||||
using xModels.Base;
|
||||
using xIdentityModels.Constants;
|
||||
|
||||
namespace xIdentityModels.Dtos
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using xCommons.Extensions;
|
||||
using xModels.Base;
|
||||
using xModels.Dtos;
|
||||
using xCommons.Extensions;
|
||||
|
||||
namespace xIdentityModels.Dtos
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using xModels.Base;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace xIdentityModels.Dtos {
|
||||
public class XProfileImageDto : XBaseDto {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using xModels.Base;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace xIdentityModels.Dtos {
|
||||
public class XUserNameIdRequest : XBaseDto {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using xModels.Base;
|
||||
using Newtonsoft.Json;
|
||||
using xIdentityModels.Constants;
|
||||
using xModels.Base;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace xIdentityModels.Dtos {
|
||||
public class XUserProfileDto : XBaseDto {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using xCommons.Extensions;
|
||||
using xIdentityModels.Interfaces;
|
||||
using xIdentityModels.Providers;
|
||||
using xIdentityModels.Interfaces;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace xIdentityModels.Extensions {
|
||||
public static class DIExtensions {
|
||||
@@ -10,6 +10,7 @@ namespace xIdentityModels.Extensions {
|
||||
/// user not provided we create this helper ...
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="helper"></param>
|
||||
public static void AddXUserRoleHandler (
|
||||
this IServiceCollection services,
|
||||
IXUserRoleHelper helper = null
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using xCommons.Extensions;
|
||||
using xExceptions.Constants;
|
||||
using xIdentityModels.Constants;
|
||||
using xIdentityModels.Models;
|
||||
using xIdentityModels.Constants;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace xIdentityModels.Extensions {
|
||||
public static class XIdentityExtensions {
|
||||
|
||||
+167
-23
@@ -1,19 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using xModels.Dtos;
|
||||
using xCommons.Extensions;
|
||||
using xIdentityModels.Descriptors;
|
||||
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,
|
||||
@@ -25,25 +31,54 @@ namespace xIdentityModels.Extensions {
|
||||
IsEnable = true,
|
||||
IsBanned = false,
|
||||
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>
|
||||
/// 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,20 +1,20 @@
|
||||
using System;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using IdentityModel.Client;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using xCommons.Constants;
|
||||
using xCommons.Extensions;
|
||||
using IdentityModel.Client;
|
||||
using xExceptions.Constants;
|
||||
using xIdentityModels.Constants;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using xIdentityModels.Models;
|
||||
using System.Net.Http.Headers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using xIdentityModels.Constants;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
|
||||
namespace xIdentityModels.Extensions {
|
||||
public static class XTokenExtensions {
|
||||
@@ -440,6 +440,7 @@ namespace xIdentityModels.Extensions {
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="secret"></param>
|
||||
public static void SetXAuthenticationTokens (
|
||||
this IHeaderDictionary source,
|
||||
XLoginResponse model,
|
||||
@@ -469,6 +470,7 @@ namespace xIdentityModels.Extensions {
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="secret"></param>
|
||||
public static void SetXAuthenticationTokens (
|
||||
this IHeaderDictionary source,
|
||||
XTokenResponse model,
|
||||
@@ -596,6 +598,7 @@ namespace xIdentityModels.Extensions {
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="secret"></param>
|
||||
public static void SetXAuthenticationTokens (
|
||||
this HttpResponse source,
|
||||
XLoginResponse model,
|
||||
@@ -612,6 +615,7 @@ namespace xIdentityModels.Extensions {
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="secret"></param>
|
||||
public static void SetXAuthenticationTokens (
|
||||
this HttpResponse source,
|
||||
XTokenResponse model,
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using xCommons.Extensions;
|
||||
using xIdentityModels.Configurations;
|
||||
using xIdentityModels.Constants;
|
||||
using xIdentityModels.Dtos;
|
||||
using xIdentityModels.Models;
|
||||
using xIdentityModels.Constants;
|
||||
using System.Collections.Generic;
|
||||
using xIdentityModels.Configurations;
|
||||
|
||||
namespace xIdentityModels.Extensions
|
||||
{
|
||||
@@ -195,5 +196,54 @@ namespace xIdentityModels.Extensions
|
||||
//
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using xModels.Base;
|
||||
using xCommons.Extensions;
|
||||
using xIdentityModels.Navigations;
|
||||
using xModels.Base;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace xIdentityModels.Models {
|
||||
public class XBannedDevice : XBaseIntIDEntity {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using xIdentityModels.Navigations;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace xIdentityModels.Models {
|
||||
/// <summary>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using xIdentityModels.Constants;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace xIdentityModels.Models {
|
||||
public class XProfileUpdateRequest {
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using xModels.Base;
|
||||
using xCommons.Extensions;
|
||||
using xIdentityModels.Constants;
|
||||
using xIdentityModels.Navigations;
|
||||
using xModels.Base;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace xIdentityModels.Models {
|
||||
public class XToken : XBaseIntIDEntity {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using xModels.Base;
|
||||
using xCommons.Helpers;
|
||||
using xCommons.Constants;
|
||||
using xCommons.Extensions;
|
||||
using xCommons.Helpers;
|
||||
using xExceptions.Constants;
|
||||
using System.Security.Claims;
|
||||
using xIdentityModels.Constants;
|
||||
using xModels.Base;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace xIdentityModels.Models
|
||||
{
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using xModels.Base;
|
||||
using xCommons.Extensions;
|
||||
using xIdentityModels.Navigations;
|
||||
using xModels.Base;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace xIdentityModels.Models {
|
||||
public class XVerificationRequest : XBaseIntIDEntity {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using xCommons.Constants;
|
||||
using xModels.Base;
|
||||
using xCommons.Constants;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace xIdentityModels.Navigations {
|
||||
/// <summary>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using xIdentityModels.Constants;
|
||||
using xModels.Base;
|
||||
using xIdentityModels.Constants;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace xIdentityModels.Navigations {
|
||||
/// <summary>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using xIdentityModels.Constants;
|
||||
using xModels.Base;
|
||||
using xIdentityModels.Constants;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace xIdentityModels.Navigations {
|
||||
/// <summary>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using xModels.Base;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using xModels.Base;
|
||||
|
||||
namespace xIdentityModels.Navigations {
|
||||
/// <summary>
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using xCommons.Extensions;
|
||||
using xModels.Base;
|
||||
using xCommons.Extensions;
|
||||
using xIdentityModels.Models;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace xIdentityModels {
|
||||
public class XApiToken : XBaseIntIDEntity {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using xIdentityModels.Constants;
|
||||
using System.Collections.Generic;
|
||||
using xIdentityModels.Navigations;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using xIdentityModels.Constants;
|
||||
using xIdentityModels.Navigations;
|
||||
|
||||
namespace xIdentityModels
|
||||
{
|
||||
|
||||
+1
-1
@@ -3,6 +3,6 @@
|
||||
<packageSources>
|
||||
<!-- <add key="megan" value="https://hub.megan.ir/nuget/index.json" /> -->
|
||||
<add key="nuget" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||
<add key="baget" value="https://nuget.saherelmhub.ir/v3/index.json" protocolVersion="3" disableTLSCertificateValidation="true" />
|
||||
<!-- <add key="baget" value="https://nuget.saherelmhub.ir/v3/index.json" protocolVersion="3" disableTLSCertificateValidation="true" /> -->
|
||||
</packageSources>
|
||||
</configuration>
|
||||
@@ -41,9 +41,9 @@
|
||||
|
||||
<!-- For XML Documentation Support -->
|
||||
<PropertyGroup>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<NoWarn>$(NoWarn);1591</NoWarn>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user