-
Notifications
You must be signed in to change notification settings - Fork 848
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VCST-1353: Add validators and custom calim providers for token reques…
…ts (#2810)
- Loading branch information
1 parent
a185c69
commit 73f01ae
Showing
14 changed files
with
200 additions
and
147 deletions.
There are no files selected for viewing
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
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
21 changes: 0 additions & 21 deletions
21
src/VirtoCommerce.Platform.Security/Model/SignInValidatorContext.cs
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
src/VirtoCommerce.Platform.Security/OpenIddict/BaseUserSignInValidator.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,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace VirtoCommerce.Platform.Security.OpenIddict | ||
{ | ||
public class BaseUserSignInValidator : ITokenRequestValidator | ||
{ | ||
public int Priority { get; set; } | ||
|
||
public Task<IList<TokenResponse>> ValidateAsync(TokenRequestContext context) | ||
{ | ||
IList<TokenResponse> result = []; | ||
|
||
if (context.SignInResult != null && !context.SignInResult.Succeeded) | ||
{ | ||
TokenResponse error; | ||
|
||
if (context.DetailedErrors && context.SignInResult.IsLockedOut) | ||
{ | ||
var permanentLockOut = context.User.LockoutEnd == DateTime.MaxValue.ToUniversalTime(); | ||
error = permanentLockOut | ||
? SecurityErrorDescriber.UserIsLockedOut() | ||
: SecurityErrorDescriber.UserIsTemporaryLockedOut(); | ||
} | ||
else | ||
{ | ||
error = SecurityErrorDescriber.LoginFailed(); | ||
} | ||
|
||
result.Add(error); | ||
} | ||
|
||
return Task.FromResult(result); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/VirtoCommerce.Platform.Security/OpenIddict/ITokenClaimProvider.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,9 @@ | ||
using System.Security.Claims; | ||
using System.Threading.Tasks; | ||
|
||
namespace VirtoCommerce.Platform.Security.OpenIddict; | ||
|
||
public interface ITokenClaimProvider | ||
{ | ||
Task SetClaimsAsync(ClaimsPrincipal principal, TokenRequestContext context); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/VirtoCommerce.Platform.Security/OpenIddict/ITokenRequestValidator.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,12 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace VirtoCommerce.Platform.Security.OpenIddict | ||
{ | ||
public interface ITokenRequestValidator | ||
{ | ||
public int Priority { get; set; } | ||
|
||
Task<IList<TokenResponse>> ValidateAsync(TokenRequestContext context); | ||
} | ||
} |
21 changes: 10 additions & 11 deletions
21
...atform.Security/SecurityErrorDescriber.cs → ...rity/OpenIddict/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
29 changes: 29 additions & 0 deletions
29
src/VirtoCommerce.Platform.Security/OpenIddict/TokenRequestContext.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,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Security.Claims; | ||
using Microsoft.AspNetCore.Authentication; | ||
using Microsoft.AspNetCore.Identity; | ||
using OpenIddict.Abstractions; | ||
using VirtoCommerce.Platform.Core.Security; | ||
|
||
namespace VirtoCommerce.Platform.Security.OpenIddict | ||
{ | ||
public class TokenRequestContext | ||
{ | ||
public string AuthenticationScheme { get; set; } | ||
|
||
public OpenIddictRequest Request { get; set; } | ||
|
||
public SignInResult SignInResult { get; set; } | ||
|
||
public ApplicationUser User { get; set; } | ||
|
||
public ClaimsPrincipal Principal { get; set; } | ||
|
||
public AuthenticationProperties Properties { get; set; } | ||
|
||
public bool DetailedErrors { get; set; } | ||
|
||
public IDictionary<string, object> AdditionalParameters { get; set; } = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase); | ||
} | ||
} |
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
32 changes: 0 additions & 32 deletions
32
src/VirtoCommerce.Platform.Security/Services/BaseUserSignInValidator.cs
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
src/VirtoCommerce.Platform.Security/Services/IUserSignInValidator.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.