Skip to content

Commit 0fc755c

Browse files
committed
Added explaining comment in SalesforceSDKManager
Static configuration can be edited Took out broken new tests (will bring them back if they make sense)
1 parent d22f67f commit 0fc755c

File tree

7 files changed

+143
-212
lines changed

7 files changed

+143
-212
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,14 @@ NS_SWIFT_NAME(SalesforceManager)
205205

206206
/**
207207
Block to dynamically select the app config at runtime based on login host.
208+
209+
NB: SFUserAccountManager stores the consumer key, callback URL, etc. in its shared
210+
instance, backed by shared prefs and initialized from the static boot config.
211+
Previously, the app always used these shared instance values for login.
212+
Now, the app can inject alternate values instead — in that case, the shared
213+
instance and prefs are left untouched (not read or overwritten).
214+
The consumer key and related values used for login are saved in the user
215+
account credentials (as before) and therefore used later for token refresh.
208216
*/
209217
@property (nonatomic, copy, nullable) SFSDKAppConfigRuntimeSelectorBlock appConfigRuntimeSelectorBlock NS_SWIFT_NAME(bootConfigRuntimeSelector);
210218

native/SampleApps/AuthFlowTester/AuthFlowTester.xcodeproj/project.pbxproj

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
4F1A8CCA2EAB16450037DC89 /* bootconfig.plist in Resources */ = {isa = PBXBuildFile; fileRef = AUTH010 /* bootconfig.plist */; };
1111
4F1A8CCB2EAB16490037DC89 /* bootconfig2.plist in Resources */ = {isa = PBXBuildFile; fileRef = AUTH036 /* bootconfig2.plist */; };
12+
4F1A8CCD2EAFEA7C0037DC89 /* BootConfigEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F1A8CCC2EAFEA7C0037DC89 /* BootConfigEditor.swift */; };
1213
4F95A89B2EAAD00000000001 /* test_credentials.json in Resources */ = {isa = PBXBuildFile; fileRef = 4F95A89A2EAAD00000000001 /* test_credentials.json */; };
1314
4F95A89C2EA806E700C98D18 /* SalesforceAnalytics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4F95A8962EA801DC00C98D18 /* SalesforceAnalytics.framework */; };
1415
4F95A89D2EA806E700C98D18 /* SalesforceAnalytics.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4F95A8962EA801DC00C98D18 /* SalesforceAnalytics.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
@@ -28,8 +29,6 @@
2829
AUTH037 /* UserCredentialsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AUTH038 /* UserCredentialsView.swift */; };
2930
AUTH040 /* RestApiTestView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AUTH041 /* RestApiTestView.swift */; };
3031
AUTH042 /* OAuthConfigurationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AUTH043 /* OAuthConfigurationView.swift */; };
31-
AUTH045 /* DefaultConfigView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AUTH046 /* DefaultConfigView.swift */; };
32-
AUTH047 /* DynamicConfigView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AUTH048 /* DynamicConfigView.swift */; };
3332
AUTH049 /* JwtAccessView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AUTH050 /* JwtAccessView.swift */; };
3433
AUTH051 /* InfoRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AUTH052 /* InfoRowView.swift */; };
3534
AUTH053 /* FlowTypesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AUTH054 /* FlowTypesView.swift */; };
@@ -60,6 +59,7 @@
6059
/* End PBXCopyFilesBuildPhase section */
6160

