Skip to content

Commit

Permalink
Greatly simplified multi-account use case.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Cobbe committed Mar 30, 2017
1 parent 299ca31 commit 36f7d23
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 313 deletions.
21 changes: 9 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -834,10 +834,7 @@ void (^networkGlobalResponseBlock)(DBRequestError *, DBTask *) =
DBAUTHRateLimitError *rateLimitError = [networkError asRateLimitError];
int backOff = [rateLimitError.retryAfter intValue];

// all reqeusting done using the SDK should be on the main thread
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, backOff * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[restartTask restart];
});
[restartTask restart];
}
};

Expand Down Expand Up @@ -909,7 +906,7 @@ The Objective-C SDK includes a convenience class, `DBClientsManager`, for integr
For most apps, it is reasonable to assume that only one Dropbox account (and access token) needs to be managed at a time. In this case, the `DBClientsManager` flow looks like this:

* call `setupWithAppKey`/`setupWithAppKeyDesktop` (or `setupWithTeamAppKey`/`setupWithTeamAppKeyDesktop`) in integrating app's app delegate
* `DBClientsManager` class determines whether any access tokens are stored -- if any exist, one token is arbitrarily chosen to use
* `DBClientsManager` class determines whether any access tokens are stored -- if any exist, one token is arbitrarily chosen to use for the `authorizedClient` / `authorizedTeamClient` shared instance
* if no token is found, client of the SDK should call `authorizeFromController`/`authorizeFromControllerDesktop` to initiate the OAuth flow
* if auth flow is initiated, client of the SDK should call `handleRedirectURL` (or `handleRedirectURLTeam`) in integrating app's app delegate to handle auth redirect back into the app and store the retrieved access token
* `DBClientsManager` class sets up a `DBUserClient` (or `DBTeamClient`) with the particular network configuration as defined by the `DBTransportDefaultConfig` instance passed in (or a standard configuration, if no config instance was passed when the `setupWith...` method was called)
Expand All @@ -923,18 +920,18 @@ The `DBUserClient` (or `DBTeamClient`) is then used to make all of the desired A
For some apps, it is necessary to manage more than one Dropbox account (and access token) at a time. In this case, the `DBClientsManager` flow looks like this:

* access token uids are managed by the app that is integrating with the SDK for later lookup
* call `setupWithAppKeyMultiUser`/`setupWithAppKeyMultiUserDesktop` (or `setupWithTeamAppKeyMultiUser`/`setupWithTeamAppKeyMultiUserDesktop`) in integrating app's app delegate
* client manager determines whether an access token is stored with the`tokenUid` as a key -- if one exists, this token is chosen to use
* call `setupWithAppKey`/`setupWithAppKeyDesktop` (or `setupWithTeamAppKey`/`setupWithTeamAppKeyDesktop`) in integrating app's app delegate
* `DBClientsManager` class determines whether any access tokens are stored -- if any exist, one token is arbitrarily chosen to use for the `authorizedClient` / `authorizedTeamClient` shared instance
* `DBClientsManager` class also populates `authorizedClients` / `authorizedTeamClients` shared dictionary from all tokens stored in keychain, if any exist
* if no token is found, client of the SDK should call `authorizeFromController`/`authorizeFromControllerDesktop` to initiate the OAuth flow
* if auth flow is initiated, call `handleRedirectURL` (or `handleRedirectURLTeam`) in integrating app's app delegate to handle auth redirect back into the app and store the retrieved access token
* at this point, the app that is integrating with the SDK should persistently save the `tokenUid` from the `DBAccessToken` field of the `DBOAuthResult` object returned from the `handleRedirectURL` (or `handleRedirectURLTeam`) method
* `tokenUid` can be reused either to authorize a new user mid-way through an app's lifecycle via `reauthorizeClient` (or `reauthorizeTeamClient`) or when the app initially launches via `setupWithAppKeyMultiUser`/`setupWithAppKeyMultiUserDesktop` (or `setupWithTeamAppKeyMultiUser`/`setupWithTeamAppKeyMultiUserDesktop`)
* `DBClientsManager` class sets up a `DBUserClient` (or `DBTeamClient`) with the particular network configuration as defined by the `DBTransportDefaultConfig` instance passed in (or a standard configuration, if no config instance was passed when the `setupWith...` method was called)
* `DBClientsManager` class sets up a `DBUserClient` (or `DBTeamClient`) with the particular network configuration as defined by the `DBTransportDefaultConfig` instance passed in (or a standard configuration, if no config instance was passed when the `setupWith...` method was called) and saves it to the list of authorized clients

