Skip to content

Commit

Permalink
"Replaced old Box SDK with new Box SDK GENERATED"
Browse files Browse the repository at this point in the history
  • Loading branch information
iammajid committed May 23, 2024
1 parent b63b18d commit 05837ec
Show file tree
Hide file tree
Showing 11 changed files with 468 additions and 371 deletions.
22 changes: 11 additions & 11 deletions CryptomatorCloudAccess.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
B3D513922BA9A32200DE0D36 /* BoxCredential.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3D5138E2BA9A32200DE0D36 /* BoxCredential.swift */; };
B3D513932BA9A32200DE0D36 /* BoxSetup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3D5138F2BA9A32200DE0D36 /* BoxSetup.swift */; };
B3D513972BA9A44000DE0D36 /* BoxCloudProviderIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3D513952BA9A3BB00DE0D36 /* BoxCloudProviderIntegrationTests.swift */; };
B3FC94A42BA9A98200D1ECFD /* BoxSDK in Frameworks */ = {isa = PBXBuildFile; productRef = B3FC94A32BA9A98200D1ECFD /* BoxSDK */; };
B3D620D22BFC7B2E007301C1 /* BoxSdkGen in Frameworks */ = {isa = PBXBuildFile; productRef = B3D620D12BFC7B2E007301C1 /* BoxSdkGen */; };
B3FC94A62BA9AA4400D1ECFD /* BoxCloudProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3FC94A52BA9AA4400D1ECFD /* BoxCloudProvider.swift */; };
B3FC94A82BA9AEEC00D1ECFD /* BoxIdentifierCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3FC94A72BA9AEEC00D1ECFD /* BoxIdentifierCache.swift */; };
B3FC94AA2BA9AEFC00D1ECFD /* BoxItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3FC94A92BA9AEFC00D1ECFD /* BoxItem.swift */; };
Expand Down Expand Up @@ -405,7 +405,6 @@
buildActionMask = 2147483647;
files = (
4A75E1C428806F5800952FE6 /* MSGraphClientModels in Frameworks */,
B3FC94A42BA9A98200D1ECFD /* BoxSDK in Frameworks */,
4A75E1C728806FA100952FE6 /* MSGraphClientSDK in Frameworks */,
4AF0AA7C2844DDD200C20B75 /* AWSS3 in Frameworks */,
74F9355D251F67A3001F4ADA /* CryptomatorCryptoLib in Frameworks */,
Expand All @@ -419,6 +418,7 @@
746F090E27BC0932003FCD9F /* PCloudSDKSwift in Frameworks */,
4A567B372615CAAC002C4D82 /* GTMSessionFetcher in Frameworks */,
4A567B1A2615C917002C4D82 /* GTMAppAuth in Frameworks */,
B3D620D22BFC7B2E007301C1 /* BoxSdkGen in Frameworks */,
4A8B872F287D7E77002D676E /* CocoaLumberjackSwift in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -1074,7 +1074,7 @@
4A75E1C628806FA100952FE6 /* MSGraphClientSDK */,
4A75E1C928806FF000952FE6 /* ObjectiveDropboxOfficial */,
4A8B872E287D7E77002D676E /* CocoaLumberjackSwift */,
B3FC94A32BA9A98200D1ECFD /* BoxSDK */,
B3D620D12BFC7B2E007301C1 /* BoxSdkGen */,
);
productName = CloudAccess;
productReference = 4A058FF124519FFC008831F9 /* CryptomatorCloudAccess.framework */;
Expand Down Expand Up @@ -1165,7 +1165,7 @@
4A75E1C528806FA100952FE6 /* XCRemoteSwiftPackageReference "msgraph-sdk-objc-spm" */,
4A75E1C828806FF000952FE6 /* XCRemoteSwiftPackageReference "dropbox-sdk-obj-c-spm" */,
4A8B872D287D7E77002D676E /* XCRemoteSwiftPackageReference "CocoaLumberjack" */,
B3FC94A12BA9A8E600D1ECFD /* XCRemoteSwiftPackageReference "box-ios-sdk" */,
B3C72B752BFC798A006F8218 /* XCRemoteSwiftPackageReference "box-swift-sdk-gen" */,
);
productRefGroup = 4A058FF224519FFC008831F9 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -1888,12 +1888,12 @@
minimumVersion = 2.3.0;
};
};
B3FC94A12BA9A8E600D1ECFD /* XCRemoteSwiftPackageReference "box-ios-sdk" */ = {
B3C72B752BFC798A006F8218 /* XCRemoteSwiftPackageReference "box-swift-sdk-gen" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/box/box-ios-sdk.git";
repositoryURL = "https://github.com/box/box-swift-sdk-gen.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 5.5.0;
kind = upToNextMinorVersion;
minimumVersion = 0.2.0;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down Expand Up @@ -1974,10 +1974,10 @@
package = 74F93565251F6863001F4ADA /* XCRemoteSwiftPackageReference "promises" */;
productName = Promises;
};
B3FC94A32BA9A98200D1ECFD /* BoxSDK */ = {
B3D620D12BFC7B2E007301C1 /* BoxSdkGen */ = {
isa = XCSwiftPackageProductDependency;
package = B3FC94A12BA9A8E600D1ECFD /* XCRemoteSwiftPackageReference "box-ios-sdk" */;
productName = BoxSDK;
package = B3C72B752BFC798A006F8218 /* XCRemoteSwiftPackageReference "box-swift-sdk-gen" */;
productName = BoxSdkGen;
};
/* End XCSwiftPackageProductDependency section */
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"originHash" : "9cadc7a70613b038fe8d97d191b9a6f48d09309fa0636f36dfa1ef6376591ebc",
"pins" : [
{
"identity" : "appauth-ios",
Expand All @@ -14,8 +15,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/aws-amplify/aws-sdk-ios-spm.git",
"state" : {
"revision" : "cfcf97f6994b6ffd9a3244dc638458f5822aba56",
"version" : "2.34.0"
"revision" : "8ff8bebfe24271f7b16c5abaeb78daf82bee3a80",
"version" : "2.34.2"
}
},
{
Expand All @@ -28,21 +29,21 @@
}
},
{
"identity" : "box-ios-sdk",
"identity" : "box-swift-sdk-gen",
"kind" : "remoteSourceControl",
"location" : "https://github.com/box/box-ios-sdk.git",
"location" : "https://github.com/box/box-swift-sdk-gen.git",
"state" : {
"revision" : "daffd86b861a5f5882655bf7a01b891f6b808c1f",
"version" : "5.5.0"
"revision" : "e5069af728c4b4f048078dfb5aed683c926da857",
"version" : "0.2.0"
}
},
{
"identity" : "cocoalumberjack",
"kind" : "remoteSourceControl",
"location" : "https://github.com/CocoaLumberjack/CocoaLumberjack.git",
"state" : {
"revision" : "67ec5818a757aba4d7c534e21a905d878d128dbf",
"version" : "3.8.1"
"revision" : "4b8714a7fb84d42393314ce897127b3939885ec3",
"version" : "3.8.5"
}
},
{
Expand Down Expand Up @@ -113,8 +114,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/AzureAD/microsoft-authentication-library-for-objc.git",
"state" : {
"revision" : "f3f84a63de86f7f121544ec917e0365e624d6a97",
"version" : "1.3.0"
"revision" : "d2f81ded070ac6452b2a6acb5bc45eb566427fe7",
"version" : "1.3.3"
}
},
{
Expand Down Expand Up @@ -156,12 +157,12 @@
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"location" : "https://github.com/apple/swift-log",
"state" : {
"revision" : "532d8b529501fb73a2455b179e0bbb6d49b652ed",
"version" : "1.5.3"
"revision" : "e97a6fcb1ab07462881ac165fdbb37f067e205d5",
"version" : "1.5.4"
}
}
],
"version" : 2
"version" : 3
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "NO">
<Testables>
<TestableReference
skipped = "NO">
Expand Down Expand Up @@ -111,6 +111,13 @@
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<EnvironmentVariables>
<EnvironmentVariable
key = ""
value = ""
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
8 changes: 4 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
}
},
{
"identity" : "box-ios-sdk",
"identity" : "box-swift-sdk-gen",
"kind" : "remoteSourceControl",
"location" : "https://github.com/box/box-ios-sdk.git",
"location" : "https://github.com/box/box-swift-sdk-gen.git",
"state" : {
"revision" : "daffd86b861a5f5882655bf7a01b891f6b808c1f",
"version" : "5.5.0"
"revision" : "e5069af728c4b4f048078dfb5aed683c926da857",
"version" : "0.2.0"
}
},
{
Expand Down
7 changes: 4 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ let appExtensionUnsafeSources = [
"Dropbox/DropboxAuthenticator.swift",
"GoogleDrive/GoogleDriveAuthenticator.swift",
"OneDrive/OneDriveAuthenticator.swift",
"PCloud/PCloudAuthenticator.swift"
"PCloud/PCloudAuthenticator.swift",
"Box/BoxAuthenticator.swift"
]

let package = Package(
Expand All @@ -29,7 +30,7 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/AzureAD/microsoft-authentication-library-for-objc.git", .upToNextMinor(from: "1.3.0")),
.package(url: "https://github.com/aws-amplify/aws-sdk-ios-spm.git", .upToNextMinor(from: "2.34.0")),
.package(url: "https://github.com/box/box-ios-sdk.git", .upToNextMinor(from: "5.5.0")),
.package(url: "https://github.com/box/box-swift-sdk-gen.git", .upToNextMinor(from: "0.2.0")),
.package(url: "https://github.com/cryptomator/cryptolib-swift.git", .upToNextMinor(from: "1.1.0")),
.package(url: "https://github.com/CocoaLumberjack/CocoaLumberjack.git", .upToNextMinor(from: "3.8.0")),
.package(url: "https://github.com/google/google-api-objectivec-client-for-rest.git", .upToNextMinor(from: "3.4.0")),
Expand All @@ -50,7 +51,7 @@ let package = Package(
dependencies: [
.product(name: "AWSCore", package: "aws-sdk-ios-spm"),
.product(name: "AWSS3", package: "aws-sdk-ios-spm"),
.product(name: "BoxSDK", package: "box-ios-sdk"),
.product(name: "BoxSdkGen", package: "box-swift-sdk-gen"),
.product(name: "CocoaLumberjackSwift", package: "CocoaLumberjack"),
.product(name: "CryptomatorCryptoLib", package: "cryptolib-swift"),
.product(name: "GoogleAPIClientForREST_Drive", package: "google-api-objectivec-client-for-rest"),
Expand Down
41 changes: 19 additions & 22 deletions Sources/CryptomatorCloudAccess/Box/BoxAuthenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import CryptomatorCloudAccessCore
#endif
import AuthenticationServices
import BoxSDK
import BoxSdkGen
import Promises
import UIKit

Expand All @@ -20,31 +20,28 @@ public enum BoxAuthenticatorError: Error {
}

public enum BoxAuthenticator {
public static let sdk = BoxSDK(clientId: BoxSetup.constants.clientId, clientSecret: BoxSetup.constants.clientSecret)
public static func authenticate(from viewController: UIViewController, tokenStorage: TokenStorage) -> Promise<BoxCredential> {
let pendingPromise = Promise<BoxCredential>.pending()

public static func authenticate(from viewController: UIViewController, tokenStore: TokenStore) -> Promise<(BoxClient, String)> {
return Promise { fulfill, reject in
_Concurrency.Task {
do {
guard let context = viewController as? ASWebAuthenticationPresentationContextProviding else {
throw BoxAuthenticatorError.invalidContext
}

guard let context = viewController as? ASWebAuthenticationPresentationContextProviding else {
reject(BoxAuthenticatorError.invalidContext)
return
}
let config = OAuthConfig(clientId: BoxSetup.constants.clientId, clientSecret: BoxSetup.constants.clientSecret)
let oauth = BoxOAuth(config: config)

sdk.getOAuth2Client(tokenStore: tokenStore, context: context) { result in
switch result {
case let .success(client):
client.users.getCurrent(fields: ["id"]) { userResult in
switch userResult {
case let .success(user):
fulfill((client, user.id))
case .failure:
reject(BoxAuthenticatorError.authenticationFailed)
}
}
case .failure:
reject(BoxAuthenticatorError.authenticationFailed)
}
// Run the login flow and store the access token using tokenStorage
try await oauth.runLoginFlow(options: .init(), context: context)
// TODO: Catch error when login failed

pendingPromise.fulfill(BoxCredential(tokenStore: tokenStorage))
} catch {
pendingPromise.reject(BoxAuthenticatorError.authenticationFailed)
}
}

return pendingPromise
}
}
Loading

0 comments on commit 05837ec

Please sign in to comment.