Initial Commit ...
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using xIdentityModels.Navigations;
|
||||
|
||||
namespace xIdentityModels.Models {
|
||||
/// <summary>
|
||||
/// represent a system wide actions
|
||||
/// </summary>
|
||||
public class XActionRequest {
|
||||
/// <summary>
|
||||
/// Client Device Locale
|
||||
/// </summary>
|
||||
/// <value>user's client device local such as en-US</value>
|
||||
public string Lang { get; set; } = null;
|
||||
/// <summary>
|
||||
/// Requested Action Token
|
||||
/// </summary>
|
||||
/// <value>a hashed content</value>
|
||||
public string ActionToken { get; set; } = null;
|
||||
/// <summary>
|
||||
/// user's device
|
||||
/// </summary>
|
||||
/// <value>an instance of <see>XDevice</see> which represent user's device</value>
|
||||
public XDevice Device { get; set; } = null;
|
||||
/// <summary>
|
||||
/// FirstName
|
||||
/// </summary>
|
||||
/// <value>users FirstName</value>
|
||||
public string FirstName { get; set; } = null;
|
||||
/// <summary>
|
||||
/// LastName
|
||||
/// </summary>
|
||||
/// <value>user's LastName</value>
|
||||
public string LastName { get; set; } = null;
|
||||
/// <summary>
|
||||
/// an Optional Value which represetns User's DateOfBirth
|
||||
/// </summary>
|
||||
/// <value>user's DateOfBirth</value>
|
||||
public DateTime? DateOfBirth { get; set; } = DateTime.MinValue;
|
||||
/// <summary>
|
||||
/// User's Id
|
||||
/// </summary>
|
||||
/// <value>a GUID string which represent user's Id</value>
|
||||
public string UserId { get; set; } = null;
|
||||
/// <summary>
|
||||
/// UserName
|
||||
/// </summary>
|
||||
/// <value>user's UserName</value>
|
||||
public string UserName { get; set; } = null;
|
||||
/// <summary>
|
||||
/// Email
|
||||
/// </summary>
|
||||
/// <value>user's Email address</value>
|
||||
public string Email { get; set; } = null;
|
||||
/// <summary>
|
||||
/// MobileNumber / PhoneNumber
|
||||
/// </summary>
|
||||
/// <value>user's PhoneNumber</value>
|
||||
public string MobileNumber { get; set; } = null;
|
||||
/// <summary>
|
||||
/// Password
|
||||
/// </summary>
|
||||
/// <value>user's Password</value>
|
||||
public string Password { get; set; } = null;
|
||||
/// <summary>
|
||||
/// NewPassword
|
||||
/// </summary>
|
||||
/// <value>a passwor string which used to Change/Reset password</value>
|
||||
public string NewPassword { get; set; } = null;
|
||||
/// <summary>
|
||||
/// EmailVerificationCode
|
||||
/// </summary>
|
||||
/// <value>a Verification Code which assign to user's for confirm it's Email Address</value>
|
||||
public string EmailVerificationCode { get; set; } = null;
|
||||
/// <summary>
|
||||
/// MobileVerificationCode
|
||||
/// </summary>
|
||||
/// <value>a Verification Code which assign to user's for confirm it's Phone Number</value>
|
||||
public string MobileVerificationCode { get; set; } = null;
|
||||
/// <summary>
|
||||
/// Thumbnail
|
||||
/// </summary>
|
||||
/// <value>an instance of <see>IFormFile</see> which is used as user's avatar</value>
|
||||
public IFormFile Thumbnail { get; set; }
|
||||
/// <summary>
|
||||
/// ReturnUrl
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// a url string which used in many used cases for providing a way to lead users to right places.
|
||||
/// </value>
|
||||
public string ReturnUrl { get; set; } = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using xIdentityModels.Navigations;
|
||||
|
||||
namespace xIdentityModels.Models {
|
||||
public class XActionRequestContext {
|
||||
//
|
||||
public string Lang { get; set; }
|
||||
|
||||
//
|
||||
public string UserId { get; set; }
|
||||
public string UserName { get; set; }
|
||||
|
||||
//
|
||||
public string MobileNumber { get; set; }
|
||||
public string MobileVerificationCode { get; set; }
|
||||
public bool MobileVerified { get; set; }
|
||||
|
||||
//
|
||||
public string Email { get; set; }
|
||||
public string EmailVerificationCode { get; set; }
|
||||
public bool EmailVerified { get; set; }
|
||||
|
||||
//
|
||||
public string FirstName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
public DateTime DateOfBirth { get; set; }
|
||||
|
||||
//
|
||||
public XDevice Device { get; set; }
|
||||
public IFormFile Thubmnail { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using xCommons.Extensions;
|
||||
using xIdentityModels.Constants;
|
||||
|
||||
namespace xIdentityModels.Models {
|
||||
public class XActionRequestToken {
|
||||
public XAction Action { get; set; }
|
||||
public XActionRequestContext Context { get; set; }
|
||||
public string Token { get; set; }
|
||||
|
||||
public void Prepare (string secret) {
|
||||
Token = (Action.ToString () +
|
||||
secret +
|
||||
Context.ToJSON ()).ToMd5String ();
|
||||
}
|
||||
|
||||
public bool Validate (string secret) {
|
||||
return (Action.ToString () +
|
||||
secret +
|
||||
Context.ToJSON ()).ToMd5String () == Token;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace xIdentityModels.Models {
|
||||
/// <summary>
|
||||
/// represent a system wide action result
|
||||
/// </summary>
|
||||
public class XActionResponse {
|
||||
/// <summary>
|
||||
/// ActionToken
|
||||
/// </summary>
|
||||
/// <value>a hashed string which carry required info for doing system actions.</value>
|
||||
[JsonProperty (
|
||||
"token",
|
||||
Required = Required.Default,
|
||||
NullValueHandling = NullValueHandling.Ignore)]
|
||||
public string Token { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ActionToken Lifetime
|
||||
/// </summary>
|
||||
/// <value>an instance of <see>DateTime</see> which represent token expiration time</value>
|
||||
[JsonProperty (
|
||||
"expiration",
|
||||
Required = Required.DisallowNull,
|
||||
NullValueHandling = NullValueHandling.Ignore)]
|
||||
public DateTime Expiration { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using xCommons.Extensions;
|
||||
using xIdentityModels.Navigations;
|
||||
using xModels.Base;
|
||||
|
||||
namespace xIdentityModels.Models {
|
||||
public class XBannedDevice : XBaseIntIDEntity {
|
||||
public DateTime BannedOn { get; set; }
|
||||
|
||||
public string DeviceStr { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public XDevice Device {
|
||||
get {
|
||||
return DeviceStr.FromJSON<XDevice> ();
|
||||
}
|
||||
set {
|
||||
DeviceStr = value.ToJSON ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using xIdentityModels.Navigations;
|
||||
|
||||
namespace xIdentityModels.Models {
|
||||
/// <summary>
|
||||
/// Represent Requirements for Authenticationg a User
|
||||
/// </summary>
|
||||
public class XLoginRequest {
|
||||
/// <summary>
|
||||
/// how select an specific User
|
||||
/// </summary>
|
||||
/// <value>an string value which represent how system select user such as: UserName, Email Address or MobileNumber</value>
|
||||
[Required]
|
||||
public string UserSelectBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// user's password
|
||||
/// </summary>
|
||||
/// <value>an string which represent user's pasword</value>
|
||||
[Required]
|
||||
public string Password { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// user's device
|
||||
/// </summary>
|
||||
/// <value>an instance of <see>XDevice</see> which represent user's device</value>
|
||||
public XDevice Device { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// user's language
|
||||
/// </summary>
|
||||
/// <value>an string which represent user's language and locale, such as: en-US</value>
|
||||
public string Language { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
using xIdentityModels.Dtos;
|
||||
|
||||
namespace xIdentityModels.Models {
|
||||
public class XLoginResponse : XTokenResponse {
|
||||
public XUserProfileDto Profile { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using xIdentityModels.Constants;
|
||||
|
||||
namespace xIdentityModels.Models {
|
||||
public class XProfileUpdateRequest {
|
||||
public string Email { get; set; }
|
||||
public bool? EmailConfirmed { get; set; }
|
||||
public string PhoneNumber { get; set; }
|
||||
public bool? PhoneNumberConfirmed { get; set; }
|
||||
public string FirstName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
public string Avatar { get; set; }
|
||||
public DateTime? DateOfBirth { get; set; }
|
||||
public DateTime? CreationDate { get; set; }
|
||||
public DateTime? LastLogin { get; set; }
|
||||
public XGender? Gender { get; set; }
|
||||
public ICollection<string> Roles { get; set; } = new HashSet<string> ();
|
||||
public bool? IsEnable { get; set; }
|
||||
public bool? IsBanned { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using xCommons.Extensions;
|
||||
using xIdentityModels.Constants;
|
||||
using xIdentityModels.Navigations;
|
||||
using xModels.Base;
|
||||
|
||||
namespace xIdentityModels.Models {
|
||||
public class XToken : XBaseIntIDEntity {
|
||||
public string Token { get; set; }
|
||||
public string Hash { get; set; }
|
||||
public string UserSelectByParam { get; set; }
|
||||
public string DeviceStr { get; set; }
|
||||
public XAction Type { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public XDevice Device {
|
||||
get {
|
||||
return DeviceStr.FromJSON<XDevice> ();
|
||||
}
|
||||
|
||||
set {
|
||||
DeviceStr = value.ToJSON ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace xIdentityModels.Models {
|
||||
public class XTokenResponse {
|
||||
[Required]
|
||||
public string AccessToken { get; set; }
|
||||
public string RefreshToken { get; set; }
|
||||
public long ExpiresAt { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using xCommons.Constants;
|
||||
using xCommons.Extensions;
|
||||
using xCommons.Helpers;
|
||||
using xExceptions.Constants;
|
||||
using xIdentityModels.Constants;
|
||||
using xModels.Base;
|
||||
|
||||
namespace xIdentityModels.Models {
|
||||
public class XUserClaimsInfoDto : XBaseDto {
|
||||
//
|
||||
#region Properties ...
|
||||
public string AccessToken { get; }
|
||||
public string RefreshToken { get; }
|
||||
public long ExpiresAt { get; }
|
||||
public string UserId { get; }
|
||||
public string UserName { get; }
|
||||
public string FirstName { get; }
|
||||
public string LastName { get; }
|
||||
public string Picture { get; }
|
||||
public string Email { get; }
|
||||
public string PhoneNumber { get; }
|
||||
public XGender Gender { get; }
|
||||
public bool IsBanned { get; }
|
||||
public bool IsEnabled { get; }
|
||||
public bool EmailConfirmed { get; }
|
||||
public bool PhoneNumberConfirmed { get; }
|
||||
public long? ExpiredOn { get; }
|
||||
public long? AuthenticatedOn { get; }
|
||||
public DateTime? BrithDate { get; }
|
||||
public IEnumerable<string> Issuers { get; } = new HashSet<string> ();
|
||||
public IEnumerable<string> Audiences { get; } = new HashSet<string> ();
|
||||
public IEnumerable<string> ClientIds { get; } = new HashSet<string> ();
|
||||
public IEnumerable<string> Scopes { get; } = new HashSet<string> ();
|
||||
public IEnumerable<string> Roles { get; } = new HashSet<string> ();
|
||||
#endregion
|
||||
|
||||
//
|
||||
public XUserClaimsInfoDto () { }
|
||||
|
||||
public XUserClaimsInfoDto (
|
||||
string accessToken,
|
||||
string refreshToken,
|
||||
long expiresAt,
|
||||
IEnumerable<Claim> claims
|
||||
) {
|
||||
//
|
||||
// refreshToken.IsNullOrEmpty ()
|
||||
if (claims.IsNull () ||
|
||||
accessToken.IsNullOrEmpty ()) {
|
||||
XException.InvalidArgs.Throw ();
|
||||
}
|
||||
|
||||
//
|
||||
// Attach XLogin Properties ...
|
||||
AccessToken = accessToken;
|
||||
RefreshToken = refreshToken;
|
||||
ExpiresAt = expiresAt;
|
||||
|
||||
//
|
||||
if (!claims.IsNull ()) {
|
||||
UserId = claims.FirstOrDefault (c => c.Type == XCustomClaims.UserId)?.Value ?? "";
|
||||
UserName = claims.FirstOrDefault (c => c.Type == XCustomClaims.UserName)?.Value ?? "";
|
||||
FirstName = claims.FirstOrDefault (c => c.Type == XCustomClaims.FirstName)?.Value ?? "";
|
||||
LastName = claims.FirstOrDefault (c => c.Type == XCustomClaims.LastName)?.Value ?? "";
|
||||
Picture = claims.FirstOrDefault (c => c.Type == XCustomClaims.Picture)?.Value ?? "";
|
||||
Email = claims.FirstOrDefault (c => c.Type == XCustomClaims.Email)?.Value ?? null;
|
||||
PhoneNumber = claims.FirstOrDefault (c => c.Type == XCustomClaims.PhoneNumber)?.Value ?? null;
|
||||
|
||||
//
|
||||
// Handle Gender ...
|
||||
var genders = ObjectHelper.ToEnumerableKeys<XGender> ();
|
||||
var genderStr = claims.FirstOrDefault (c => c.Type == XCustomClaims.Gender).Value ?? null;
|
||||
if (genderStr.IsNullOrEmpty ()) {
|
||||
Gender = XGender.Male;
|
||||
} else {
|
||||
Gender = genderStr.GetValue<XGender> ();
|
||||
}
|
||||
|
||||
//
|
||||
// Handle IsBanned ...
|
||||
var isBannedStr = claims.FirstOrDefault (c => c.Type == XCustomClaims.IsBanned).Value ?? null;
|
||||
if (isBannedStr.IsNullOrEmpty ()) {
|
||||
IsBanned = false;
|
||||
} else {
|
||||
//
|
||||
var isBanned = false;
|
||||
Boolean.TryParse (isBannedStr, out isBanned);
|
||||
|
||||
//
|
||||
IsBanned = isBanned;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle IsEnabled ...
|
||||
var isEnabledStr = claims.FirstOrDefault (c => c.Type == XCustomClaims.IsEnabled).Value ?? null;
|
||||
if (isEnabledStr.IsNullOrEmpty ()) {
|
||||
IsEnabled = false;
|
||||
} else {
|
||||
//
|
||||
var isEnabled = false;
|
||||
Boolean.TryParse (isEnabledStr, out isEnabled);
|
||||
|
||||
//
|
||||
IsEnabled = isEnabled;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Email Confirmed ...
|
||||
var emailConfirmedStr = claims.FirstOrDefault (c => c.Type == XCustomClaims.EmailVerified).Value ?? null;
|
||||
if (emailConfirmedStr.IsNullOrEmpty ()) {
|
||||
EmailConfirmed = false;
|
||||
} else {
|
||||
//
|
||||
var emailConfirmed = false;
|
||||
Boolean.TryParse (emailConfirmedStr, out emailConfirmed);
|
||||
|
||||
//
|
||||
EmailConfirmed = emailConfirmed;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle PhoneNumber Confirmed ...
|
||||
var phoneNumberConfirmedStr = claims.FirstOrDefault (c => c.Type == XCustomClaims.PhoneNumberVerified).Value ?? null;
|
||||
if (phoneNumberConfirmedStr.IsNullOrEmpty ()) {
|
||||
PhoneNumberConfirmed = false;
|
||||
} else {
|
||||
//
|
||||
var phoneNumberConfirmed = false;
|
||||
Boolean.TryParse (phoneNumberConfirmedStr, out phoneNumberConfirmed);
|
||||
|
||||
//
|
||||
PhoneNumberConfirmed = phoneNumberConfirmed;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle ExpiredOn ...
|
||||
var expiredOnStr = claims.FirstOrDefault (c => c.Type == XCustomClaims.ExpiredOn).Value ?? null;
|
||||
if (expiredOnStr.IsNullOrEmpty ()) {
|
||||
ExpiredOn = null;
|
||||
} else {
|
||||
//
|
||||
long expiredOn = 0;
|
||||
long.TryParse (expiredOnStr, out expiredOn);
|
||||
|
||||
//
|
||||
ExpiredOn = expiredOn;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle AuthenticatedOn ...
|
||||
var authenticatedOnStr = claims.FirstOrDefault (c => c.Type == XCustomClaims.AuthenticatedOn).Value ?? null;
|
||||
if (authenticatedOnStr.IsNullOrEmpty ()) {
|
||||
AuthenticatedOn = null;
|
||||
} else {
|
||||
//
|
||||
long authenticatedOn = 0;
|
||||
long.TryParse (authenticatedOnStr, out authenticatedOn);
|
||||
|
||||
//
|
||||
AuthenticatedOn = authenticatedOn;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle BrithDate ...
|
||||
var brithDateStr = claims.FirstOrDefault (c => c.Type == XCustomClaims.BrithDate)?.Value ?? "";
|
||||
if (brithDateStr.IsNullOrEmpty ()) {
|
||||
// BrithDate = null;
|
||||
} else {
|
||||
//
|
||||
DateTime bDate;
|
||||
DateTime.TryParse (brithDateStr, out bDate);
|
||||
|
||||
//
|
||||
BrithDate = bDate;
|
||||
}
|
||||
|
||||
//
|
||||
Issuers = claims.Where (c => c.Type == XCustomClaims.Issuer) ?
|
||||
.Select (c => c.Value) ?? new HashSet<string> ();
|
||||
Audiences = claims.Where (c => c.Type == XCustomClaims.Audience) ?
|
||||
.Select (c => c.Value) ?? new HashSet<string> ();
|
||||
ClientIds = claims.Where (c => c.Type == XCustomClaims.ClientId) ?
|
||||
.Select (c => c.Value) ?? new HashSet<string> ();
|
||||
Scopes = claims.Where (c => c.Type == XCustomClaims.Scope) ?
|
||||
.Select (c => c.Value) ?? new HashSet<string> ();
|
||||
Roles = claims.Where (c => c.Type == XCustomClaims.Role) ?
|
||||
.Select (c => c.Value) ?? new HashSet<string> ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using xCommons.Extensions;
|
||||
using xIdentityModels.Navigations;
|
||||
using xModels.Base;
|
||||
|
||||
namespace xIdentityModels.Models {
|
||||
public class XVerificationRequest : XBaseIntIDEntity {
|
||||
|
||||
[Required]
|
||||
public string VerificationCode { get; set; }
|
||||
|
||||
public int NumberOfTries { get; set; }
|
||||
public DateTime LastTryOn { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public XActionRequestToken Request {
|
||||
get {
|
||||
return RequestStr.FromJSON<XActionRequestToken> ();
|
||||
}
|
||||
set {
|
||||
RequestStr = value.ToJSON ();
|
||||
}
|
||||
}
|
||||
|
||||
public string RequestStr { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public XDevice Device {
|
||||
get {
|
||||
return DeviceStr.FromJSON<XDevice> ();
|
||||
}
|
||||
set {
|
||||
DeviceStr = value.ToJSON ();
|
||||
}
|
||||
}
|
||||
|
||||
public string DeviceStr { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user