1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-08 14:38:15 -05:00

identitysever cleanup

This commit is contained in:
Kyle Spearrin 2017-01-20 22:26:19 -05:00
parent 3348b07ce2
commit 52b8fef26f
3 changed files with 15 additions and 6 deletions

View File

@ -1,4 +1,5 @@
using Bit.Core.Domains; using Bit.Api.Models.Response;
using Bit.Core.Domains;
using Bit.Core.Enums; using Bit.Core.Enums;
using Bit.Core.Exceptions; using Bit.Core.Exceptions;
using Bit.Core.Repositories; using Bit.Core.Repositories;
@ -44,7 +45,6 @@ namespace Bit.Api.IdentityServer
if(!twoFactorRequest && await TwoFactorRequiredAsync(user)) if(!twoFactorRequest && await TwoFactorRequiredAsync(user))
{ {
context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "Two factor code required.", context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "Two factor code required.",
// TODO: return something better?
new System.Collections.Generic.Dictionary<string, object> { { "TwoFactorRequired", true } }); new System.Collections.Generic.Dictionary<string, object> { { "TwoFactorRequired", true } });
return; return;
} }
@ -66,9 +66,12 @@ namespace Bit.Api.IdentityServer
} }
} }
context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, await Task.Delay(2000);
twoFactorRequest ? "Code is not correct. Try again." : "Username or password is incorrect. Try again.", context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, customResponse:
new System.Collections.Generic.Dictionary<string, object> { { "Error", true } }); new System.Collections.Generic.Dictionary<string, object> { {
"ErrorModel", new ErrorResponseModel(twoFactorRequest ?
"Code is not correct. Try again." : "Username or password is incorrect. Try again.")
} });
} }
private async Task<bool> TwoFactorRequiredAsync(User user) private async Task<bool> TwoFactorRequiredAsync(User user)

View File

@ -10,6 +10,12 @@ namespace Bit.Api.Models.Response
: base("error") : base("error")
{ } { }
public ErrorResponseModel(string message)
: this()
{
Message = message;
}
public ErrorResponseModel(ModelStateDictionary modelState) public ErrorResponseModel(ModelStateDictionary modelState)
: this() : this()
{ {

View File

@ -14,7 +14,7 @@ namespace Bit.Api.Utilities
{ {
public override void OnException(ExceptionContext context) 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; var exception = context.Exception;
if(exception == null) if(exception == null)