|
@@ -52,7 +52,7 @@ namespace iiie.Authentication.Business.JWT
|
52
|
52
|
/// <returns>The HTTP response</returns>
|
53
|
53
|
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
54
|
54
|
{
|
55
|
|
- HttpStatusCode statusCode;
|
|
55
|
+ OpResult<bool> error = null;
|
56
|
56
|
string token;
|
57
|
57
|
|
58
|
58
|
if (!TryRetrieveToken(request, out token))
|
|
@@ -70,17 +70,15 @@ namespace iiie.Authentication.Business.JWT
|
70
|
70
|
|
71
|
71
|
if (name == null || salt == null)
|
72
|
72
|
{
|
73
|
|
- OpResult<bool>.Error(ResultStatus.LoginError, string.Format("Incomplete token; username is present: {0}; salt is present {1}", name != null, salt != null)).Log();
|
74
|
|
- statusCode = HttpStatusCode.Unauthorized;
|
|
73
|
+ error = OpResult<bool>.Error(ResultStatus.LoginError, string.Format("Incomplete token; username is present: {0}; salt is present {1}", name != null, salt != null), "Incomplete token").Log();
|
75
|
74
|
}
|
76
|
75
|
else
|
77
|
76
|
{
|
78
|
77
|
var user = GetUserDbo(name.Value, salt.Value);
|
79
|
78
|
if (user == null)
|
80
|
79
|
{
|
81
|
|
- OpResult<bool>.Error(ResultStatus.LoginError,
|
82
|
|
- string.Format("Username {0} not found", name.Value)).Log();
|
83
|
|
- statusCode = HttpStatusCode.Unauthorized;
|
|
80
|
+ error = OpResult<bool>.Error(ResultStatus.LoginError,
|
|
81
|
+ string.Format("Username {0} not found", name.Value), "").Log();
|
84
|
82
|
}
|
85
|
83
|
else
|
86
|
84
|
{
|
|
@@ -91,11 +89,10 @@ namespace iiie.Authentication.Business.JWT
|
91
|
89
|
}
|
92
|
90
|
catch (Exception e)
|
93
|
91
|
{
|
94
|
|
- OpResult<bool>.Error(ResultStatus.LoginError, e).Log();
|
95
|
|
- statusCode = HttpStatusCode.Unauthorized;
|
|
92
|
+ error = OpResult<bool>.Error(ResultStatus.LoginError, e, "Failed to validate token").Log();
|
96
|
93
|
}
|
97
|
|
- return Task<HttpResponseMessage>.Factory.StartNew(() =>
|
98
|
|
- new HttpResponseMessage(statusCode), cancellationToken);
|
|
94
|
+ var resp = request.CreateErrorResponse(HttpStatusCode.Unauthorized, error.PublicDetails);
|
|
95
|
+ return Task<HttpResponseMessage>.Factory.StartNew(() => resp, cancellationToken);
|
99
|
96
|
}
|
100
|
97
|
}
|
101
|
98
|
}
|