-
Notifications
You must be signed in to change notification settings - Fork 844
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73f01ae
commit 900d3a0
Showing
4 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
src/VirtoCommerce.Platform.Security/Model/SignInValidatorContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string, object> AdditionalParameters { get; set; } = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/VirtoCommerce.Platform.Security/Model/TokenLoginResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IdentityError> Errors | ||
{ | ||
get | ||
{ | ||
var errors = new List<IdentityError>(); | ||
if (Code != null) | ||
{ | ||
errors.Add(new IdentityError | ||
{ | ||
Code = Code, | ||
Description = ErrorDescription | ||
}); | ||
} | ||
return errors; | ||
} | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/VirtoCommerce.Platform.Security/SecurityErrorDescriber.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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." | ||
}; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/VirtoCommerce.Platform.Security/Services/IUserSignInValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IList<TokenLoginResponse>> ValidateUserAsync(SignInValidatorContext context); | ||
} | ||
} |