From 63268d8d2e14c43e11db466f214b50d48445bef6 Mon Sep 17 00:00:00 2001 From: Stephen Cobbe Date: Wed, 29 Mar 2017 14:54:17 -0700 Subject: [PATCH] Added userClientFromTokenUid and teamClientFromTokenUid to DBClientsManager. --- .../Shared/Handwritten/DBClientsManager.h | 21 +++++++++++++++++++ .../Shared/Handwritten/DBClientsManager.m | 17 +++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/Source/ObjectiveDropboxOfficial/Shared/Handwritten/DBClientsManager.h b/Source/ObjectiveDropboxOfficial/Shared/Handwritten/DBClientsManager.h index b4d96670f..d0f8d4b87 100644 --- a/Source/ObjectiveDropboxOfficial/Shared/Handwritten/DBClientsManager.h +++ b/Source/ObjectiveDropboxOfficial/Shared/Handwritten/DBClientsManager.h @@ -8,6 +8,7 @@ @class DBUserClient; @class DBTeamClient; +@class DBTransportDefaultConfig; @class DBOAuthResult; /// @@ -57,6 +58,26 @@ /// + (void)setAuthorizedTeamClient:(DBTeamClient * _Nullable)client; +/// +/// Creates a User Client from the supplied `tokenUid` associated with the stored access token. +/// +/// @param tokenUid The uid used to lookup the stored access token. +/// @param transportConfig The transport config used to configure the client. Will use default settings if `nil`. +/// +/// @returns An authorized User Client, or `nil`. +/// ++ (DBUserClient * _Nullable)userClientFromTokenUid:(NSString * _Nonnull)tokenUid transportConfig:(DBTransportDefaultConfig * _Nullable)transportConfig; + +/// +/// Creates a Team Client from the supplied `tokenUid` associated with the stored access token. +/// +/// @param tokenUid The uid used to lookup the stored access token. +/// @param transportConfig The transport config used to configure the client. Will use default settings if `nil`. +/// +/// @returns An authorized Team Client, or `nil`. +/// ++ (DBTeamClient * _Nullable)teamClientFromTokenUid:(NSString * _Nonnull)tokenUid transportConfig:(DBTransportDefaultConfig * _Nullable)transportConfig; + /// /// Reauthorizes the shared authorized user client instance with the access token retrieved from storage via the /// supplied `tokenUid` key. diff --git a/Source/ObjectiveDropboxOfficial/Shared/Handwritten/DBClientsManager.m b/Source/ObjectiveDropboxOfficial/Shared/Handwritten/DBClientsManager.m index cbb593013..18ec60327 100644 --- a/Source/ObjectiveDropboxOfficial/Shared/Handwritten/DBClientsManager.m +++ b/Source/ObjectiveDropboxOfficial/Shared/Handwritten/DBClientsManager.m @@ -55,6 +55,22 @@ + (void)setAuthorizedTeamClient:(DBTeamClient *)client { authorizedTeamClient = client; } ++ (DBUserClient *)userClientFromTokenUid:(NSString *)tokenUid transportConfig:(DBTransportDefaultConfig *)transportConfig { + NSString *accessToken = [[DBOAuthManager sharedOAuthManager] getAccessToken:tokenUid].accessToken; + if (accessToken) { + return [[DBUserClient alloc] initWithAccessToken:accessToken transportConfig:transportConfig]; + } + return nil; +} + ++ (DBTeamClient *)teamClientFromTokenUid:(NSString *)tokenUid transportConfig:(DBTransportDefaultConfig *)transportConfig { + NSString *accessToken = [[DBOAuthManager sharedOAuthManager] getAccessToken:tokenUid].accessToken; + if (accessToken) { + return [[DBTeamClient alloc] initWithAccessToken:accessToken transportConfig:transportConfig]; + } + return nil; +} + + (void)setupWithOAuthManager:(DBOAuthManager *)oAuthManager transportConfig:(DBTransportDefaultConfig *)transportConfig { NSAssert(![DBOAuthManager sharedOAuthManager], @"Only call `[DBClientsManager setupWith...]` once"); @@ -62,6 +78,7 @@ + (void)setupWithOAuthManager:(DBOAuthManager *)oAuthManager [[self class] setupHelperWithOAuthManager:oAuthManager transportConfig:transportConfig]; DBAccessToken *accessToken = [[DBOAuthManager sharedOAuthManager] getFirstAccessToken]; + NSLog(@"\n\n%@\n\n", accessToken.uid); [[self class] setupAuthorizedClient:accessToken]; }