Ejemplo n.º 1
0
        private void buttonAuthenticate_Click(object sender, EventArgs e)
        {
            if (config == null)
            {
                // get the config of dropbox
                config =
                    CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox) as
                    Dropbox.DropBoxConfiguration;

                // set your own callback which will be called from Dropbox after successful
                // authorization
                config.AuthorizationCallBack = new Uri("http://getgreenshot.org/");

                // create a request token
                requestToken =
                    Dropbox.DropBoxStorageProviderTools.GetDropBoxRequestToken(config,
                                                                               DropboxUtils.DROPBOX_APP_KEY,
                                                                               DropboxUtils.DROPBOX_APP_SECRET);

                // call the authorization url via WebBrowser Plugin
                String AuthorizationUrl =
                    Dropbox.DropBoxStorageProviderTools.GetDropBoxAuthorizationUrl(config, requestToken);

                System.Diagnostics.Process.Start(AuthorizationUrl);
            }
            else
            {
                // create the access token
                AuthToken = Dropbox.DropBoxStorageProviderTools.ExchangeDropBoxRequestTokenIntoAccessToken(config,
                                                                                                           DropboxUtils.DROPBOX_APP_KEY, DropboxUtils.DROPBOX_APP_SECRET, requestToken);
                requestToken = null;
            }
        }
 /// <summary>
 /// This method builds derived from the request token a valid authorization url which can be used
 /// for web applications
 /// </summary>
 /// <param name="configuration"></param>
 /// <param name="DropBoxRequestToken"></param>
 /// <returns></returns>
 public static String GetDropBoxAuthorizationUrl(DropBoxConfiguration configuration, DropBoxRequestToken DropBoxRequestToken)
 {
     // build the auth url
     return OAuthUrlGenerator.GenerateAuthorizationUrl(configuration.AuthorizationTokenUrl.ToString(),
                                                       configuration.AuthorizationCallBack.ToString(),
                                                       DropBoxRequestToken.RealToken);
 }
        private static object GetRealToken(DropBoxRequestToken dropBoxRequestToken)
        {
            if (_getRealTokenFieldInfo == null)
            {
                _getRealTokenFieldInfo = dropBoxRequestToken
                    .GetType()
                    .GetField("RealToken", BindingFlags.Instance | BindingFlags.NonPublic);
            }

            var realToken = _getRealTokenFieldInfo.GetValue(dropBoxRequestToken);

            return realToken;
        }
