示例#1
0
        /// <summary>
        /// If we have a valid access token, "login" to smugmug.
        /// Otherwise authorize the application to smugmug.
        /// </summary>
        /// <param name="mySite"></param>
        /// <param name="accessTok"></param>
        /// <returns></returns>
        private static MyUser AuthorizeToSmugMug(Site mySite)
        {
            //These values should have already been populated
            if (string.IsNullOrEmpty(apiKey) || string.IsNullOrEmpty(secret))
            {
                return(null);
            }

            Token accessTok = new Token()
            {
                id = token, Secret = tokenSecret
            };

            MyUser user = null;

            //if we have a token
            if (!(string.IsNullOrEmpty(token) || string.IsNullOrEmpty(tokenSecret)))
            {
                user = mySite.Login(accessTok);
            }

            // If the token was valid
            if (user == null)
            {
                do
                {
                    // reauthorize
                    accessTok = SmugMugAuthorize.AuthorizeSmugMug(mySite);

                    user = mySite.Login(accessTok);

                    if (user == null)
                    {
                        Console.WriteLine("Authorizing the user failed. Try authorizing again? (hit Y to continue)");
                        if (Console.ReadKey().Key == ConsoleKey.Y)
                        {
                            continue;
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        //save the secrets to the file
                        SmugMugSecretsAccess.SaveSecretsToFile(apiKey, secret, accessTok.id, accessTok.Secret);
                    }
                } while (user == null);
            }

            return(user);
        }
示例#2
0
        /// <summary>
        /// If the secrets are in a file, get them from there. Otherwise, request them (apikey, secret) from the user
        /// </summary>
        private static void GetSmugMugSecrets()
        {
            SmugMugSecretsAccess.ReadSecretsFromFile(out apiKey, out secret, out token, out tokenSecret);

            // Do we have the secret/apikey?
            if (string.IsNullOrEmpty(apiKey) || string.IsNullOrEmpty(secret))
            {
                Console.WriteLine("Please enter your API Key and press [Enter]:");
                apiKey = Console.ReadLine();
                Console.WriteLine("Please enter your Application Secret and press [Enter]:");
                secret = Console.ReadLine();
            }

            Console.WriteLine("Using APIKey={0}", apiKey);
            Console.WriteLine("Using AppSecret={0}", secret);
            Console.WriteLine("Using token={0}", token);
            Console.WriteLine("Using tokenSecret={0}", tokenSecret);
        }