Skip to content
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 @@ -237,6 +237,10 @@ NS_SWIFT_NAME(SalesforceManager)
*/
@property (nonatomic, assign) BOOL useWebServerAuthentication;

/** Whether or not the app supports welcome discovery, this should only be enabled if the connected app is supported.
*/
@property (nonatomic, assign) BOOL supportsWelcomeDiscovery;

/** Whether hybrid authentication flow should be used. Defaults to YES.
*/
@property (nonatomic, assign) BOOL useHybridAuthentication;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ - (instancetype)init {
self.useWebServerAuthentication = YES;
self.blockSalesforceIntegrationUser = NO;
self.useHybridAuthentication = YES;
self.supportsWelcomeDiscovery = NO;
[self setupServiceConfiguration];
_snapshotViewControllers = [SFSDKSafeMutableDictionary new];
_nativeLoginViewControllers = [SFSDKSafeMutableDictionary new];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ enum DomainDiscovery: String {
case callbackURL = "callback_url"
}
}

/* TODO: Keep this list of client ids up to date with those
* supported by Salesforce Welcome Discovery or remove it
* when no longer required.
*/
static let supportedClientIds: Set<String> = [
"SfdcMobileChatterAndroid",
"SfdcMobileChatteriOS"
]
}

/// Represents the result of a domain discovery operation.
Expand Down Expand Up @@ -87,14 +78,20 @@ public class DomainDiscoveryCoordinator: NSObject {
}

@objc
@available(*, deprecated, renamed: "isDiscoveryDomain(domain:)")
public func isDiscoveryDomain(_ domain: String?, clientId: String?) -> Bool {
guard let domain = domain, let clientId = clientId else { return false }
return isDiscoveryDomain(domain)
}

@objc
public func isDiscoveryDomain(_ domain: String?) -> Bool {
guard let domain = domain else { return false }
let isDiscovery = domain.lowercased().contains(DomainDiscovery.URLComponent.path.rawValue)
let isSupportedClient = DomainDiscovery.supportedClientIds.contains(clientId)
if isDiscovery && !isSupportedClient {
SFSDKCoreLogger.e(classForCoder, message: "\(domain) is a discovery domain, but client ID '\(clientId)' is not supported.")
let discoveryEnabled = SalesforceManager.shared.supportsWelcomeDiscovery
if isDiscovery && !discoveryEnabled {
SFSDKCoreLogger.w(classForCoder, message: "\(domain) is a discovery domain, but welcome discovery isn't enabled.")
}
return isDiscovery && isSupportedClient
return isDiscovery && discoveryEnabled
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#import "SFSDKIDPConstants.h"
#import "SFSDKAuthSession.h"
#import "SFSDKAuthRequest.h"
#import <SalesforceSDKCore/SalesforceSDKCore-Swift.h>
#import <SalesforceSDKCommon/SalesforceSDKCommon-Swift.h>
#import <SalesforceSDKCommon/SFSDKDatasharingHelper.h>
#import <LocalAuthentication/LocalAuthentication.h>
Expand Down Expand Up @@ -213,8 +214,7 @@ - (void)authenticate {

- (void)authenticateWithCredentials:(SFOAuthCredentials *)credentials {
self.credentials = credentials;
if ([self.domainDiscoveryCoordinator isDiscoveryDomain:self.credentials.domain
clientId:self.credentials.clientId]) {
if ([self.domainDiscoveryCoordinator isDiscoveryDomain:self.credentials.domain]) {
[self runMyDomainDiscoveryAndAuthenticate];
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,15 @@ final class DomainDiscoveryCoordinatorTests: XCTestCase {
XCTAssertEqual(results?.myDomain, expectedDomain)
XCTAssertEqual(results?.loginHint, expectedLoginHint)
}
}

func testDiscoveryFlag() throws {
let coordinator = DomainDiscoveryCoordinator()
let domain = "welcome.salesforce.com/discovery"

SalesforceManager.shared.supportsWelcomeDiscovery = false
XCTAssertFalse(coordinator.isDiscoveryDomain(domain))

SalesforceManager.shared.supportsWelcomeDiscovery = true
XCTAssertTrue(coordinator.isDiscoveryDomain(domain))
}
}
Loading