public static CurrentUser GetCurrentUser(this IOwinContext context) { try { var claimsPrincipal = context.Authentication.User; if (claimsPrincipal == null) return CurrentUser.Anonymous; var name = claimsPrincipal.FindFirst(ClaimHeaders.Name); if (name == null) return CurrentUser.Anonymous; var currentUser = new CurrentUser(name.Value); return currentUser; } catch (Exception exception) { Log.Error(exception, "Failed to create current user"); Debugger.Break(); return CurrentUser.Anonymous; } }
static CurrentUser CreateAnonymousUser() { var anonymousUser = new CurrentUser(""); return anonymousUser; }