Преглед на файлове

task(rn, android): update dropbox logic to retrieve refresh token

factor2
tmoldovan8x8 преди 3 години
родител
ревизия
83a1ee1182
No account linked to committer's email address

+ 1
- 1
android/sdk/build.gradle Целия файл

@@ -44,7 +44,7 @@ dependencies {
44 44
     //noinspection GradleDynamicVersion
45 45
     implementation 'org.webkit:android-jsc:+'
46 46
 
47
-    implementation 'com.dropbox.core:dropbox-core-sdk:3.0.8'
47
+    implementation 'com.dropbox.core:dropbox-core-sdk:4.0.1'
48 48
     implementation 'com.jakewharton.timber:timber:4.7.1'
49 49
     implementation 'com.squareup.duktape:duktape-android:1.3.0'
50 50
     implementation 'com.google.code.gson:gson:2.8.6'

+ 11
- 5
android/sdk/src/main/java/org/jitsi/meet/sdk/DropboxModule.java Целия файл

@@ -8,6 +8,8 @@ import android.text.TextUtils;
8 8
 
9 9
 import com.dropbox.core.DbxException;
10 10
 import com.dropbox.core.DbxRequestConfig;
11
+import com.dropbox.core.android.Auth;
12
+import com.dropbox.core.oauth.DbxCredential;
11 13
 import com.dropbox.core.v2.DbxClientV2;
12 14
 import com.dropbox.core.v2.users.FullAccount;
13 15
 import com.dropbox.core.v2.users.SpaceAllocation;
@@ -17,7 +19,6 @@ import com.facebook.react.bridge.LifecycleEventListener;
17 19
 import com.facebook.react.bridge.Promise;
18 20
 import com.facebook.react.bridge.ReactApplicationContext;
19 21
 import com.facebook.react.bridge.ReactContextBaseJavaModule;
20
-import com.dropbox.core.android.Auth;
21 22
 import com.facebook.react.bridge.ReactMethod;
22 23
 import com.facebook.react.bridge.WritableMap;
23 24
 import com.facebook.react.module.annotations.ReactModule;
@@ -66,7 +67,7 @@ class DropboxModule
66 67
     @ReactMethod
67 68
     public void authorize(final Promise promise) {
68 69
         if (isEnabled) {
69
-            Auth.startOAuth2Authentication(this.getCurrentActivity(), appKey);
70
+            Auth.startOAuth2PKCE(this.getCurrentActivity(), appKey, DbxRequestConfig.newBuilder(clientId).build());
70 71
             this.promise = promise;
71 72
         } else {
72 73
             promise.reject(
@@ -181,10 +182,15 @@ class DropboxModule
181 182
 
182 183
     @Override
183 184
     public void onHostResume() {
184
-        String token = Auth.getOAuth2Token();
185
+        DbxCredential credential = Auth.getDbxCredential();
186
+
187
+        if (credential != null && this.promise != null) {
188
+            WritableMap result = Arguments.createMap();
189
+            result.putString("token", credential.getAccessToken());
190
+            result.putString("rToken", credential.getRefreshToken());
191
+            result.putDouble("expireDate", credential.getExpiresAt());
185 192
 
186
-        if (token != null && this.promise != null) {
187
-            this.promise.resolve(token);
193
+            this.promise.resolve(result);
188 194
             this.promise = null;
189 195
         }
190 196
     }

+ 3
- 3
react/features/dropbox/actions.js Целия файл

@@ -33,15 +33,15 @@ export function authorizeDropbox() {
33 33
  *
34 34
  * @param {string} token - The new token.
35 35
  * @param {string} rToken - The refresh token.
36
- * @param {string} expireDate - The token expiration date as ISO string.
36
+ * @param {number} expireDate - The token expiration date as UNIX timestamp.
37 37
  * @returns {{
38 38
  *     type: UPDATE_DROPBOX_TOKEN,
39 39
  *     token: string,
40 40
  *     rToken: string,
41
- *     expireDate: string
41
+ *     expireDate: number
42 42
  * }}
43 43
  */
44
-export function updateDropboxToken(token: string, rToken: string, expireDate: string) {
44
+export function updateDropboxToken(token: string, rToken: string, expireDate: number) {
45 45
     return {
46 46
         type: UPDATE_DROPBOX_TOKEN,
47 47
         token,

+ 12
- 8
react/features/dropbox/functions.native.js Целия файл

@@ -7,16 +7,20 @@ const { Dropbox } = NativeModules;
7 7
 /**
8 8
  * Action to authorize the Jitsi Recording app in dropbox.
9 9
  *
10
- * @param {string} appKey - The Jitsi Recorder dropbox app key.
11
- * @param {string} redirectURI - The return URL.
12
- * @returns {Promise<string>} - The promise will be resolved with the dropbox
10
+ * @returns {Promise<Object>} - The promise will be resolved with the dropbox
13 11
  * access token or rejected with an error.
14 12
  */
15
-export function _authorizeDropbox(): Promise<string> {
16
-    return Dropbox.authorize()
17
-        .then(token => {
18
-            return { token };
19
-        });
13
+export function _authorizeDropbox(): Promise<Object> {
14
+    return Dropbox.authorize();
15
+}
16
+
17
+/**
18
+ * Gets a new acccess token based on the refresh token.
19
+ *
20
+ * @returns {Promise}
21
+ */
22
+export function getNewAccessToken() {
23
+    return _authorizeDropbox();
20 24
 }
21 25
 
22 26
 /**

+ 7
- 7
react/features/dropbox/functions.web.js Целия файл

@@ -28,13 +28,13 @@ function authorize(authUrl: string): Promise<string> {
28 28
 }
29 29
 
30 30
 /**
31
- * Returns the token's expiry date as ISO string.
31
+ * Returns the token's expiry date as UNIX timestamp.
32 32
  *
33 33
  * @param {number} expiresIn - The seconds in which the token expires.
34
- * @returns {string} - The ISO value for the expiry date.
34
+ * @returns {number} - The timestamp value for the expiry date.
35 35
  */
36
-function getTokenExpiresAtDate(expiresIn: number) {
37
-    return new Date(Date.now() + (expiresIn * 1000)).toISOString();
36
+function getTokenExpiresAtTimestamp(expiresIn: number) {
37
+    return new Date(Date.now() + (expiresIn * 1000)).getTime();
38 38
 }
39 39
 
40 40
 /**
@@ -42,7 +42,7 @@ function getTokenExpiresAtDate(expiresIn: number) {
42 42
  *
43 43
  * @param {string} appKey - The Jitsi Recorder dropbox app key.
44 44
  * @param {string} redirectURI - The return URL.
45
- * @returns {Promise<string>}
45
+ * @returns {Promise<Object>}
46 46
  */
47 47
 export function _authorizeDropbox(
48 48
         appKey: string,
@@ -62,7 +62,7 @@ export function _authorizeDropbox(
62 62
             return {
63 63
                 token: resp.result.access_token,
64 64
                 rToken: resp.result.refresh_token,
65
-                expireDate: getTokenExpiresAtDate(resp.result.expires_in)
65
+                expireDate: getTokenExpiresAtTimestamp(resp.result.expires_in)
66 66
             };
67 67
         });
68 68
 }
@@ -85,7 +85,7 @@ export function getNewAccessToken(appKey: string, rToken: string) {
85 85
             return {
86 86
                 token: dropbox.getAccessToken(),
87 87
                 rToken: dropbox.getRefreshToken(),
88
-                expireDate: dropbox.getAccessTokenExpiresAt().toISOString()
88
+                expireDate: dropbox.getAccessTokenExpiresAt().getTime()
89 89
             };
90 90
         });
91 91
 }

+ 3
- 3
react/features/recording/components/Recording/AbstractStartRecordingDialog.js Целия файл

@@ -58,9 +58,9 @@ type Props = {
58 58
     _rToken: string,
59 59
 
60 60
     /**
61
-     * Access token's expiration date as ISO string.
61
+     * Access token's expiration date as UNIX timestamp.
62 62
      */
63
-    _tokenExpireDate?: string,
63
+    _tokenExpireDate?: number,
64 64
 
65 65
     /**
66 66
      * The dropbox access token.
@@ -350,7 +350,7 @@ class AbstractStartRecordingDialog extends Component<Props, State> {
350 350
  *     _fileRecordingsServiceSharingEnabled: boolean,
351 351
  *     _isDropboxEnabled: boolean,
352 352
  *     _rToken:string,
353
- *     _tokenExpireDate: string,
353
+ *     _tokenExpireDate: number,
354 354
  *     _token: string
355 355
  * }}
356 356
  */

Loading…
Отказ
Запис