Beispiel #1
0
        public static string GetOtp(string deviceId)
        {
            var otp = RandomGenerator.GenerateString(16);

            OtpCache.Set(otp, deviceId, TimeSpan.FromMinutes(1));
            return(otp);
        }
Beispiel #2
0
 public static bool OtpMatchesDevice(string otp, string deviceId)
 {
     if (OtpCache.TryGetValue(otp, out string cachedDevice) &&
         cachedDevice == deviceId)
     {
         return(true);
     }
     return(false);
 }
Beispiel #3
0
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            if (!AppConfig.RemoteControlRequiresAuthentication)
            {
                return;
            }

            if (context.HttpContext.User.Identity.IsAuthenticated)
            {
                return;
            }

            if (context.HttpContext.Request.Query.TryGetValue("otp", out var otp) &&
                OtpCache.TryGetValue(otp.ToString(), out _))
            {
                return;
            }

            context.Result = new RedirectToPageResult("/Account/Login", new { area = "Identity" });
        }