Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for using a custom transport client after handling dauth #405

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading