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

This commit is contained in:
tmoldovan8x8 2021-09-01 15:21:03 +03:00 committed by GitHub
parent 0a6872733e
commit 83a1ee1182
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 27 deletions

View File

@ -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'

View File

@ -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 (token != null && this.promise != null) {
this.promise.resolve(token);
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());
this.promise.resolve(result);
this.promise = null;
}
}

View File

@ -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,

View File

@ -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<string>} - The promise will be resolved with the dropbox
* @returns {Promise<Object>} - The promise will be resolved with the dropbox
* access token or rejected with an error.
*/
export function _authorizeDropbox(): Promise<string> {
return Dropbox.authorize()
.then(token => {
return { token };
});
export function _authorizeDropbox(): Promise<Object> {
return Dropbox.authorize();
}
/**
* Gets a new acccess token based on the refresh token.
*
* @returns {Promise}
*/
export function getNewAccessToken() {
return _authorizeDropbox();
}
/**

View File

@ -28,13 +28,13 @@ function authorize(authUrl: string): Promise<string> {
}
/**
* 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<string>}
* @returns {Promise<Object>}
*/
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()
};
});
}

View File

@ -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<Props, State> {
* _fileRecordingsServiceSharingEnabled: boolean,
* _isDropboxEnabled: boolean,
* _rToken:string,
* _tokenExpireDate: string,
* _tokenExpireDate: number,
* _token: string
* }}
*/