protected virtual IPrincipal GetPrincipal(HttpRequestMessage request) { if (request == null || request.Headers == null || request.Headers.Authorization == null || !"Basic".Equals(request.Headers.Authorization.Scheme) || string.IsNullOrEmpty((request.Headers.Authorization.Parameter ?? string.Empty).Trim())) { return(null); } var token = JsonConvert.DeserializeObject <SYSAccessToken>(Encoding.UTF8.GetString(Convert.FromBase64String(request.Headers.Authorization.Parameter))); CFContext.SetCurrent(new WebApiContext(request, token)); return(CFContext.User); }