Browse Source

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

factor2
tmoldovan8x8 3 years ago
parent
commit
83a1ee1182
No account linked to committer's email address

+ 1
- 1
android/sdk/build.gradle View File

44
     //noinspection GradleDynamicVersion
44
     //noinspection GradleDynamicVersion
45
     implementation 'org.webkit:android-jsc:+'
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
     implementation 'com.jakewharton.timber:timber:4.7.1'
48
     implementation 'com.jakewharton.timber:timber:4.7.1'
49
     implementation 'com.squareup.duktape:duktape-android:1.3.0'
49
     implementation 'com.squareup.duktape:duktape-android:1.3.0'
50
     implementation 'com.google.code.gson:gson:2.8.6'
50
     implementation 'com.google.code.gson:gson:2.8.6'

+ 11
- 5
android/sdk/src/main/java/org/jitsi/meet/sdk/DropboxModule.java View File

8
 
8
 
9
 import com.dropbox.core.DbxException;
9
 import com.dropbox.core.DbxException;
10
 import com.dropbox.core.DbxRequestConfig;
10
 import com.dropbox.core.DbxRequestConfig;
11
+import com.dropbox.core.android.Auth;
12
+import com.dropbox.core.oauth.DbxCredential;
11
 import com.dropbox.core.v2.DbxClientV2;
13
 import com.dropbox.core.v2.DbxClientV2;
12
 import com.dropbox.core.v2.users.FullAccount;
14
 import com.dropbox.core.v2.users.FullAccount;
13
 import com.dropbox.core.v2.users.SpaceAllocation;
15
 import com.dropbox.core.v2.users.SpaceAllocation;
17
 import com.facebook.react.bridge.Promise;
19
 import com.facebook.react.bridge.Promise;
18
 import com.facebook.react.bridge.ReactApplicationContext;
20
 import com.facebook.react.bridge.ReactApplicationContext;
19
 import com.facebook.react.bridge.ReactContextBaseJavaModule;
21
 import com.facebook.react.bridge.ReactContextBaseJavaModule;
20
-import com.dropbox.core.android.Auth;
21
 import com.facebook.react.bridge.ReactMethod;
22
 import com.facebook.react.bridge.ReactMethod;
22
 import com.facebook.react.bridge.WritableMap;
23
 import com.facebook.react.bridge.WritableMap;
23
 import com.facebook.react.module.annotations.ReactModule;
24
 import com.facebook.react.module.annotations.ReactModule;
66
     @ReactMethod
67
     @ReactMethod
67
     public void authorize(final Promise promise) {
68
     public void authorize(final Promise promise) {
68
         if (isEnabled) {
69
         if (isEnabled) {
69
-            Auth.startOAuth2Authentication(this.getCurrentActivity(), appKey);
70
+            Auth.startOAuth2PKCE(this.getCurrentActivity(), appKey, DbxRequestConfig.newBuilder(clientId).build());
70
             this.promise = promise;
71
             this.promise = promise;
71
         } else {
72
         } else {
72
             promise.reject(
73
             promise.reject(
181
 
182
 
182
     @Override
183
     @Override
183
     public void onHostResume() {
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
             this.promise = null;
194
             this.promise = null;
189
         }
195
         }
190
     }
196
     }

+ 3
- 3
react/features/dropbox/actions.js View File

33
  *
33
  *
34
  * @param {string} token - The new token.
34
  * @param {string} token - The new token.
35
  * @param {string} rToken - The refresh token.
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
  * @returns {{
37
  * @returns {{
38
  *     type: UPDATE_DROPBOX_TOKEN,
38
  *     type: UPDATE_DROPBOX_TOKEN,
39
  *     token: string,
39
  *     token: string,
40
  *     rToken: string,
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
     return {
45
     return {
46
         type: UPDATE_DROPBOX_TOKEN,
46
         type: UPDATE_DROPBOX_TOKEN,
47
         token,
47
         token,

+ 12
- 8
react/features/dropbox/functions.native.js View File

7
 /**
7
 /**
8
  * Action to authorize the Jitsi Recording app in dropbox.
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
  * access token or rejected with an error.
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 View File

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
  * @param {number} expiresIn - The seconds in which the token expires.
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
  *
42
  *
43
  * @param {string} appKey - The Jitsi Recorder dropbox app key.
43
  * @param {string} appKey - The Jitsi Recorder dropbox app key.
44
  * @param {string} redirectURI - The return URL.
44
  * @param {string} redirectURI - The return URL.
45
- * @returns {Promise<string>}
45
+ * @returns {Promise<Object>}
46
  */
46
  */
47
 export function _authorizeDropbox(
47
 export function _authorizeDropbox(
48
         appKey: string,
48
         appKey: string,
62
             return {
62
             return {
63
                 token: resp.result.access_token,
63
                 token: resp.result.access_token,
64
                 rToken: resp.result.refresh_token,
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
             return {
85
             return {
86
                 token: dropbox.getAccessToken(),
86
                 token: dropbox.getAccessToken(),
87
                 rToken: dropbox.getRefreshToken(),
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 View File

58
     _rToken: string,
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
      * The dropbox access token.
66
      * The dropbox access token.
350
  *     _fileRecordingsServiceSharingEnabled: boolean,
350
  *     _fileRecordingsServiceSharingEnabled: boolean,
351
  *     _isDropboxEnabled: boolean,
351
  *     _isDropboxEnabled: boolean,
352
  *     _rToken:string,
352
  *     _rToken:string,
353
- *     _tokenExpireDate: string,
353
+ *     _tokenExpireDate: number,
354
  *     _token: string
354
  *     _token: string
355
  * }}
355
  * }}
356
  */
356
  */

Loading…
Cancel
Save