diff --git a/src/Api/IdentityServer/ResourceOwnerPasswordValidator.cs b/src/Api/IdentityServer/ResourceOwnerPasswordValidator.cs index 4402dfd24c..1147f9c471 100644 --- a/src/Api/IdentityServer/ResourceOwnerPasswordValidator.cs +++ b/src/Api/IdentityServer/ResourceOwnerPasswordValidator.cs @@ -1,4 +1,5 @@ -using Bit.Core.Domains; +using Bit.Api.Models.Response; +using Bit.Core.Domains; using Bit.Core.Enums; using Bit.Core.Exceptions; using Bit.Core.Repositories; @@ -44,7 +45,6 @@ namespace Bit.Api.IdentityServer if(!twoFactorRequest && await TwoFactorRequiredAsync(user)) { context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "Two factor code required.", - // TODO: return something better? new System.Collections.Generic.Dictionary { { "TwoFactorRequired", true } }); return; } @@ -66,9 +66,12 @@ namespace Bit.Api.IdentityServer } } - context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, - twoFactorRequest ? "Code is not correct. Try again." : "Username or password is incorrect. Try again.", - new System.Collections.Generic.Dictionary { { "Error", true } }); + await Task.Delay(2000); + context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, customResponse: + new System.Collections.Generic.Dictionary { { + "ErrorModel", new ErrorResponseModel(twoFactorRequest ? + "Code is not correct. Try again." : "Username or password is incorrect. Try again.") + } }); } private async Task TwoFactorRequiredAsync(User user) diff --git a/src/Api/Models/Response/ErrorResponseModel.cs b/src/Api/Models/Response/ErrorResponseModel.cs index b43557b175..3041617656 100644 --- a/src/Api/Models/Response/ErrorResponseModel.cs +++ b/src/Api/Models/Response/ErrorResponseModel.cs @@ -10,6 +10,12 @@ namespace Bit.Api.Models.Response : base("error") { } + public ErrorResponseModel(string message) + : this() + { + Message = message; + } + public ErrorResponseModel(ModelStateDictionary modelState) : this() { diff --git a/src/Api/Utilities/ExceptionHandlerFilterAttribute.cs b/src/Api/Utilities/ExceptionHandlerFilterAttribute.cs index 0f7c8dec7d..ad48e0b01c 100644 --- a/src/Api/Utilities/ExceptionHandlerFilterAttribute.cs +++ b/src/Api/Utilities/ExceptionHandlerFilterAttribute.cs @@ -14,7 +14,7 @@ namespace Bit.Api.Utilities { public override void OnException(ExceptionContext context) { - var errorModel = new ErrorResponseModel { Message = "An error has occured." }; + var errorModel = new ErrorResponseModel("An error has occured."); var exception = context.Exception; if(exception == null)