6261
/* Begin PBXFileReference section */
62+
4F1A8CCC2EAFEA7C0037DC89 /* BootConfigEditor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BootConfigEditor.swift; sourceTree = "<group>"; };
6363
4F95A8962EA801DC00C98D18 /* SalesforceAnalytics.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SalesforceAnalytics.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6464
4F95A8982EA801DC00C98D18 /* SalesforceSDKCommon.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SalesforceSDKCommon.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6565
4F95A89A2EA801DC00C98D18 /* SalesforceSDKCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SalesforceSDKCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -80,8 +80,6 @@
8080
AUTH038 /* UserCredentialsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserCredentialsView.swift; sourceTree = "<group>"; };
8181
AUTH041 /* RestApiTestView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestApiTestView.swift; sourceTree = "<group>"; };
8282
AUTH043 /* OAuthConfigurationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OAuthConfigurationView.swift; sourceTree = "<group>"; };
83-
AUTH046 /* DefaultConfigView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultConfigView.swift; sourceTree = "<group>"; };
84-
AUTH048 /* DynamicConfigView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DynamicConfigView.swift; sourceTree = "<group>"; };
8583
AUTH050 /* JwtAccessView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JwtAccessView.swift; sourceTree = "<group>"; };
8684
AUTH052 /* InfoRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoRowView.swift; sourceTree = "<group>"; };
8785
AUTH054 /* FlowTypesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowTypesView.swift; sourceTree = "<group>"; };
@@ -195,12 +193,11 @@
195193
AUTH039 /* Views */ = {
196194
isa = PBXGroup;
197195
children = (
196+
4F1A8CCC2EAFEA7C0037DC89 /* BootConfigEditor.swift */,
198197
4FEBAF282EA9B91500D4880A /* RevokeView.swift */,
199198
AUTH038 /* UserCredentialsView.swift */,
200199
AUTH041 /* RestApiTestView.swift */,
201200
AUTH043 /* OAuthConfigurationView.swift */,
202-
AUTH046 /* DefaultConfigView.swift */,
203-
AUTH048 /* DynamicConfigView.swift */,
204201
AUTH050 /* JwtAccessView.swift */,
205202
AUTH052 /* InfoRowView.swift */,
206203
AUTH054 /* FlowTypesView.swift */,
@@ -331,11 +328,10 @@
331328
AUTH037 /* UserCredentialsView.swift in Sources */,
332329
AUTH040 /* RestApiTestView.swift in Sources */,
333330
AUTH042 /* OAuthConfigurationView.swift in Sources */,
334-
AUTH045 /* DefaultConfigView.swift in Sources */,
335-
AUTH047 /* DynamicConfigView.swift in Sources */,
336331
4FEBAF292EA9B91500D4880A /* RevokeView.swift in Sources */,
337332
AUTH049 /* JwtAccessView.swift in Sources */,
338333
AUTH051 /* InfoRowView.swift in Sources */,
334+
4F1A8CCD2EAFEA7C0037DC89 /* BootConfigEditor.swift in Sources */,
339335
AUTH053 /* FlowTypesView.swift in Sources */,
340336
);
341337
};

native/SampleApps/AuthFlowTester/AuthFlowTester/ViewControllers/ConfigPickerViewController.swift

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ import SalesforceSDKCore
3030

