public async void Auth(string host, string ikey, string skey, string user)
        {
            var config = new DuoAuthConfig(host, ikey, skey);
            var client = new DuoAuthClient(config);
            var res    = await client.AuthPushByUsernameAsync(user);

            var json = res.OriginalJson;

            if (json.Contains("allow"))
            {
                AuthStatus = 1;
            }
            else if (json.Contains("deny"))
            {
                AuthStatus = 2;
            }
            else if (json.Contains("username"))
            {
                AuthStatus = 3;
            }
            else
            {
                AuthStatus = 0;
            }

            AuthCall(AuthStatus);
        }
Exemplo n.º 2
0
        public async Task <bool> AuthenticateUserTwoFactorAsync(string username, string factor, string passcode)
        {
            dynamic stuff;
            // var config = new DuoAuthConfig("host.com", "integrationKey", "secretKey");

            // Instantiate Client
            // var client = new DuoAuthClient(config);
            var client = new DuoAuthClient(duoAuthConfig);


            /*
             * // Check that Duo is online...
             * var response = await client.PingAsync();
             * try {
             *  //{"response": {"time": 1608327739}, "stat": "OK"}
             *  dynamic stuff = JsonConvert.DeserializeObject(response.OriginalJson);
             *  string status = stuff.stat;
             *
             *  if(status.Equals("OK")) {
             *      // Proceed only if server is up here...
             *  }
             * }
             * catch(Exception ex) {
             *
             * }
             */
            if (!String.IsNullOrEmpty(factor))
            {
                if (factor.Equals("Push"))
                {
                    var auth = await client.AuthPushByUsernameAsync(username);

                    stuff = JsonConvert.DeserializeObject(auth.OriginalJson);
                    if (validTwoFactor(stuff))
                    {
                        return(true);
                    }
                }
                if (factor.Equals("Phone"))
                {
                    var auth = await client.AuthPhoneByUsernameAsync(username);

                    stuff = JsonConvert.DeserializeObject(auth.OriginalJson);
                    if (validTwoFactor(stuff))
                    {
                        return(true);
                    }
                }
                if (factor.Equals("Passcode"))
                {
                    var auth = await client.AuthPasscodeByUsernameAsync(username, passcode);

                    stuff = JsonConvert.DeserializeObject(auth.OriginalJson);
                    if (validTwoFactor(stuff))
                    {
                        return(true);
                    }
                }
                if (factor.Equals("SMS"))
                {
                    var auth = await client.AuthSmsByUsernameAsync(username);

                    return(false);
                }
            }



            return(false);
        }