diff --git a/src/VirtoCommerce.Platform.Security/Model/SignInValidatorContext.cs b/src/VirtoCommerce.Platform.Security/Model/SignInValidatorContext.cs new file mode 100644 index 00000000000..0f230c7f92d --- /dev/null +++ b/src/VirtoCommerce.Platform.Security/Model/SignInValidatorContext.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using VirtoCommerce.Platform.Core.Security; + +namespace VirtoCommerce.Platform.Security.Model +{ + [Obsolete("Use VirtoCommerce.Platform.Security.OpenIddict.TokenRequestContext", DiagnosticId = "VC0008", UrlFormat = "https://docs.virtocommerce.org/products/products-virto3-versions/")] + public class SignInValidatorContext + { + public ApplicationUser User { get; set; } + + public string StoreId { get; set; } + + public bool DetailedErrors { get; set; } + + public bool IsSucceeded { get; set; } + + public bool IsLockedOut { get; set; } + + public IDictionary AdditionalParameters { get; set; } = new Dictionary(StringComparer.OrdinalIgnoreCase); + } +} diff --git a/src/VirtoCommerce.Platform.Security/Model/TokenLoginResponse.cs b/src/VirtoCommerce.Platform.Security/Model/TokenLoginResponse.cs new file mode 100644 index 00000000000..7d279d7a2ba --- /dev/null +++ b/src/VirtoCommerce.Platform.Security/Model/TokenLoginResponse.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Identity; +using OpenIddict.Abstractions; + +namespace VirtoCommerce.Platform.Security.Model +{ + [Obsolete("Use VirtoCommerce.Platform.Security.OpenIddict.TokenResponse", DiagnosticId = "VC0008", UrlFormat = "https://docs.virtocommerce.org/products/products-virto3-versions/")] + public class TokenLoginResponse : OpenIddictResponse + { + public string UserId { get; set; } + + public IList Errors + { + get + { + var errors = new List(); + if (Code != null) + { + errors.Add(new IdentityError + { + Code = Code, + Description = ErrorDescription + }); + } + return errors; + } + } + } +} diff --git a/src/VirtoCommerce.Platform.Security/SecurityErrorDescriber.cs b/src/VirtoCommerce.Platform.Security/SecurityErrorDescriber.cs new file mode 100644 index 00000000000..ea89db97ca8 --- /dev/null +++ b/src/VirtoCommerce.Platform.Security/SecurityErrorDescriber.cs @@ -0,0 +1,74 @@ +using System; +using VirtoCommerce.Platform.Core.Common; +using VirtoCommerce.Platform.Security.Model; +using static OpenIddict.Abstractions.OpenIddictConstants; + +namespace VirtoCommerce.Platform.Security +{ + [Obsolete("Use VirtoCommerce.Platform.Security.OpenIddict.SecurityErrorDescriber", DiagnosticId = "VC0008", UrlFormat = "https://docs.virtocommerce.org/products/products-virto3-versions/")] + public static class SecurityErrorDescriber + { + public static TokenLoginResponse LoginFailed() => new() + { + Error = Errors.InvalidGrant, + Code = nameof(LoginFailed).ToSnakeCase(), + ErrorDescription = "Login attempt failed. Please check your credentials." + }; + + public static TokenLoginResponse UserIsLockedOut() => new() + { + Error = Errors.InvalidGrant, + Code = nameof(UserIsLockedOut).ToSnakeCase(), + ErrorDescription = "Your account has been locked. Please contact support for assistance." + }; + + public static TokenLoginResponse UserIsTemporaryLockedOut() => new() + { + Error = Errors.InvalidGrant, + Code = nameof(UserIsLockedOut).ToSnakeCase(), + ErrorDescription = "Your account has been temporarily locked. Please try again after some time." + }; + + public static TokenLoginResponse PasswordExpired() => new() + { + Error = Errors.InvalidGrant, + Code = nameof(PasswordExpired).ToSnakeCase(), + ErrorDescription = "Your password has been expired and must be changed.", + }; + + public static TokenLoginResponse PasswordLoginDisabled() => new() + { + Error = Errors.InvalidGrant, + Code = nameof(PasswordLoginDisabled).ToSnakeCase(), + ErrorDescription = "The username/password login is disabled." + }; + + public static TokenLoginResponse TokenInvalid() => new() + { + Error = Errors.InvalidGrant, + Code = nameof(TokenInvalid).ToSnakeCase(), + ErrorDescription = "The token is no longer valid." + }; + + public static TokenLoginResponse SignInNotAllowed() => new() + { + Error = Errors.InvalidGrant, + Code = nameof(SignInNotAllowed).ToSnakeCase(), + ErrorDescription = "The user is no longer allowed to sign in." + }; + + public static TokenLoginResponse InvalidClient() => new() + { + Error = Errors.InvalidClient, + Code = nameof(InvalidClient).ToSnakeCase(), + ErrorDescription = "The client application was not found in the database." + }; + + public static TokenLoginResponse UnsupportedGrantType() => new() + { + Error = Errors.UnsupportedGrantType, + Code = nameof(UnsupportedGrantType).ToSnakeCase(), + ErrorDescription = "The specified grant type is not supported." + }; + } +} diff --git a/src/VirtoCommerce.Platform.Security/Services/IUserSignInValidator.cs b/src/VirtoCommerce.Platform.Security/Services/IUserSignInValidator.cs new file mode 100644 index 00000000000..6c3d01bd2ab --- /dev/null +++ b/src/VirtoCommerce.Platform.Security/Services/IUserSignInValidator.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using VirtoCommerce.Platform.Security.Model; + +namespace VirtoCommerce.Platform.Security.Services +{ + [Obsolete("Use VirtoCommerce.Platform.Security.OpenIddict.ITokenRequestValidator", DiagnosticId = "VC0008", UrlFormat = "https://docs.virtocommerce.org/products/products-virto3-versions/")] + public interface IUserSignInValidator + { + public int Priority { get; set; } + + Task> ValidateUserAsync(SignInValidatorContext context); + } +}