Skip to content

Commit

Permalink
Added BoxCloudProvider, authentication logic, tests, and credentials …
Browse files Browse the repository at this point in the history
…for Box integration
  • Loading branch information
iammajid committed Apr 15, 2024
1 parent e52202e commit afcdff9
Show file tree
Hide file tree
Showing 11 changed files with 361 additions and 179 deletions.
12 changes: 10 additions & 2 deletions CryptomatorCloudAccess.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@
9ED0E624246198F600FDB438 /* VaultFormat7CloudProviderMockTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9ED0E623246198F600FDB438 /* VaultFormat7CloudProviderMockTests.swift */; };
9EE62A0D247D54760089DAF7 /* CloudProvider+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EE62A0C247D54760089DAF7 /* CloudProvider+Convenience.swift */; };
9EE62A10247D54E90089DAF7 /* CloudProvider+ConvenienceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EE62A0F247D54E90089DAF7 /* CloudProvider+ConvenienceTests.swift */; };
B3408AC82BCD32CA005271D2 /* BoxCredentialMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3408AC72BCD32CA005271D2 /* BoxCredentialMock.swift */; };
B3408ACA2BCDAA09005271D2 /* BoxError.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3408AC92BCDAA09005271D2 /* BoxError.swift */; };
B3D513912BA9A32200DE0D36 /* BoxAuthenticator.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3D5138D2BA9A32200DE0D36 /* BoxAuthenticator.swift */; };
B3D513922BA9A32200DE0D36 /* BoxCredential.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3D5138E2BA9A32200DE0D36 /* BoxCredential.swift */; };
B3D513932BA9A32200DE0D36 /* BoxSetup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3D5138F2BA9A32200DE0D36 /* BoxSetup.swift */; };
Expand Down Expand Up @@ -376,6 +378,8 @@
9ED0E623246198F600FDB438 /* VaultFormat7CloudProviderMockTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VaultFormat7CloudProviderMockTests.swift; sourceTree = "<group>"; };
9EE62A0C247D54760089DAF7 /* CloudProvider+Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CloudProvider+Convenience.swift"; sourceTree = "<group>"; };
9EE62A0F247D54E90089DAF7 /* CloudProvider+ConvenienceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CloudProvider+ConvenienceTests.swift"; sourceTree = "<group>"; };
B3408AC72BCD32CA005271D2 /* BoxCredentialMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoxCredentialMock.swift; sourceTree = "<group>"; };
B3408AC92BCDAA09005271D2 /* BoxError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoxError.swift; sourceTree = "<group>"; };
B3D5138D2BA9A32200DE0D36 /* BoxAuthenticator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BoxAuthenticator.swift; sourceTree = "<group>"; };
B3D5138E2BA9A32200DE0D36 /* BoxCredential.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BoxCredential.swift; sourceTree = "<group>"; };
B3D5138F2BA9A32200DE0D36 /* BoxSetup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BoxSetup.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -982,11 +986,12 @@
isa = PBXGroup;
children = (
B3D5138D2BA9A32200DE0D36 /* BoxAuthenticator.swift */,
B3D5138E2BA9A32200DE0D36 /* BoxCredential.swift */,
B3D5138F2BA9A32200DE0D36 /* BoxSetup.swift */,
B3FC94A52BA9AA4400D1ECFD /* BoxCloudProvider.swift */,
B3D5138E2BA9A32200DE0D36 /* BoxCredential.swift */,
B3408AC92BCDAA09005271D2 /* BoxError.swift */,
B3FC94A72BA9AEEC00D1ECFD /* BoxIdentifierCache.swift */,
B3FC94A92BA9AEFC00D1ECFD /* BoxItem.swift */,
B3D5138F2BA9A32200DE0D36 /* BoxSetup.swift */,
);
name = Box;
path = Sources/CryptomatorCloudAccess/Box;
Expand All @@ -996,6 +1001,7 @@
isa = PBXGroup;
children = (
B3D513952BA9A3BB00DE0D36 /* BoxCloudProviderIntegrationTests.swift */,
B3408AC72BCD32CA005271D2 /* BoxCredentialMock.swift */,
);
path = Box;
sourceTree = "<group>";
Expand Down Expand Up @@ -1337,6 +1343,7 @@
748A42C024AB424500DEB6D0 /* WebDAVClient.swift in Sources */,
B3D513932BA9A32200DE0D36 /* BoxSetup.swift in Sources */,
4A567B082615C6AF002C4D82 /* DropboxCloudProvider.swift in Sources */,
B3408ACA2BCDAA09005271D2 /* BoxError.swift in Sources */,
74C596E824F022AF00FFD17E /* CloudPath.swift in Sources */,
4A05900C2451A107008831F9 /* CloudProvider.swift in Sources */,
4A567B142615C8B8002C4D82 /* GoogleDriveAuthenticator.swift in Sources */,
Expand Down Expand Up @@ -1415,6 +1422,7 @@
4AC75F9C2861A6DE002731FE /* VaultFormat6S3IntegrationTests.swift in Sources */,
4ACA63A02615FE2C00D19304 /* CloudAccessIntegrationTest.swift in Sources */,
B3D513972BA9A44000DE0D36 /* BoxCloudProviderIntegrationTests.swift in Sources */,
B3408AC82BCD32CA005271D2 /* BoxCredentialMock.swift in Sources */,
4ACA64262616054F00D19304 /* IntegrationTestSecrets.swift in Sources */,
4A41D2432641938A00B5D787 /* VaultFormat6OneDriveIntegrationTests.swift in Sources */,
7470C54B26569A7E00E361B8 /* MSAuthenticationProviderMock.swift in Sources */,
Expand Down
45 changes: 27 additions & 18 deletions Sources/CryptomatorCloudAccess/Box/BoxAuthenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,38 @@
// Created by Majid Achhoud on 18.03.24.
//

import Foundation
#if canImport(CryptomatorCloudAccessCore)
import CryptomatorCloudAccessCore
#endif
import AuthenticationServices
import BoxSDK
import Promises
import UIKit

public enum BoxAuthenticatorError: Error {
case authenticationFailed
case authenticationFailed
}

public struct BoxAuthenticator {

private static let sdk = BoxSDK(clientId: BoxSetup.constants.clientId, clientSecret: BoxSetup.constants.clientSecret)

public static func authenticate(from viewController: UIViewController) -> Promise<BoxClient> {
return Promise { fulfill, reject in
sdk.getOAuth2Client() { result in
switch result {
case let .success(client):
fulfill(client)
case .failure(_):
reject(BoxAuthenticatorError.authenticationFailed)
}
}
}
}
public enum BoxAuthenticator {
public static let sdk = BoxSDK(clientId: BoxSetup.constants.clientId, clientSecret: BoxSetup.constants.clientSecret)

public static func authenticate(from viewController: UIViewController, tokenStore: TokenStore) -> Promise<(BoxClient, String)> {
return Promise { fulfill, reject in
sdk.getOAuth2Client(tokenStore: tokenStore, context: viewController as! ASWebAuthenticationPresentationContextProviding) { 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)
}
}
}
}
}
Loading

0 comments on commit afcdff9

Please sign in to comment.