Пример #1
0
        static void Main(string[] args)
        {
            int port = 8080;

            if (args.Length > 0)
            {
                if (!int.TryParse(args[0], out port))
                {
                    Console.WriteLine("Reddit.NET OAuth Token Retriever");
                    Console.WriteLine("Created by Kris Craig");

                    Console.WriteLine();

                    Console.WriteLine("Usage:  AuthTokenRetriever [port] [App ID [App Secret]]");

                    Environment.Exit(Environment.ExitCode);
                }
            }

            string appId     = (args.Length >= 2 ? args[1] : null);
            string appSecret = (args.Length >= 3 ? args[2] : null);

            // If appId and appSecret are unspecified, use guided mode.  --Kris
            if (string.IsNullOrWhiteSpace(appId) && string.IsNullOrWhiteSpace(appSecret))
            {
                if (string.IsNullOrWhiteSpace(appId))
                {
                    Console.Write("App ID: ");
                    appId = Console.ReadLine();
                }

                Console.Write("App Secret (leave blank for 'installed'-type apps): ");
                appSecret = Console.ReadLine();

                Console.WriteLine();
                Console.WriteLine("** IMPORTANT:  Before you proceed any further, make sure you are logged into Reddit as the user you wish to authenticate! **");
                Console.WriteLine();

                Console.WriteLine("In the next step, a browser window will open and you'll be taken to Reddit's app authentication page.  Press any key to continue....");
                Console.ReadKey();
            }

            // Create a new instance of the auth token retrieval library.  --Kris
            AuthTokenRetrieverLib authTokenRetrieverLib = new AuthTokenRetrieverLib(appId, appSecret, port);

            // Start the callback listener.  --Kris
            authTokenRetrieverLib.AwaitCallback();

            // Clearning the Console causes an IO exception whilst running a non-console application, which in turn crashes uHttpSharp. --Adam
            // Console.Clear();  // Gets rid of that annoying logging exception message generated by the uHttpSharp library.  --Kris

            // Open the browser to the Reddit authentication page.  Once the user clicks "accept", Reddit will redirect the browser to localhost:8080, where AwaitCallback will take over.  --Kris
            OpenBrowser(authTokenRetrieverLib.AuthURL());

            Console.ReadKey();  // Hit any key to exit.  --Kris

            authTokenRetrieverLib.StopListening();

            Console.WriteLine("Token retrieval utility terminated.");
        }
Пример #2
0
        public static string AuthorizeUser(string appId, string appSecret = null, int port = 8080)
        {
            // Create a new instance of the auth token retrieval library.  --Kris
            AuthTokenRetrieverLib authTokenRetrieverLib = new AuthTokenRetrieverLib(appId, appSecret, port);

            // Start the callback listener.
            authTokenRetrieverLib.AwaitCallback();

            // Open the browser to the Reddit authentication page.  Once the user clicks "accept", Reddit will redirect the browser to localhost:8080, where AwaitCallback will take over.
            OpenBrowser(authTokenRetrieverLib.AuthURL());

            while (true)
            {
            }

            // Cleanup.
            authTokenRetrieverLib.StopListening();

            return(authTokenRetrieverLib.RefreshToken);
        }
Пример #3
0
        static void Main(string[] args)
        {
            string appId     = (args.Length >= 1 ? args[0] : null);
            string appSecret = (args.Length >= 2 ? args[1] : null);

            // Create a new instance of the auth token retrieval library.  --Kris
            AuthTokenRetrieverLib authTokenRetrieverLib = new AuthTokenRetrieverLib(appId, appSecret, 8080);

            // Start the callback listener.  --Kris
            authTokenRetrieverLib.AwaitCallback();
            Console.Clear();  // Gets rid of that annoying logging exception message generated by the uHttpSharp library.  --Kris

            // Open the browser to the Reddit authentication page.  Once the user clicks "accept", Reddit will redirect the browser to localhost:8080, where AwaitCallback will take over.  --Kris
            OpenBrowser(authTokenRetrieverLib.AuthURL());

            Console.ReadKey();  // Hit any key to exit.  --Kris

            authTokenRetrieverLib.StopListening();

            Console.WriteLine("Token retrieval utility terminated.");
        }