-
Notifications
You must be signed in to change notification settings - Fork 444
/
Auth.java
51 lines (40 loc) · 1.52 KB
/
Auth.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.dropbox.core.android;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
/**
* Helper class for integrating with {@link AuthActivity}
*/
public class Auth {
public static void startOAuth2Authentication(Context context, String appKey) {
if (!AuthActivity.checkAppBeforeAuth(context, appKey, true /*alertUser*/)) {
return;
}
// Start Dropbox auth activity.
String apiType = "1";
String webHost = "www.dropbox.com";
Intent intent = AuthActivity.makeIntent(context, appKey, webHost, apiType);
if (!(context instanceof Activity)) {
// If starting the intent outside of an Activity, must include
// this. See startActivity(). Otherwise, we prefer to stay in
// the same task.
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
context.startActivity(intent);
}
public static String getOAuth2Token() {
Intent data = AuthActivity.result;
if (data == null) {
return null;
}
String token = data.getStringExtra(AuthActivity.EXTRA_ACCESS_TOKEN);
String secret = data.getStringExtra(AuthActivity.EXTRA_ACCESS_SECRET);
String uid = data.getStringExtra(AuthActivity.EXTRA_UID);
if (token != null && !token.equals("") &&
secret != null && !secret.equals("") &&
uid != null && !uid.equals("")) {
return secret;
}
return null;
}
}