Exemplo n.º 1
0
        /// <summary>
        /// Use this method to authorize the application to SmugMug.
        /// </summary>
        public static async Task <OAuthToken> AuthorizeSmugMug(string apiKey, string secret, AuthenticationOptions options)
        {
            OAuth.OAuthAuthenticator authenticator = new OAuth.OAuthAuthenticator(apiKey, secret);

            string reqTokUrl = authenticator.CreateGetRequestTokenAddress(OAuthGetRequestTokenUrl, HttpMethod.Get.ToString(), NonWebOAuthApplicationCallback);
            string tokens    = await GetResponseContentAsync(reqTokUrl);

            // Figure out which authorization options are requested (if any)
            string authorizationOptions = options == null ? string.Empty : "?" + options.AsQueryString();
            string authorizeUrl         = authenticator.CreateAuthorizeAddress(OAuthAuthorizeUrl + authorizationOptions, tokens);

            Process.Start(authorizeUrl);

            Console.WriteLine("Press [Enter] after you authorized the application and entered the pin provided");
            string pin = Console.ReadLine();

            // Get the request token to exchange for an access token
            authenticator.ParseRequestTokens(tokens, out string reqToken, out string reqTokenSecret);
            string accessTokenUrl = authenticator.CreateGetAccessTokenAddress(OAuthGetAccessTokenUrl, "GET", reqTokenSecret, reqToken, pin);

            string authTokens = GetResponseContentAsync(accessTokenUrl).Result;
            string authToken, authTokenSecret;

            authenticator.ParseRequestTokens(authTokens, out authToken, out authTokenSecret);

            return(new OAuthToken(apiKey, secret, authToken, authTokenSecret));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Use this method to authorize the application to SmugMug.
        /// </summary>
        public static OAuthToken AuthorizeSmugMug(string apiKey, string secret, AuthenticationOptions options)
        {
            OAuth.OAuthAuthenticator authenticator = new OAuth.OAuthAuthenticator(apiKey, secret);

            string reqTokUrl = authenticator.CreateGetRequestTokenAddress(OAuthGetRequestTokenUrl, HttpMethod.Get.ToString(), NonWebOAuthApplicationCallback);
            string tokens    = GetResponseContent(reqTokUrl).Result; // requestClient.GetAsync(reqTokUrl).Result.Content.ReadAsStringAsync().Result;

            // Figure out which authorization options are requested (if any)
            string authorizationOptions = options == null ? string.Empty : "?" + options.AsQueryString();
            string authorizeUrl         = authenticator.CreateAuthorizeAddress(OAuthAuthorizeUrl + authorizationOptions, tokens);

            // Launching the url to authorize the app
            ProcessStartInfo psi = new ProcessStartInfo();

            psi.UseShellExecute = true; // we need to be explicit about this since on Core the default is 'false'
            psi.FileName        = authorizeUrl;
            Process.Start(psi);

            Console.WriteLine("Press [Enter] after you authorized the application and entered the pin provided");
            string pin = Console.ReadLine();

            // Get the request token to exchange for an access token
            string reqToken, reqTokenSecret;

            authenticator.ParseRequestTokens(tokens, out reqToken, out reqTokenSecret);
            string accessTokenUrl = authenticator.CreateGetAccessTokenAddress(OAuthGetAccessTokenUrl, "GET", reqTokenSecret, reqToken, pin);

            string authTokens = GetResponseContent(accessTokenUrl).Result;
            string authToken, authTokenSecret;

            authenticator.ParseRequestTokens(authTokens, out authToken, out authTokenSecret);

            return(new OAuthToken(apiKey, secret, authToken, authTokenSecret));
        }