Ejemplo n.º 4
0
        void ButtonOKClick(object sender, EventArgs e)
        {
            if (config != null && requestToken != null)
            {
                // create the access token
                AuthToken = Dropbox.DropBoxStorageProviderTools.ExchangeDropBoxRequestTokenIntoAccessToken(config,
                                                                                                           DropboxUtils.DROPBOX_APP_KEY, DropboxUtils.DROPBOX_APP_SECRET, requestToken);
                requestToken = null;

                this.DialogResult = DialogResult.OK;
            }
            else
            {
                this.DialogResult = DialogResult.OK;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Starts the token exchange process
        /// </summary>
        private void Authenticate()
        {
            // 0. reset token
            _GeneratedToken = null;

            // 1. modify dropbox configuration
            _UsedConfig.APIVersion = DropBoxAPIVersion.V1;

            // 2. get the request token
            _CurrentRequestToken = DropBoxStorageProviderTools.GetDropBoxRequestToken(_UsedConfig, appKey, appSecret);

            if (_CurrentRequestToken == null)
            {
                MessageBox.Show("Can't get request token. Check Application Key & Secret values.");
                return;
            }

            // 3. get the authorization url
            var authUrl = DropBoxStorageProviderTools.GetDropBoxAuthorizationUrl(_UsedConfig, _CurrentRequestToken);

            // 4. navigate to the AuthUrl
            wcAuthenticate.Navigate(authUrl);
        }
        /// <summary>
        /// This method is able to exchange the request token into an access token which can be used in 
        /// sharpbox. It is necessary that the user validated the request via authorization url otherwise 
        /// this call wil results in an unauthorized exception!
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="ConsumerKey"></param>
        /// <param name="ConsumerSecret"></param>
        /// <param name="DropBoxRequestToken"></param>
        /// <returns></returns>
        public static ICloudStorageAccessToken ExchangeDropBoxRequestTokenIntoAccessToken(DropBoxConfiguration configuration, String ConsumerKey, String ConsumerSecret, DropBoxRequestToken DropBoxRequestToken)
        {
            // build the consumer context
            var consumerContext = new OAuthConsumerContext(ConsumerKey, ConsumerSecret);

            // build up the oauth session
            var serviceContext = new OAuthServiceContext(configuration.RequestTokenUrl.ToString(),
                                                         configuration.AuthorizationTokenUrl.ToString(), configuration.AuthorizationCallBack.ToString(),
                                                         configuration.AccessTokenUrl.ToString());

            // build the access token
            var svc = new OAuthService();
            var accessToken = svc.GetAccessToken(serviceContext, consumerContext, DropBoxRequestToken.RealToken);
            if (accessToken == null)
                throw new UnauthorizedAccessException();

            // create the access token 
            return new DropBoxToken(accessToken,
                                    new DropBoxBaseTokenInformation
                                        {
                                            ConsumerKey = ConsumerKey,
                                            ConsumerSecret = ConsumerSecret
                                        });
        }
        /// <summary>
        /// This method is able to exchange the request token into an access token which can be used in
        /// sharpbox. It is necessary that the user validated the request via authorization url otherwise
        /// this call wil results in an unauthorized exception!
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="ConsumerKey"></param>
        /// <param name="ConsumerSecret"></param>
        /// <param name="DropBoxRequestToken"></param>
        /// <returns></returns>
        static public ICloudStorageAccessToken ExchangeDropBoxRequestTokenIntoAccessToken(DropBoxConfiguration configuration, String ConsumerKey, String ConsumerSecret, DropBoxRequestToken DropBoxRequestToken)
        {
            // build the consumer context
            var consumerContext = new OAuthConsumerContext(ConsumerKey, ConsumerSecret);

            // build up the oauth session
            var serviceContext = new OAuthServiceContext(configuration.RequestTokenUrl.ToString(),
                                                         configuration.AuthorizationTokenUrl.ToString(), configuration.AuthorizationCallBack.ToString(),
                                                         configuration.AccessTokenUrl.ToString());

            // build the access token
            OAuthService svc         = new OAuthService();
            OAuthToken   accessToken = svc.GetAccessToken(serviceContext, consumerContext, DropBoxRequestToken.RealToken);

            if (accessToken == null)
            {
                throw new UnauthorizedAccessException();
            }

            // create the access token
            return(new DropBoxToken(accessToken,
                                    new DropBoxBaseTokenInformation()
            {
                ConsumerKey = ConsumerKey,
                ConsumerSecret = ConsumerSecret
            }));
        }
 /// <summary>
 /// This method builds derived from the request token a valid authorization url which can be used
 /// for web applications
 /// </summary>
 /// <param name="configuration"></param>
 /// <param name="DropBoxRequestToken"></param>
 /// <returns></returns>
 static public String GetDropBoxAuthorizationUrl(DropBoxConfiguration configuration, DropBoxRequestToken DropBoxRequestToken)
 {
     // build the auth url
     return(OAuthUrlGenerator.GenerateAuthorizationUrl(configuration.AuthorizationTokenUrl.ToString(),
                                                       configuration.AuthorizationCallBack.ToString(),
                                                       DropBoxRequestToken.RealToken));
 }
        void ButtonOKClick(object sender, EventArgs e)
        {
            if (config != null && requestToken !=null)
            {
                // create the access token
                AuthToken = Dropbox.DropBoxStorageProviderTools.ExchangeDropBoxRequestTokenIntoAccessToken(config,
            DropboxUtils.DROPBOX_APP_KEY, DropboxUtils.DROPBOX_APP_SECRET, requestToken);
                requestToken = null;

                this.DialogResult = DialogResult.OK;
            }
            else
            {
                this.DialogResult = DialogResult.OK;
            }
        }
Ejemplo n.º 10
0
        private void buttonAuthenticate_Click(object sender, EventArgs e)
        {
            if (config == null)
            {
                // get the config of dropbox
                config =
                CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox) as
                Dropbox.DropBoxConfiguration;

                // set your own callback which will be called from Dropbox after successful
                // authorization
                config.AuthorizationCallBack = new Uri("http://getgreenshot.org/");

                // create a request token
                requestToken =
                Dropbox.DropBoxStorageProviderTools.GetDropBoxRequestToken(config,
                DropboxUtils.DROPBOX_APP_KEY,
                DropboxUtils.DROPBOX_APP_SECRET);

                // call the authorization url via WebBrowser Plugin
                String AuthorizationUrl =
                Dropbox.DropBoxStorageProviderTools.GetDropBoxAuthorizationUrl(config, requestToken);

                System.Diagnostics.Process.Start(AuthorizationUrl);
            }
            else
            {
                 // create the access token
                AuthToken = Dropbox.DropBoxStorageProviderTools.ExchangeDropBoxRequestTokenIntoAccessToken(config,
            DropboxUtils.DROPBOX_APP_KEY, DropboxUtils.DROPBOX_APP_SECRET, requestToken);
                requestToken = null;
            }
        }