task(rn, android): update dropbox logic to retrieve refresh token
This commit is contained in:
parent
0a6872733e
commit
83a1ee1182
|
@ -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'
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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()
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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
|
||||
* }}
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue