/// <summary> /// Enable: app__NoAccountLocalhost /// </summary> /// <param name="context"></param> public async Task Invoke(HttpContext context) { var isHostLocal = IsLocalhost.IsHostLocalHost(context.Connection.LocalIpAddress, context.Connection.RemoteIpAddress); var isApiCall = context.Request.Path.HasValue && (context.Request.Path.Value.StartsWith("/api") || context.Request.Path.Value.StartsWith("/realtime")); var isFromLogoutCall = context.Request.QueryString.HasValue && context.Request.QueryString.Value.Contains("fromLogout"); if (isHostLocal && !context.User.Identity.IsAuthenticated && !isApiCall && !isFromLogoutCall) { var userManager = (IUserManager)context.RequestServices.GetService(typeof(IUserManager)); var user = userManager.GetUser("email", Identifier); if (user == null) { var newPassword = Convert.ToBase64String( Pbkdf2Hasher.GenerateRandomSalt()); await userManager.SignUpAsync(string.Empty, "email", Identifier, newPassword + newPassword); user = userManager.GetUser("email", Identifier); } await userManager.SignIn(context, user, true); } await _next.Invoke(context); }
public void FromRemote() { Assert.IsFalse(IsLocalhost.IsHostLocalHost(IPAddress.Loopback, IPAddress.Parse("8.8.8.8"))); }
public void OnOfBothNull() { Assert.IsFalse(IsLocalhost.IsHostLocalHost(null, IPAddress.Loopback)); }
public void IpAddressIPv6Loopback() { Assert.IsTrue(IsLocalhost.IsHostLocalHost(IPAddress.IPv6Loopback, IPAddress.IPv6Loopback)); }
public void Null() { Assert.IsFalse(IsLocalhost.IsHostLocalHost(null, null)); }