コード例 #1
0
ファイル: DuoVerify.cs プロジェクト: mayitoeb/duo_api_csharp
    static int Main(string[] args)
    {
        if (args.Length < 4)
        {
            System.Console.WriteLine("Usage: <integration key> <secret key> <integration host> <E.164-formatted phone number>");
            return(1);
        }
        string ikey       = args[0];
        string skey       = args[1];
        string host       = args[2];
        string phone      = args[3];
        var    client     = new Duo.DuoApi(ikey, skey, host);
        var    parameters = new Dictionary <string, string>();

        parameters["phone"]   = phone;
        parameters["message"] = "The PIN is <pin>";

        // Start a call
        var r = client.JSONApiCall <Dictionary <string, object> >(
            "POST", "/verify/v1/call", parameters);

        // Get the transaction ID from the response.
        if (!r.ContainsKey("txid"))
        {
            System.Console.WriteLine("Could not send PIN!");
            return(1);
        }

        // Poll the txid for the status of the transaction.
        System.Console.WriteLine("The PIN is " + r["pin"]);
        parameters.Clear();
        parameters["txid"] = r["txid"] as String;
        String state;

        do
        {
            var status_res =
                client.JSONApiCall <Dictionary <string, object> >(
                    "GET", "/verify/v1/status", parameters);
            state = status_res["state"] as String;
            System.Console.WriteLine(status_res["info"]);
        } while (state != "ended");

        return(0);
    }
コード例 #2
0
    static int Main(string[] args)
    {
        if (args.Length < 4)
        {
            System.Console.WriteLine("Usage: <integration key> <secret key> <integration host> <E.164-formatted phone number>");
            return 1;
        }
        string ikey = args[0];
        string skey = args[1];
        string host = args[2];
        string phone = args[3];
        var client = new Duo.DuoApi(ikey, skey, host);
        var parameters = new Dictionary<string, string>();
        parameters["phone"] = phone;
        parameters["message"] = "The PIN is <pin>";

        // Start a call
        var r = client.JSONApiCall<Dictionary<string, object>>(
            "POST", "/verify/v1/call", parameters);

        // Get the transaction ID from the response.
        if (! r.ContainsKey("txid"))
        {
            System.Console.WriteLine("Could not send PIN!");
            return 1;
        }

        // Poll the txid for the status of the transaction.
        System.Console.WriteLine("The PIN is " + r["pin"]);
        parameters.Clear();
        parameters["txid"] = r["txid"] as String;
        String state;
        do
        {
            var status_res =
                client.JSONApiCall<Dictionary<string, object>>(
            "GET", "/verify/v1/status", parameters);
            state = status_res["state"] as String;
            System.Console.WriteLine(status_res["info"]);
        } while (state != "ended");

        return 0;
    }
コード例 #3
0
ファイル: DuoAdmin.cs プロジェクト: mayitoeb/duo_api_csharp
    static int Main(string[] args)
    {
        if (args.Length < 3)
        {
            System.Console.WriteLine("Usage: <integration key> <secret key> <integration host>");
            return(1);
        }
        string ikey       = args[0];
        string skey       = args[1];
        string host       = args[2];
        var    client     = new Duo.DuoApi(ikey, skey, host);
        var    parameters = new Dictionary <string, string>();
        var    r          = client.JSONApiCall <Dictionary <string, object> >(
            "GET", "/admin/v1/info/authentication_attempts", parameters);
        var attempts = r["authentication_attempts"] as Dictionary <string, object>;

        foreach (KeyValuePair <string, object> info in attempts)
        {
            var s = String.Format("{0} authentication(s) ended with {1}.",
                                  info.Value,
                                  info.Key);
            System.Console.WriteLine(s);
        }

        // /admin/v1/users returns a JSON Array instead of an object.
        var users = client.JSONApiCall <System.Collections.ArrayList>(
            "GET", "/admin/v1/users", parameters);

        System.Console.WriteLine(String.Format("{0} users.", users.Count));
        foreach (Dictionary <string, object> user in users)
        {
            System.Console.WriteLine(
                "\t" + "Username: "******"username"] as string));
        }

        return(0);
    }
コード例 #4
0
    static int Main(string[] args)
    {
        if (args.Length < 3)
        {
            System.Console.WriteLine("Usage: <integration key> <secret key> <integration host>");
            return 1;
        }
        string ikey = args[0];
        string skey = args[1];
        string host = args[2];
        var client = new Duo.DuoApi(ikey, skey, host);
        var parameters = new Dictionary<string, string>();
        var r = client.JSONApiCall<Dictionary<string, object>>(
            "GET", "/admin/v1/info/authentication_attempts", parameters);
        var attempts = r["authentication_attempts"] as Dictionary<string, object>;
        foreach (KeyValuePair<string, object> info in attempts) {
            var s = String.Format("{0} authentication(s) ended with {1}.",
                                  info.Value,
                                  info.Key);
            System.Console.WriteLine(s);
        }

        return 0;
    }
コード例 #5
0
    static int Main(string[] args)
    {
        if (args.Length < 3)
        {
            System.Console.WriteLine("Usage: <integration key> <secret key> <integration host>");
            return(1);
        }
        string ikey       = args[0];
        string skey       = args[1];
        string host       = args[2];
        var    client     = new Duo.DuoApi(ikey, skey, host);
        var    parameters = new Dictionary <string, string>();
        var    r          = client.JSONApiCall <Dictionary <string, object> >(
            "GET", "/admin/v1/info/authentication_attempts", parameters);
        var attempts = r["authentication_attempts"] as Dictionary <string, object>;

        foreach (KeyValuePair <string, object> info in attempts)
        {
            var s = String.Format("{0} authentication(s) ended with {1}.",
                                  info.Value,
                                  info.Key);
            System.Console.WriteLine(s);
        }

        // /admin/v1/users returns a JSON Array instead of an object.
        var users = client.JSONApiCall <System.Collections.ArrayList>(
            "GET", "/admin/v1/users", parameters);

        System.Console.WriteLine(String.Format("{0} users.", users.Count));
        foreach (Dictionary <string, object> user in users)
        {
            System.Console.WriteLine(
                "\t" + "Username: "******"username"] as string));
        }

        // paging call
        int?offset = 0;

        while (offset != null)
        {
            var jsonResponse = client.JSONPagingApiCall("GET", "/admin/v1/users", parameters, (int)offset, 10);
            var pagedUsers   = jsonResponse["response"] as System.Collections.ArrayList;
            System.Console.WriteLine(String.Format("{0} users at offset {1}", pagedUsers.Count, offset));
            foreach (Dictionary <string, object> user in pagedUsers)
            {
                System.Console.WriteLine(
                    "\t" + "Username: "******"username"] as string));
            }
            var metadata = jsonResponse["metadata"] as Dictionary <string, object>;
            if (metadata.ContainsKey("next_offset"))
            {
                offset = metadata["next_offset"] as int?;
            }
            else
            {
                offset = null;
            }
        }

        return(0);
    }