Skip to content

Commit

Permalink
Added userClientFromTokenUid and teamClientFromTokenUid to DBClientsM…
Browse files Browse the repository at this point in the history
…anager.
  • Loading branch information
Stephen Cobbe committed Mar 29, 2017
1 parent b1a7abf commit 63268d8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

@class DBUserClient;
@class DBTeamClient;
@class DBTransportDefaultConfig;
@class DBOAuthResult;

///
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,30 @@ + (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");

[[self class] setupHelperWithOAuthManager:oAuthManager transportConfig:transportConfig];

DBAccessToken *accessToken = [[DBOAuthManager sharedOAuthManager] getFirstAccessToken];
NSLog(@"\n\n%@\n\n", accessToken.uid);
[[self class] setupAuthorizedClient:accessToken];
}

Expand Down

0 comments on commit 63268d8

Please sign in to comment.