3131
struct ConfigPickerView: View {
3232
@State private var isLoading = false
33+
@State private var staticConsumerKey = ""
34+
@State private var staticCallbackUrl = ""
35+
@State private var staticScopes = ""
3336
@State private var dynamicConsumerKey = ""
3437
@State private var dynamicCallbackUrl = ""
3538
@State private var dynamicScopes = ""
@@ -46,16 +49,25 @@ struct ConfigPickerView: View {
4649

4750
Divider()
4851

49-
// Default config section
50-
DefaultConfigView(
52+
// Static config section
53+
BootConfigEditor(
54+
title: "Static Configuration",
55+
buttonLabel: "Use static config",
56+
buttonColor: .blue,
57+
consumerKey: $staticConsumerKey,
58+
callbackUrl: $staticCallbackUrl,
59+
scopes: $staticScopes,
5160
isLoading: isLoading,
52-
onUseConfig: handleDefaultConfig
61+
onUseConfig: handleStaticConfig
5362
)
5463

5564
Divider()
5665

5766
// Dynamic config section
58-
DynamicConfigView(
67+
BootConfigEditor(
68+
title: "Dynamic Configuration",
69+
buttonLabel: "Use dynamic config",
70+
buttonColor: .green,
5971
consumerKey: $dynamicConsumerKey,
6072
callbackUrl: $dynamicCallbackUrl,
6173
scopes: $dynamicScopes,
@@ -77,7 +89,7 @@ struct ConfigPickerView: View {
7789
}
7890
.navigationViewStyle(.stack)
7991
.onAppear {
80-
loadDynamicConfigDefaults()
92+
loadConfigDefaults()
8193
}
8294
}
8395

@@ -93,8 +105,15 @@ struct ConfigPickerView: View {
93105

94106
// MARK: - Helper Methods
95107

96-
private func loadDynamicConfigDefaults() {
97-
// Load initial values from bootconfig2.plist
108+
private func loadConfigDefaults() {
109+
// Load static config from bootconfig.plist (via SalesforceManager)
110+
if let config = SalesforceManager.shared.bootConfig {
111+
staticConsumerKey = config.remoteAccessConsumerKey
112+
staticCallbackUrl = config.oauthRedirectURI
113+
staticScopes = config.oauthScopes.sorted().joined(separator: " ")
114+
}
115+
116+
// Load dynamic config defaults from bootconfig2.plist
98117
if let config = BootConfig("/bootconfig2.plist") {
99118
dynamicConsumerKey = config.remoteAccessConsumerKey
100119
dynamicCallbackUrl = config.oauthRedirectURI
@@ -104,12 +123,37 @@ struct ConfigPickerView: View {
104123

105124
// MARK: - Button Actions
106125

107-
private func handleDefaultConfig() {
126+
private func handleStaticConfig() {
108127
isLoading = true
109128

129+
// Parse scopes from space-separated string
130+
let scopesArray = staticScopes
131+
.split(separator: " ")
132+
.map { String($0) }
133+
.filter { !$0.isEmpty }
134+
135+
// Create BootConfig with values from the editor
136+
var configDict: [String: Any] = [
137+
"remoteAccessConsumerKey": staticConsumerKey,
138+
"oauthRedirectURI": staticCallbackUrl,
139+
"shouldAuthenticate": true
140+
]
141+
142+
// Only add scopes if not empty
143+
if !scopesArray.isEmpty {
144+
configDict["oauthScopes"] = scopesArray
145+
}
146+
147+
// Set as the bootConfig
148+
SalesforceManager.shared.bootConfig = BootConfig(configDict)
110149
SalesforceManager.shared.bootConfigRuntimeSelector = nil
111150

112-
// Use default bootconfig - no additional setup needed
151+
// Update UserAccountManager properties
152+
UserAccountManager.shared.oauthClientID = staticConsumerKey
153+
UserAccountManager.shared.oauthCompletionURL = staticCallbackUrl
154+
UserAccountManager.shared.scopes = scopesArray.isEmpty ? [] : Set(scopesArray)
155+
156+
// Proceed with login
113157
onConfigurationCompleted()
114158
}
115159

native/SampleApps/AuthFlowTester/AuthFlowTester/Views/DynamicConfigView.swift renamed to native/SampleApps/AuthFlowTester/AuthFlowTester/Views/BootConfigEditor.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
DynamicConfigView.swift
2+
BootConfigEditor.swift
33
AuthFlowTester
44

55
Copyright (c) 2025-present, salesforce.com, inc. All rights reserved.
@@ -28,7 +28,10 @@
2828
import SwiftUI
2929
import SalesforceSDKCore
3030

31-
struct DynamicConfigView: View {
31+
struct BootConfigEditor: View {
32+
let title: String
33+
let buttonLabel: String
34+
let buttonColor: Color
3235
@Binding var consumerKey: String
3336
@Binding var callbackUrl: String
3437
@Binding var scopes: String
@@ -44,7 +47,7 @@ struct DynamicConfigView: View {
4447
}
4548
}) {
4649
HStack {
47-
Text("Dynamic Configuration")
50+
Text(title)
4851
.font(.headline)
4952
.foregroundColor(.primary)
5053
Spacer()
@@ -64,6 +67,7 @@ struct DynamicConfigView: View {
6467
.textFieldStyle(RoundedBorderTextFieldStyle())
6568
.autocapitalization(.none)
6669
.disableAutocorrection(true)
70+
.accessibilityIdentifier("consumerKeyTextField")
6771

6872
Text("Callback URL:")
6973
.font(.caption)
@@ -73,6 +77,7 @@ struct DynamicConfigView: View {
7377
.textFieldStyle(RoundedBorderTextFieldStyle())
7478
.autocapitalization(.none)
7579
.disableAutocorrection(true)
80+
.accessibilityIdentifier("callbackUrlTextField")
7681

7782
Text("Scopes (space-separated):")
7883
.font(.caption)
@@ -82,17 +87,18 @@ struct DynamicConfigView: View {
8287
.textFieldStyle(RoundedBorderTextFieldStyle())
8388
.autocapitalization(.none)
8489
.disableAutocorrection(true)
90+
.accessibilityIdentifier("scopesTextField")
8591
}
8692
.padding(.horizontal)
8793
}
8894

8995
Button(action: onUseConfig) {
90-
Text("Use dynamic config")
96+
Text(buttonLabel)
9197
.font(.headline)
9298
.foregroundColor(.white)
9399
.frame(maxWidth: .infinity)
94100
.frame(height: 44)
95-
.background(Color.green)
101+
.background(buttonColor)
96102
.cornerRadius(8)
97103
}
98104
.disabled(isLoading)

native/SampleApps/AuthFlowTester/AuthFlowTester/Views/DefaultConfigView.swift

Lines changed: 0 additions & 121 deletions
This file was deleted.

0 commit comments

Comments
 (0)