The `DBUserClient` (or `DBTeamClient`) is then used to make all of the desired API calls.
The `DBUserClient`s (or `DBTeamClient`s) in `authorizedClients` / `authorizedTeamClients` is then used to make all of the desired API calls.

* call `resetClients` to logout Dropbox user but not clear any access tokens
* if specific access tokens need to be removed, use the `clearStoredAccessToken` method in `DBOAuthManager`
* call `unlinkAndResetClients` to logout Dropbox user and clear all access tokens
* if specific access tokens need to be removed, use the `clearStoredAccessToken` method in `DBOAuthManager`.

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,9 @@
+ (void)setupWithOAuthManager:(DBOAuthManager * _Nonnull)oAuthManager
transportConfig:(DBTransportDefaultConfig * _Nonnull)transportConfig;

+ (void)setupWithOAuthManagerMultiUser:(DBOAuthManager * _Nonnull)oAuthManager
transportConfig:(DBTransportDefaultConfig * _Nonnull)transportConfig
tokenUid:(NSString * _Nullable)tokenUid;

+ (void)setupWithOAuthManagerTeam:(DBOAuthManager * _Nonnull)oAuthManager
transportConfig:(DBTransportDefaultConfig * _Nonnull)transportConfig;

+ (void)setupWithOAuthManagerTeamMultiUser:(DBOAuthManager * _Nonnull)oAuthManager
transportConfig:(DBTransportDefaultConfig * _Nonnull)transportConfig
tokenUid:(NSString * _Nullable)tokenUid;

+ (void)setTransportConfig:(DBTransportDefaultConfig * _Nonnull)transportConfig;

+ (DBTransportDefaultConfig * _Nonnull)transportConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,39 +59,6 @@
///
+ (void)setupWithTransportConfig:(DBTransportDefaultConfig * _Nullable)transportConfig;

///
/// Stores the user app key. If an access token already exists associated with the `tokenUid` key, initializes an
/// authorized shared `DBUserClient` instance. Convenience method for `setupWithTransportConfigMultiUser:`.
///
/// This method should be used in the multi Dropbox user case (i.e. when it is necessary to track multiple Dropbox
/// accounts / access tokens). Here, a token uid is supplied by the client of the SDK. If there exists an access token
/// stored with that uid as a key, it is retrieved and used to instantiate a `DBUserClient` instance. This method should
/// be called from the app delegate.
///
/// @param appKey The app key of the third-party Dropbox API user app that will be associated with all API calls. To
/// create an app or to locate your app's app key, please visit the App Console here:
/// https://www.dropbox.com/developers/apps.
/// @param tokenUid The uid of the stored access token to use. This uid is returned after a successful progression
/// through the OAuth flow (via `handleRedirectURL:`) in the `DBAccessToken` field of the `DBOAuthResult` object.
///
+ (void)setupWithAppKeyMultiUser:(NSString * _Nonnull)appKey tokenUid:(NSString * _Nullable)tokenUid;

///
/// Stores the user transport config info. If an access token already exists associated with the `tokenUid` key,
/// initializes an authorized shared `DBUserClient` instance.
///
/// This method should be used in the multi Dropbox user case (i.e. when it is necessary to track multiple Dropbox
/// accounts / access tokens). Here, a token uid is supplied by the client of the SDK. If there exists an access token
/// stored with that uid as a key, it is retrieved and used to instantiate a `DBUserClient` instance. This method should
/// be called from the app delegate.
///
/// @param transportConfig A wrapper around the different parameters that can be set to change network calling behavior.
/// @param tokenUid The uid of the stored access token to use. This uid is returned after a successful progression
/// through the OAuth flow (via `handleRedirectURL:`) in the `DBAccessToken` field of the `DBOAuthResult` object.
///
+ (void)setupWithTransportConfigMultiUser:(DBTransportDefaultConfig * _Nullable)transportConfig
tokenUid:(NSString * _Nullable)tokenUid;

///
/// Stores the team app key. If any access token already exists, initializes an authorized shared `DBTeamClient`
/// instance. Convenience method for `setupWithTeamTransportConfig:`.
Expand All @@ -118,37 +85,4 @@
///
+ (void)setupWithTeamTransportConfig:(DBTransportDefaultConfig * _Nullable)transportConfig;

