Skip to content

Commit 42d88e2

Browse files
author
Xuyan Ke
committed
Let handle redirect url methods return whether the url can be handled
This is needed on iOS to properly return the value in app delegate method.
1 parent 949b05f commit 42d88e2

7 files changed

Lines changed: 44 additions & 29 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,8 @@ To handle the redirection back into the Objective-C SDK once the authentication
438438
}
439439
}
440440
};
441-
[DBClientsManager handleRedirectURL:url completion:completion];
442-
return NO;
441+
BOOL canHandle = [DBClientsManager handleRedirectURL:url completion:completion];
442+
return canHandle;
443443
}
444444
```
445445

Source/ObjectiveDropboxOfficial/Platform/ObjectiveDropboxOfficial_iOS/DBOAuthMobileManager-iOS.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ - (BOOL)checkAndPresentPlatformSpecificAuth:(id<DBSharedApplication>)sharedAppli
7979
return NO;
8080
}
8181

82-
- (void)handleRedirectURL:(NSURL *)url completion:(DBOAuthCompletion)completion {
83-
[super handleRedirectURL:url
84-
completion:^(DBOAuthResult *result) {
82+
- (BOOL)handleRedirectURL:(NSURL *)url completion:(DBOAuthCompletion)completion {
83+
return [super handleRedirectURL:url
84+
completion:^(DBOAuthResult *result) {
8585
[[DBMobileSharedApplication mobileSharedApplication] dismissAuthController];
8686
completion(result);
8787
}];

Source/ObjectiveDropboxOfficial/Shared/Handwritten/DBClientsManager.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ NS_ASSUME_NONNULL_BEGIN
9292
/// @param url The auth redirect url which relaunches the SDK.
9393
/// @param completion Completion block to pass back authorization result.
9494
///
95-
+ (void)handleRedirectURL:(NSURL *)url completion:(DBOAuthCompletion)completion;
95+
/// @return Whether the URL can be handled.
96+
///
97+
+ (BOOL)handleRedirectURL:(NSURL *)url completion:(DBOAuthCompletion)completion;
9698

9799
///
98100
/// Handles launching the SDK with a redirect url from an external source to authorize a team API client.
@@ -103,7 +105,9 @@ NS_ASSUME_NONNULL_BEGIN
103105
/// @param url The auth redirect url which relaunches the SDK.
104106
/// @param completion Completion block to pass back authorization result.
105107
///
106-
+ (void)handleRedirectURLTeam:(NSURL *)url completion:(DBOAuthCompletion)completion;
108+
/// @return Whether the URL can be handled.
109+
///
110+
+ (BOOL)handleRedirectURLTeam:(NSURL *)url completion:(DBOAuthCompletion)completion;
107111

108112
///
109113
/// Multi-Dropbox account use case. Sets to `nil` the active user / team shared authorized client, clears the stored

Source/ObjectiveDropboxOfficial/Shared/Handwritten/DBClientsManager.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ + (void)setupWithOAuthManagerTeam:(DBOAuthManager *)oAuthManager
117117
[self db_setupAuthorizedTeamClients];
118118
}
119119

120-
+ (void)handleRedirectURL:(NSURL *)url completion:(DBOAuthCompletion)completion {
121-
[self db_handleRedirectURL:url isTeam:NO completion:completion];
120+
+ (BOOL)handleRedirectURL:(NSURL *)url completion:(DBOAuthCompletion)completion {
121+
return [self db_handleRedirectURL:url isTeam:NO completion:completion];
122122
}
123123

124-
+ (void)handleRedirectURLTeam:(NSURL *)url completion:(DBOAuthCompletion)completion {
125-
[self db_handleRedirectURL:url isTeam:YES completion:completion];
124+
+ (BOOL)handleRedirectURLTeam:(NSURL *)url completion:(DBOAuthCompletion)completion {
125+
return [self db_handleRedirectURL:url isTeam:YES completion:completion];
126126
}
127127

128128
+ (void)unlinkAndResetClient:(NSString *)tokenUid {
@@ -294,12 +294,12 @@ + (void)db_resetClient:(NSString *)tokenUid {
294294
}
295295
}
296296

297-
+ (void)db_handleRedirectURL:(NSURL *)url isTeam:(BOOL)isTeam completion:(DBOAuthCompletion)completion {
297+
+ (BOOL)db_handleRedirectURL:(NSURL *)url isTeam:(BOOL)isTeam completion:(DBOAuthCompletion)completion {
298298
NSAssert([DBOAuthManager sharedOAuthManager],
299299
@"Call the appropriate `[DBClientsManager setupWith...]` before calling this method");
300300

301-
[[DBOAuthManager sharedOAuthManager] handleRedirectURL:url
302-
completion:^(DBOAuthResult *result) {
301+
return [[DBOAuthManager sharedOAuthManager] handleRedirectURL:url
302+
completion:^(DBOAuthResult *result) {
303303
if ([result isSuccess]) {
304304
DBAccessToken *token = result.accessToken;
305305
if (isTeam) {

Source/ObjectiveDropboxOfficial/Shared/Handwritten/OAuth/DBOAuthManager.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ NS_ASSUME_NONNULL_BEGIN
202202
/// @param completion Completion block for oauth result, called with `nil` if SDK cannot handle the redirect URL,
203203
/// otherwise an instance of `DBOAuthResult`.
204204
///
205-
- (void)handleRedirectURL:(NSURL *)url completion:(DBOAuthCompletion)completion;
205+
/// @return Whether the URL can be handled.
206+
///
207+
- (BOOL)handleRedirectURL:(NSURL *)url completion:(DBOAuthCompletion)completion;
206208

207209
#pragma mark - Keychain methods
208210

Source/ObjectiveDropboxOfficial/Shared/Handwritten/OAuth/DBOAuthManager.m

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,26 @@ - (instancetype)initWithAppKey:(NSString *)appKey host:(NSString *)host redirect
150150

151151
#pragma mark - Auth flow methods
152152

153-
- (void)handleRedirectURL:(NSURL *)url completion:(DBOAuthCompletion)completion {
153+
- (BOOL)handleRedirectURL:(NSURL *)url completion:(DBOAuthCompletion)completion {
154154
// check if url is a cancel url
155155
if (([[url host] isEqualToString:@"1"] && [[url path] isEqualToString:@"/cancel"]) ||
156156
([[url host] isEqualToString:@"2"] && [[url path] isEqualToString:@"/cancel"])) {
157157
completion([[DBOAuthResult alloc] initWithCancel]);
158-
} else if (![self canHandleURL:url]) {
159-
completion(nil);
160-
} else {
158+
return YES;
159+
}
160+
161+
if ([self canHandleURL:url]) {
161162
[self extractFromUrl:url
162163
completion:^(DBOAuthResult *result) {
163-
if ([result isSuccess]) {
164-
[self storeAccessToken:result.accessToken];
165-
}
166-
completion(result);
167-
}];
164+
if ([result isSuccess]) {
165+
[self storeAccessToken:result.accessToken];
166+
}
167+
completion(result);
168+
}];
169+
return YES;
170+
} else {
171+
completion(nil);
172+
return NO;
168173
}
169174
}
170175

TestObjectiveDropbox/TestObjectiveDropbox_iOS/AppDelegate.m

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
7979
}
8080

8181
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
82+
BOOL urlHandled = NO;
8283
if ([[url absoluteString] containsString:@"openWith"]) {
8384
NSLog(@"Successfully retrieved openWith url");
8485

@@ -101,11 +102,12 @@ - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
101102

102103
DBOpenWithInfo *openWithInfo = [connector openWithInfoFromURL:url];
103104
[((ViewController *)self.window.rootViewController) setOpenWithInfoNSURL:openWithInfo];
105+
urlHandled = YES;
104106
} else {
105-
[self db_handleAuthUrl:url];
107+
urlHandled = [self db_handleAuthUrl:url];
106108
}
107109

108-
return NO;
110+
return urlHandled;
109111
}
110112

111113
- (void)applicationWillResignActive:(UIApplication *)application {
@@ -138,7 +140,7 @@ - (void)applicationWillTerminate:(UIApplication *)application {
138140
// applicationDidEnterBackground:.
139141
}
140142

141-
- (void)db_handleAuthUrl:(NSURL *)url {
143+
- (BOOL)db_handleAuthUrl:(NSURL *)url {
142144
DBOAuthCompletion completion = ^(DBOAuthResult *authResult) {
143145
if (authResult != nil) {
144146
if ([authResult isSuccess]) {
@@ -152,16 +154,18 @@ - (void)db_handleAuthUrl:(NSURL *)url {
152154
[((ViewController *)self.window.rootViewController) checkButtons];
153155
};
154156

157+
BOOL handled = NO;
155158
switch (appPermission) {
156159
case FullDropbox: {
157-
[DBClientsManager handleRedirectURL:url completion: completion];
160+
handled = [DBClientsManager handleRedirectURL:url completion:completion];
158161
break;
159162
}
160163
case TeamMemberFileAccess:
161164
case TeamMemberManagement:
162-
[DBClientsManager handleRedirectURLTeam:url completion: completion];
165+
handled = [DBClientsManager handleRedirectURLTeam:url completion:completion];
163166
break;
164167
}
168+
return handled;
165169
}
166170

167171
@end

0 commit comments

Comments
 (0)