Ejemplo n.º 1
0
        // Creates a new Dropbox Session or retrives the existing session
        AndroidAuthSession CreateSession()
        {
            var session = new AndroidAuthSession(new AppKeyPair(DropboxCredentials.AppKey, DropboxCredentials.AppSecret));

            GetAuth(session);
            return(session);
        }
Ejemplo n.º 2
0
        static public Boolean WriteDropbox(String AppKey, String AppSecret, String fileNamePath)
        {
            DBFileNamePath = fileNamePath;
            try
            {
                // If the authorizing process has already been started
                if (DBAuthStart)
                {   // Writes to Dropbox must be a thread. Android reuqirement
                    ThreadPool.QueueUserWorkItem(o => writeDB());
                }

                // If the authorizing process has not been done yet
                if (!DBAuthStart)
                {
                    DBAuthStart = true;
                    AppKeyPair         appKeys = new AppKeyPair(AppKey, AppSecret);
                    AndroidAuthSession session = new AndroidAuthSession(appKeys);
                    dropboxApi = new DropboxApi(session);
                    (dropboxApi.Session as AndroidAuthSession).StartOAuth2Authentication(MainActivity.mainContext);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("***** WriteDropbox failed: " + e.ToString());
                System.Diagnostics.Debug.WriteLine("***** DBAuthStart: " + DBAuthStart);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 3
0
        private void StartDropboxAuthActivity()
        {
            AppKeyPair appKeys = new AppKeyPair(AppKey, AppSecret);

            _session    = new AndroidAuthSession(appKeys);
            _dropboxApi = new DropboxApi(_session);
            _session.StartOAuth2Authentication(this);
        }
Ejemplo n.º 4
0
        // Saves the Dropbox Auth token to proferences
        void StoreAuth(AndroidAuthSession session)
        {
            var oauth2AccessToken = session.OAuth2AccessToken;

            if (!string.IsNullOrWhiteSpace(oauth2AccessToken))
            {
                var edit = GetSharedPreferences(DropboxCredentials.PreferencesName, 0).Edit();
                edit.PutString(DropboxCredentials.AppKey, "oauth2:");
                edit.PutString(DropboxCredentials.AppSecret, oauth2AccessToken);
                edit.Commit();
            }
        }
Ejemplo n.º 5
0
        // Retrieves the Dropbox Auth Token saved on preferences
        void GetAuth(AndroidAuthSession session)
        {
            var prefs  = GetSharedPreferences(DropboxCredentials.PreferencesName, 0);
            var key    = prefs.GetString(DropboxCredentials.AppKey, null);
            var secret = prefs.GetString(DropboxCredentials.AppSecret, null);

            if (string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(secret))
            {
                return;
            }

            session.OAuth2AccessToken = secret;
        }
        public static DropboxApi GetDBApi(Context context)
        {
            var appKeys = new AppKeyPair(AppKey, AppSecret);
            AndroidAuthSession session;

            if (PreferenceManager.GetDefaultSharedPreferences(context).Contains(PrefDropboxToken))
            {
                session = new AndroidAuthSession(appKeys,
                    PreferenceManager.GetDefaultSharedPreferences(context).GetString(PrefDropboxToken, ""));
            }
            else
            {
                session = new AndroidAuthSession(appKeys);
            }
            return new DropboxApi(session);
        }
Ejemplo n.º 7
0
        protected override void OnStart()
        {
            base.OnStart();
            AppKeyPair         appKeys = new AppKeyPair(AppKey, AppSecret);
            AndroidAuthSession session = new AndroidAuthSession(appKeys);

            if (File.Exists(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "/" + "dropboxKey.txt"))
            {
                session.OAuth2AccessToken = File.ReadAllText(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "/" + "dropboxKey.txt");
            }
            dropboxApi = new DropboxApi(session);

            if (!File.Exists(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "/" + "dropboxKey.txt"))
            {
                (dropboxApi.Session as AndroidAuthSession).StartOAuth2Authentication(this);
            }
        }
Ejemplo n.º 8
0
		// Saves the Dropbox Auth token to proferences
		void StoreAuth (AndroidAuthSession session)
		{
			var oauth2AccessToken = session.OAuth2AccessToken;

			if (!string.IsNullOrWhiteSpace (oauth2AccessToken)) {
				var edit = GetSharedPreferences (DropboxCredentials.PreferencesName, 0).Edit ();
				edit.PutString (DropboxCredentials.AppKey, "oauth2:");
				edit.PutString (DropboxCredentials.AppSecret, oauth2AccessToken);
				edit.Commit ();
			}
		}
Ejemplo n.º 9
0
		// Retrieves the Dropbox Auth Token saved on preferences
		void GetAuth (AndroidAuthSession session)
		{
			var prefs = GetSharedPreferences (DropboxCredentials.PreferencesName, 0);
			var key = prefs.GetString (DropboxCredentials.AppKey, null);
			var secret = prefs.GetString (DropboxCredentials.AppSecret, null);

			if (string.IsNullOrWhiteSpace (key) || string.IsNullOrWhiteSpace (secret))
				return;
			
			session.OAuth2AccessToken = secret;
		}
Ejemplo n.º 10
0
		// Creates a new Dropbox Session or retrives the existing session
		AndroidAuthSession CreateSession ()
		{
			var session = new AndroidAuthSession (new AppKeyPair (DropboxCredentials.AppKey, DropboxCredentials.AppSecret));
			GetAuth (session);
			return session;
		}