Skip to content

Commit 12143c2

Browse files
authored
Merge pull request forcedotcom#3945 from bbirman/welcome-flag
Add welcome discovery flag instead of having hardcoded consumer keys
2 parents f8a40a6 + cb646bf commit 12143c2

File tree

5 files changed

+30
-17
lines changed

5 files changed

+30
-17
lines changed

libs/SalesforceSDKCore/SalesforceSDKCore/Classes/Common/SalesforceSDKManager.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ NS_SWIFT_NAME(SalesforceManager)
237237
*/
238238
@property (nonatomic, assign) BOOL useWebServerAuthentication;
239239

240+
/** Whether or not the app supports welcome discovery, this should only be enabled if the connected app is supported.
241+
*/
242+
@property (nonatomic, assign) BOOL supportsWelcomeDiscovery;
243+
240244
/** Whether hybrid authentication flow should be used. Defaults to YES.
241245
*/
242246
@property (nonatomic, assign) BOOL useHybridAuthentication;

libs/SalesforceSDKCore/SalesforceSDKCore/Classes/Common/SalesforceSDKManager.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ - (instancetype)init {
315315
self.useWebServerAuthentication = YES;
316316
self.blockSalesforceIntegrationUser = NO;
317317
self.useHybridAuthentication = YES;
318+
self.supportsWelcomeDiscovery = NO;
318319
[self setupServiceConfiguration];
319320
_snapshotViewControllers = [SFSDKSafeMutableDictionary new];
320321
_nativeLoginViewControllers = [SFSDKSafeMutableDictionary new];

libs/SalesforceSDKCore/SalesforceSDKCore/Classes/OAuth/DomainDiscoveryCoordinator.swift

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@ enum DomainDiscovery: String {
1515
case callbackURL = "callback_url"
1616
}
1717
}
18-
19-
/* TODO: Keep this list of client ids up to date with those
20-
* supported by Salesforce Welcome Discovery or remove it
21-
* when no longer required.
22-
*/
23-
static let supportedClientIds: Set<String> = [
24-
"SfdcMobileChatterAndroid",
25-
"SfdcMobileChatteriOS"
26-
]
2718
}
2819

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

8980
@objc
81+
@available(*, deprecated, renamed: "isDiscoveryDomain(domain:)")
9082
public func isDiscoveryDomain(_ domain: String?, clientId: String?) -> Bool {
91-
guard let domain = domain, let clientId = clientId else { return false }
83+
return isDiscoveryDomain(domain)
84+
}
85+
86+
@objc
87+
public func isDiscoveryDomain(_ domain: String?) -> Bool {
88+
guard let domain = domain else { return false }
9289
let isDiscovery = domain.lowercased().contains(DomainDiscovery.URLComponent.path.rawValue)
93-
let isSupportedClient = DomainDiscovery.supportedClientIds.contains(clientId)
94-
if isDiscovery && !isSupportedClient {
95-
SFSDKCoreLogger.e(classForCoder, message: "\(domain) is a discovery domain, but client ID '\(clientId)' is not supported.")
90+
let discoveryEnabled = SalesforceManager.shared.supportsWelcomeDiscovery
91+
if isDiscovery && !discoveryEnabled {
92+
SFSDKCoreLogger.w(classForCoder, message: "\(domain) is a discovery domain, but welcome discovery isn't enabled.")
9693
}
97-
return isDiscovery && isSupportedClient
94+
return isDiscovery && discoveryEnabled
9895
}
9996
}
10097

libs/SalesforceSDKCore/SalesforceSDKCore/Classes/OAuth/SFOAuthCoordinator.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#import "SFSDKIDPConstants.h"
5050
#import "SFSDKAuthSession.h"
5151
#import "SFSDKAuthRequest.h"
52+
#import <SalesforceSDKCore/SalesforceSDKCore-Swift.h>
5253
#import <SalesforceSDKCommon/SalesforceSDKCommon-Swift.h>
5354
#import <SalesforceSDKCommon/SFSDKDatasharingHelper.h>
5455
#import <LocalAuthentication/LocalAuthentication.h>
@@ -213,8 +214,7 @@ - (void)authenticate {
213214

214215
- (void)authenticateWithCredentials:(SFOAuthCredentials *)credentials {
215216
self.credentials = credentials;
216-
if ([self.domainDiscoveryCoordinator isDiscoveryDomain:self.credentials.domain
217-
clientId:self.credentials.clientId]) {
217+
if ([self.domainDiscoveryCoordinator isDiscoveryDomain:self.credentials.domain]) {
218218
[self runMyDomainDiscoveryAndAuthenticate];
219219
return;
220220
}

libs/SalesforceSDKCore/SalesforceSDKCoreTests/DomainDiscoveryCoordinatorTests.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,15 @@ final class DomainDiscoveryCoordinatorTests: XCTestCase {
155155
XCTAssertEqual(results?.myDomain, expectedDomain)
156156
XCTAssertEqual(results?.loginHint, expectedLoginHint)
157157
}
158-
}
158+
159+
func testDiscoveryFlag() throws {
160+
let coordinator = DomainDiscoveryCoordinator()
161+
let domain = "welcome.salesforce.com/discovery"
162+
163+
SalesforceManager.shared.supportsWelcomeDiscovery = false
164+
XCTAssertFalse(coordinator.isDiscoveryDomain(domain))
165+
166+
SalesforceManager.shared.supportsWelcomeDiscovery = true
167+
XCTAssertTrue(coordinator.isDiscoveryDomain(domain))
168+
}
169+
}

0 commit comments

Comments
 (0)