-
Notifications
You must be signed in to change notification settings - Fork 16
/
AuthenticationFailureResult.cs
45 lines (35 loc) · 1.21 KB
/
AuthenticationFailureResult.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http;
using Newtonsoft.Json;
namespace D2L.Security.OAuth2.Authentication {
public sealed class AuthenticationFailureResult : IHttpActionResult {
private readonly Exception m_exception;
public AuthenticationFailureResult( Exception exception ) {
m_exception = exception;
}
public Task<HttpResponseMessage> ExecuteAsync( CancellationToken cancellationToken ) {
var response = new HttpResponseMessage( HttpStatusCode.Unauthorized );
response.Content = new ObjectContent<Response>(
new Response {
},
new JsonMediaTypeFormatter(),
"application/problem+json"
);
return Task.FromResult( response );
}
// See https://tools.ietf.org/html/draft-nottingham-http-problem-06
private sealed class Response {
[JsonProperty("title")]
public string Title { get { return "Authentication required"; } }
[JsonProperty( "status" )]
public long Status { get { return (long)HttpStatusCode.Unauthorized; } }
[JsonProperty( "detail" )]
public string Detail { get; set; }
}
}
}