///
/// Stores the team app key. If an access token already exists associated with the `tokenUid` key, initializes an
/// authorized shared `DBTeamClient` instance. Convenience method for `setupWithTeamTransportConfigMultiUser:`.
///
/// This method should be used in the multi Dropbox user case (i.e. when it is necessary to track multiple Dropbox
/// accounts / access tokens). Here, a token uid is supplied by the client of the SDK. If there exists an access token
/// stored with that uid as a key, it is retrieved and used to instantiate a `DBTeamClient` instance. This method should
/// be called from the app delegate.
///
/// @param appKey The app key of the third-party Dropbox API user app that will be associated with all API calls. To
/// create an app or to locate your app's app key, please visit the App Console here:
/// https://www.dropbox.com/developers/apps.
/// @param tokenUid The uid of the stored access token to use. This uid is returned after a successful progression
/// through the OAuth flow (via `handleRedirectURLTeam:`) in the `DBAccessToken` field of the `DBOAuthResult` object.
///
+ (void)setupWithTeamAppKeyMultiUser:(NSString * _Nonnull)appKey tokenUid:(NSString * _Nullable)tokenUid;

///
/// Stores the team transport config info. If an access token already exists associated with the `tokenUid` key,
/// initializes an authorized shared `DBTeamClient` instance.
///
/// This method should be used in the multi Dropbox user case (i.e. when it is necessary to track multiple Dropbox
/// accounts / access tokens). Here, a token uid is supplied by the client of the SDK. If there exists an access token
/// stored with that uid as a key, it is retrieved and used to instantiate a `DBTeamClient` instance. This method should
/// be called from the app delegate.
///
/// @param transportConfig A wrapper around the different parameters that can be set to change network calling behavior.
/// @param tokenUid The uid of the stored access token to use. This uid is returned after a successful progression
/// through the OAuth flow (via `handleRedirectURLTeam:`) in the `DBAccessToken` field of the `DBOAuthResult` object.
///
+ (void)setupWithTeamTransportConfigMultiUser:(DBTransportDefaultConfig * _Nullable)transportConfig
tokenUid:(NSString * _Nullable)tokenUid;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,6 @@ + (void)setupWithTransportConfig:(DBTransportDefaultConfig *)transportConfig {
transportConfig:transportConfig];
}

+ (void)setupWithAppKeyMultiUser:(NSString *)appKey tokenUid:(NSString *)tokenUid {
DBTransportDefaultConfig *transportConfig = [[DBTransportDefaultConfig alloc] initWithAppKey:appKey];
[[self class] setupWithOAuthManagerMultiUser:[[DBMobileOAuthManager alloc] initWithAppKey:transportConfig.appKey]
transportConfig:transportConfig
tokenUid:tokenUid];
}

+ (void)setupWithTransportConfigMultiUser:(DBTransportDefaultConfig *)transportConfig tokenUid:(NSString *)tokenUid {
[[self class] setupWithOAuthManagerMultiUser:[[DBMobileOAuthManager alloc] initWithAppKey:transportConfig.appKey]
transportConfig:transportConfig
tokenUid:tokenUid];
}

+ (void)setupWithTeamAppKey:(NSString *)appKey {
[[self class] setupWithTeamTransportConfig:[[DBTransportDefaultConfig alloc] initWithAppKey:appKey]];
}
Expand All @@ -56,18 +43,4 @@ + (void)setupWithTeamTransportConfig:(DBTransportDefaultConfig *)transportConfig
transportConfig:transportConfig];
}

+ (void)setupWithTeamAppKeyMultiUser:(NSString *)appKey tokenUid:(NSString *)tokenUid {
DBTransportDefaultConfig *transportConfig = [[DBTransportDefaultConfig alloc] initWithAppKey:appKey];
[[self class] setupWithOAuthManagerTeamMultiUser:[[DBMobileOAuthManager alloc] initWithAppKey:transportConfig.appKey]
transportConfig:transportConfig
tokenUid:tokenUid];
}

