Skip to content

Commit

Permalink
Allow for using a custom transport client after handling dauth (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlocke authored Mar 1, 2024
1 parent baaba8e commit 5ed2773
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ public class DropboxClientsManager {
public static func handleRedirectURL(
_ url: URL,
includeBackgroundClient: Bool,
transportClient: DropboxTransportClient? = nil,
backgroundSessionTransportClient: DropboxTransportClient? = nil,
sessionConfiguration: NetworkSessionConfiguration? = nil,
backgroundSessionConfiguration: NetworkSessionConfiguration? = nil,
completion: @escaping DropboxOAuthCompletion
Expand All @@ -335,12 +337,12 @@ public class DropboxClientsManager {
if let result = result {
switch result {
case .success(let accessToken):
setupAuthorizedClient(accessToken, transportClient: nil, sessionConfiguration: sessionConfiguration)
setupAuthorizedClient(accessToken, transportClient: transportClient, sessionConfiguration: sessionConfiguration)

if includeBackgroundClient {
setupAuthorizedBackgroundClient(
accessToken,
transportClient: nil,
transportClient: backgroundSessionTransportClient,
sessionConfiguration: backgroundSessionConfiguration,
requestsToReconnect: { _ in } // No need for reconnect as no loads are in progress pre-auth
)
Expand All @@ -363,6 +365,7 @@ public class DropboxClientsManager {
@discardableResult
public static func handleRedirectURLTeam(
_ url: URL,
transportClient: DropboxTransportClient? = nil,
sessionConfiguration: NetworkSessionConfiguration? = nil,
completion: @escaping DropboxOAuthCompletion
) -> Bool {
Expand All @@ -371,7 +374,7 @@ public class DropboxClientsManager {
if let result = result {
switch result {
case .success(let accessToken):
setupAuthorizedTeamClient(accessToken, transportClient: nil, sessionConfiguration: sessionConfiguration)
setupAuthorizedTeamClient(accessToken, transportClient: transportClient, sessionConfiguration: sessionConfiguration)
case .cancel, .error:
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,46 @@ public class DBXDropboxClientsManager: NSObject {
/// - parameters:
/// - url: The URL to attempt to handle.
/// - includeBackgroundClient: additionally auth background client.
/// - transportClient: A custom transport client to use for network requests.
/// - backgroundSessionTransportClient: A custom transport client to use for background network requests.
/// - sessionConfiguration: A custom session configuration to use for network requests.
/// - backgroundSessionConfiguration: A custom session configuration to use for background network requests.
/// - completion: The callback closure to receive auth result.
/// - returns: Whether the redirect URL can be handled.
@objc
@discardableResult
public static func handleRedirectURLTeam(_ url: URL, includeBackgroundClient: Bool, completion: @escaping (DBXDropboxOAuthResult?) -> Void) -> Bool {
DropboxClientsManager.handleRedirectURLTeam(url, completion: bridgeDropboxOAuthCompletion(completion))
public static func handleRedirectURL(
_ url: URL,
includeBackgroundClient: Bool,
transportClient: DBXDropboxTransportClient?,
backgroundSessionTransportClient: DBXDropboxTransportClient?,
sessionConfiguration: DBXNetworkSessionConfiguration?,
backgroundSessionConfiguration: DBXNetworkSessionConfiguration?,
completion: @escaping (DBXDropboxOAuthResult?) -> Void) -> Bool
{
DropboxClientsManager.handleRedirectURL(
url,
includeBackgroundClient: includeBackgroundClient,
transportClient: transportClient?.swift,
backgroundSessionTransportClient: backgroundSessionTransportClient?.swift,
sessionConfiguration: sessionConfiguration?.swift,
backgroundSessionConfiguration: backgroundSessionConfiguration?.swift,
completion: bridgeDropboxOAuthCompletion(completion)
)
}

/// Handle a redirect and automatically initialize the client and save the token.
///
/// - parameters:
/// - url: The URL to attempt to handle.
/// - transportClient: A custom transport client to use for network requests.
/// - sessionConfiguration: A custom session configuration to use for network requests.
/// - completion: The callback closure to receive auth result.
/// - returns: Whether the redirect URL can be handled.
@objc
@discardableResult
public static func handleRedirectURLTeam(_ url: URL, transportClient: DBXDropboxTransportClient?, sessionConfiguration: DBXNetworkSessionConfiguration?, completion: @escaping (DBXDropboxOAuthResult?) -> Void) -> Bool {
DropboxClientsManager.handleRedirectURLTeam(url, transportClient: transportClient?.swift, sessionConfiguration: sessionConfiguration?.swift, completion: bridgeDropboxOAuthCompletion(completion))
}

/// Prepare the appropriate single user DropboxClient to handle incoming background session events and make ongoing tasks available for reconnection
Expand Down

0 comments on commit 5ed2773

Please sign in to comment.