protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { HttpStatusCode statusCode; string token = null; if (!TryRetrieveToken(request, out token)) { statusCode = HttpStatusCode.Unauthorized; return(Task <HttpResponseMessage> .Factory.StartNew(() => new HttpResponseMessage(statusCode))); } try { if (SecurityTokenValidator.Validate(token, SecurityTokenType.SWT, signingKey, issuer, audience)) { //HttpContext.Current.User = Thread.CurrentPrincipal; } return(base.SendAsync(request, cancellationToken)); } catch (Exception ex) { Trace.TraceWarning("Exception in SWT validation."); Trace.TraceError(ex.Message); statusCode = HttpStatusCode.InternalServerError; } return(Task <HttpResponseMessage> .Factory.StartNew(() => new HttpResponseMessage(statusCode))); }
public bool Authenticate(SecurityTokenType type, string token) { if (container.ContainsKey(SecurityTokenType.NONE.ToString()) && type == SecurityTokenType.NONE) { return true; } if (token != null && container.ContainsKey(type.ToString())) { Tuple<string, string, string> tuple = container[type.ToString()]; return SecurityTokenValidator.Validate(token, type, tuple.Item1, tuple.Item2, tuple.Item3, context); } return false; }