+ (void)setupWithTeamTransportConfigMultiUser:(DBTransportDefaultConfig *)transportConfig
tokenUid:(NSString *)tokenUid {
[[self class] setupWithOAuthManagerTeamMultiUser:[[DBMobileOAuthManager alloc] initWithAppKey:transportConfig.appKey]
transportConfig:transportConfig
tokenUid:tokenUid];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -60,40 +60,6 @@
///
+ (void)setupWithTransportConfigDesktop:(DBTransportDefaultConfig * _Nullable)transportConfig;

///
/// Stores the user app key for desktop. If an access token already exists associated with the `tokenUid` key,
/// initializes an authorized shared `DBUserClient` instance. Convenience method for
/// `setupWithTransportConfigMultiUserDesktop:`.
///
/// This method should be used in the multi Dropbox user case (i.e. when it is necessary to track multiple Dropbox
/// accounts / access tokens). Here, a token uid is supplied by the client of the SDK. If there exists an access token
/// stored with that uid as a key, it is retrieved and used to instantiate a `DBUserClient` instance. This method should
/// be called from the app delegate.
///
/// @param appKey The app key of the third-party Dropbox API user app that will be associated with all API calls. To
/// create an app or to locate your app's app key, please visit the App Console here:
/// https://www.dropbox.com/developers/apps.
/// @param tokenUid The uid of the stored access token to use. This uid is returned after a successful progression
/// through the OAuth flow (via `handleRedirectURL:`) in the `DBAccessToken` field of the `DBOAuthResult` object.
///
+ (void)setupWithAppKeyMultiUserDesktop:(NSString * _Nonnull)appKey tokenUid:(NSString * _Nullable)tokenUid;

///
/// Stores the user transport config info for desktop. If an access token already exists associated with the `tokenUid`
/// key, initializes an authorized shared `DBUserClient` instance.
///
/// This method should be used in the multi Dropbox user case (i.e. when it is necessary to track multiple Dropbox
/// accounts / access tokens). Here, a token uid is supplied by the client of the SDK. If there exists an access token
/// stored with that uid as a key, it is retrieved and used to instantiate a `DBUserClient` instance. This method should
/// be called from the app delegate.
///
/// @param transportConfig A wrapper around the different parameters that can be set to change network calling behavior.
/// @param tokenUid The uid of the stored access token to use. This uid is returned after a successful progression
/// through the OAuth flow (via `handleRedirectURL:`) in the `DBAccessToken` field of the `DBOAuthResult` object.
///
+ (void)setupWithTransportConfigMultiUserDesktop:(DBTransportDefaultConfig * _Nonnull)transportConfig
tokenUid:(NSString * _Nullable)tokenUid;

///
/// Stores the team app key for desktop. If any access token already exists, initializes an authorized shared
/// `DBTeamClient` instance. Convenience method for `setupWithTeamTransportConfigDesktop:`.
Expand All @@ -120,38 +86,4 @@
///
+ (void)setupWithTeamTransportConfigDesktop:(DBTransportDefaultConfig * _Nullable)transportConfig;

///
/// Stores the team app key for desktop. If an access token already exists associated with the `tokenUid` key,
/// initializes an authorized shared `DBTeamClient` instance. Convenience method for
/// `setupWithTeamTransportConfigMultiUserDesktop:`.
///
/// This method should be used in the multi Dropbox user case (i.e. when it is necessary to track multiple Dropbox
/// accounts / access tokens). Here, a token uid is supplied by the client of the SDK. If there exists an access token
/// stored with that uid as a key, it is retrieved and used to instantiate a `DBTeamClient` instance. This method should
/// be called from the app delegate.
///
/// @param appKey The app key of the third-party Dropbox API user app that will be associated with all API calls. To
/// create an app or to locate your app's app key, please visit the App Console here:
/// https://www.dropbox.com/developers/apps.
/// @param tokenUid The uid of the stored access token to use. This uid is returned after a successful progression
/// through the OAuth flow (via `handleRedirectURLTeam:`) in the `DBAccessToken` field of the `DBOAuthResult` object.
///
+ (void)setupWithTeamAppKeyMultiUserDesktop:(NSString * _Nonnull)appKey tokenUid:(NSString * _Nullable)tokenUid;

///
/// Stores the team transport config info for desktop. If an access token already exists associated with the `tokenUid`
/// key, initializes an authorized shared `DBTeamClient` instance.
///
/// This method should be used in the multi Dropbox user case (i.e. when it is necessary to track multiple Dropbox
/// accounts / access tokens). Here, a token uid is supplied by the client of the SDK. If there exists an access token
/// stored with that uid as a key, it is retrieved and used to instantiate a `DBTeamClient` instance. This method should
/// be called from the app delegate.
///
/// @param transportConfig A wrapper around the different parameters that can be set to change network calling behavior.
/// @param tokenUid The uid of the stored access token to use. This uid is returned after a successful progression
/// through the OAuth flow (via `handleRedirectURLTeam:`) in the `DBAccessToken` field of the `DBOAuthResult` object.
///
+ (void)setupWithTeamTransportConfigMultiUserDesktop:(DBTransportDefaultConfig * _Nullable)transportConfig
tokenUid:(NSString * _Nullable)tokenUid;

@end
Loading

0 comments on commit 36f7d23

Please sign in to comment.