use of com.dropbox.core.DbxOAuth1AccessToken in project dropbox-sdk-java by dropbox.
the class Main method main.
public static void main(String[] args) throws IOException {
// Only display important log messages.
Logger.getLogger("").setLevel(Level.INFO);
Config cfg = parseArgs(args);
if (cfg == null) {
System.exit(1);
return;
}
// Read app info file (contains app key and app secret)
DbxAppInfo appInfo;
try {
appInfo = DbxAppInfo.Reader.readFromFile(cfg.appInfoFile);
} catch (JsonReader.FileLoadException ex) {
System.err.println("Error reading <app-info-file>: " + ex.getMessage());
System.exit(1);
return;
}
DbxOAuth1AccessToken oauth1AccessToken = new DbxOAuth1AccessToken(cfg.accessTokenKey, cfg.accessTokenSecret);
// Get an OAuth 2 access token.
DbxRequestConfig requestConfig = new DbxRequestConfig("examples-authorize");
DbxOAuth1Upgrader upgrader = new DbxOAuth1Upgrader(requestConfig, appInfo);
String oauth2AccessToken;
try {
oauth2AccessToken = upgrader.createOAuth2AccessToken(oauth1AccessToken);
} catch (DbxException ex) {
System.err.println("Error getting OAuth 2 access token: " + ex.getMessage());
System.exit(1);
return;
}
System.out.println("OAuth 2 access token obtained.");
DbxAuthInfo authInfo = new DbxAuthInfo(oauth2AccessToken, appInfo.getHost());
DbxAuthInfo.Writer.writeToStream(authInfo, System.out);
System.out.println();
// Disable the OAuth 1 access token.
if (cfg.disable) {
try {
upgrader.disableOAuth1AccessToken(oauth1AccessToken);
} catch (DbxException ex) {
System.err.println("Error disabling OAuth 1 access token: " + ex.getMessage());
System.exit(1);
return;
}
System.out.println("OAuth 1 access token disabled.");
}
}
use of com.dropbox.core.DbxOAuth1AccessToken in project keepass2android by PhilippC.
the class DropboxV2Storage method onResume.
@Override
public void onResume(final FileStorageSetupActivity activity) {
if (activity.getProcessName().equals(PROCESS_NAME_SELECTFILE))
activity.getState().putString(EXTRA_PATH, activity.getPath());
Log.d("KP2AJ", "OnResume (3). LoggedIn=" + mLoggedIn);
/*if (mLoggedIn)
{
finishActivityWithSuccess(activity);
return;
}*/
final String[] storedV1Keys = getKeysV1();
if (storedV1Keys != null) {
new AsyncTask<Object, Object, Object>() {
@Override
protected Object doInBackground(Object... objects) {
DbxOAuth1AccessToken v1Token = new DbxOAuth1AccessToken(storedV1Keys[0], storedV1Keys[1]);
DbxOAuth1Upgrader upgrader = new DbxOAuth1Upgrader(requestConfig, appInfo);
try {
String v2Token = upgrader.createOAuth2AccessToken(v1Token);
upgrader.disableOAuth1AccessToken(v1Token);
storeKey(v2Token);
return v2Token;
} catch (Exception e) {
e.printStackTrace();
clearKeys();
return null;
}
}
@Override
protected void onPostExecute(Object o) {
if (o != null) {
buildSession();
finishActivityWithSuccess(activity);
} else
resumeGetAuthToken(activity);
}
}.execute();
} else {
resumeGetAuthToken(activity);
}
}
Aggregations