From 83a1ee1182a8aa6ca95b1b618273cf9e6a113c35 Mon Sep 17 00:00:00 2001 From: tmoldovan8x8 <62697631+tmoldovan8x8@users.noreply.github.com> Date: Wed, 1 Sep 2021 15:21:03 +0300 Subject: [PATCH] task(rn, android): update dropbox logic to retrieve refresh token --- android/sdk/build.gradle | 2 +- .../org/jitsi/meet/sdk/DropboxModule.java | 16 ++++++++++----- react/features/dropbox/actions.js | 6 +++--- react/features/dropbox/functions.native.js | 20 +++++++++++-------- react/features/dropbox/functions.web.js | 14 ++++++------- .../Recording/AbstractStartRecordingDialog.js | 6 +++--- 6 files changed, 37 insertions(+), 27 deletions(-) diff --git a/android/sdk/build.gradle b/android/sdk/build.gradle index e10d7f6faa..394240476a 100644 --- a/android/sdk/build.gradle +++ b/android/sdk/build.gradle @@ -44,7 +44,7 @@ dependencies { //noinspection GradleDynamicVersion implementation 'org.webkit:android-jsc:+' - implementation 'com.dropbox.core:dropbox-core-sdk:3.0.8' + implementation 'com.dropbox.core:dropbox-core-sdk:4.0.1' implementation 'com.jakewharton.timber:timber:4.7.1' implementation 'com.squareup.duktape:duktape-android:1.3.0' implementation 'com.google.code.gson:gson:2.8.6' diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/DropboxModule.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/DropboxModule.java index 80f3359143..7bbdea7a14 100644 --- a/android/sdk/src/main/java/org/jitsi/meet/sdk/DropboxModule.java +++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/DropboxModule.java @@ -8,6 +8,8 @@ import android.text.TextUtils; import com.dropbox.core.DbxException; import com.dropbox.core.DbxRequestConfig; +import com.dropbox.core.android.Auth; +import com.dropbox.core.oauth.DbxCredential; import com.dropbox.core.v2.DbxClientV2; import com.dropbox.core.v2.users.FullAccount; import com.dropbox.core.v2.users.SpaceAllocation; @@ -17,7 +19,6 @@ import com.facebook.react.bridge.LifecycleEventListener; import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; -import com.dropbox.core.android.Auth; import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.WritableMap; import com.facebook.react.module.annotations.ReactModule; @@ -66,7 +67,7 @@ class DropboxModule @ReactMethod public void authorize(final Promise promise) { if (isEnabled) { - Auth.startOAuth2Authentication(this.getCurrentActivity(), appKey); + Auth.startOAuth2PKCE(this.getCurrentActivity(), appKey, DbxRequestConfig.newBuilder(clientId).build()); this.promise = promise; } else { promise.reject( @@ -181,10 +182,15 @@ class DropboxModule @Override public void onHostResume() { - String token = Auth.getOAuth2Token(); + DbxCredential credential = Auth.getDbxCredential(); + + if (credential != null && this.promise != null) { + WritableMap result = Arguments.createMap(); + result.putString("token", credential.getAccessToken()); + result.putString("rToken", credential.getRefreshToken()); + result.putDouble("expireDate", credential.getExpiresAt()); - if (token != null && this.promise != null) { - this.promise.resolve(token); + this.promise.resolve(result); this.promise = null; } } diff --git a/react/features/dropbox/actions.js b/react/features/dropbox/actions.js index f3f3a724db..078999043b 100644 --- a/react/features/dropbox/actions.js +++ b/react/features/dropbox/actions.js @@ -33,15 +33,15 @@ export function authorizeDropbox() { * * @param {string} token - The new token. * @param {string} rToken - The refresh token. - * @param {string} expireDate - The token expiration date as ISO string. + * @param {number} expireDate - The token expiration date as UNIX timestamp. * @returns {{ * type: UPDATE_DROPBOX_TOKEN, * token: string, * rToken: string, - * expireDate: string + * expireDate: number * }} */ -export function updateDropboxToken(token: string, rToken: string, expireDate: string) { +export function updateDropboxToken(token: string, rToken: string, expireDate: number) { return { type: UPDATE_DROPBOX_TOKEN, token, diff --git a/react/features/dropbox/functions.native.js b/react/features/dropbox/functions.native.js index e19eedc394..41d12c616d 100644 --- a/react/features/dropbox/functions.native.js +++ b/react/features/dropbox/functions.native.js @@ -7,16 +7,20 @@ const { Dropbox } = NativeModules; /** * Action to authorize the Jitsi Recording app in dropbox. * - * @param {string} appKey - The Jitsi Recorder dropbox app key. - * @param {string} redirectURI - The return URL. - * @returns {Promise} - The promise will be resolved with the dropbox + * @returns {Promise} - The promise will be resolved with the dropbox * access token or rejected with an error. */ -export function _authorizeDropbox(): Promise { - return Dropbox.authorize() - .then(token => { - return { token }; - }); +export function _authorizeDropbox(): Promise { + return Dropbox.authorize(); +} + +/** + * Gets a new acccess token based on the refresh token. + * + * @returns {Promise} + */ +export function getNewAccessToken() { + return _authorizeDropbox(); } /** diff --git a/react/features/dropbox/functions.web.js b/react/features/dropbox/functions.web.js index 06c7118088..da739ceab1 100644 --- a/react/features/dropbox/functions.web.js +++ b/react/features/dropbox/functions.web.js @@ -28,13 +28,13 @@ function authorize(authUrl: string): Promise { } /** - * Returns the token's expiry date as ISO string. + * Returns the token's expiry date as UNIX timestamp. * * @param {number} expiresIn - The seconds in which the token expires. - * @returns {string} - The ISO value for the expiry date. + * @returns {number} - The timestamp value for the expiry date. */ -function getTokenExpiresAtDate(expiresIn: number) { - return new Date(Date.now() + (expiresIn * 1000)).toISOString(); +function getTokenExpiresAtTimestamp(expiresIn: number) { + return new Date(Date.now() + (expiresIn * 1000)).getTime(); } /** @@ -42,7 +42,7 @@ function getTokenExpiresAtDate(expiresIn: number) { * * @param {string} appKey - The Jitsi Recorder dropbox app key. * @param {string} redirectURI - The return URL. - * @returns {Promise} + * @returns {Promise} */ export function _authorizeDropbox( appKey: string, @@ -62,7 +62,7 @@ export function _authorizeDropbox( return { token: resp.result.access_token, rToken: resp.result.refresh_token, - expireDate: getTokenExpiresAtDate(resp.result.expires_in) + expireDate: getTokenExpiresAtTimestamp(resp.result.expires_in) }; }); } @@ -85,7 +85,7 @@ export function getNewAccessToken(appKey: string, rToken: string) { return { token: dropbox.getAccessToken(), rToken: dropbox.getRefreshToken(), - expireDate: dropbox.getAccessTokenExpiresAt().toISOString() + expireDate: dropbox.getAccessTokenExpiresAt().getTime() }; }); } diff --git a/react/features/recording/components/Recording/AbstractStartRecordingDialog.js b/react/features/recording/components/Recording/AbstractStartRecordingDialog.js index 6baf4f79d6..feb2ec36ff 100644 --- a/react/features/recording/components/Recording/AbstractStartRecordingDialog.js +++ b/react/features/recording/components/Recording/AbstractStartRecordingDialog.js @@ -58,9 +58,9 @@ type Props = { _rToken: string, /** - * Access token's expiration date as ISO string. + * Access token's expiration date as UNIX timestamp. */ - _tokenExpireDate?: string, + _tokenExpireDate?: number, /** * The dropbox access token. @@ -350,7 +350,7 @@ class AbstractStartRecordingDialog extends Component { * _fileRecordingsServiceSharingEnabled: boolean, * _isDropboxEnabled: boolean, * _rToken:string, - * _tokenExpireDate: string, + * _tokenExpireDate: number, * _token: string * }} */