Skip to content

Commit 3fa16e5

Browse files
committed
Using SalesforceManager.shared.bootConfigRuntimeSelector
Also showing scopes in config screen and allowing user to enter scopes for dynamic config
1 parent 5fae385 commit 3fa16e5

File tree

4 files changed

+63
-9
lines changed

4 files changed

+63
-9
lines changed

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

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct ConfigPickerView: View {
3232
@State private var isLoading = false
3333
@State private var dynamicConsumerKey = ""
3434
@State private var dynamicCallbackUrl = ""
35+
@State private var dynamicScopes = ""
3536

3637
let onConfigurationCompleted: () -> Void
3738

@@ -57,6 +58,7 @@ struct ConfigPickerView: View {
5758
DynamicConfigView(
5859
consumerKey: $dynamicConsumerKey,
5960
callbackUrl: $dynamicCallbackUrl,
61+
scopes: $dynamicScopes,
6062
isLoading: isLoading,
6163
onUseConfig: handleDynamicBootconfig
6264
)
@@ -94,8 +96,9 @@ struct ConfigPickerView: View {
9496
private func loadDynamicConfigDefaults() {
9597
// Load initial values from bootconfig2.plist
9698
if let config = BootConfig("/bootconfig2.plist") {
97-
dynamicConsumerKey = config.remoteAccessConsumerKey ?? ""
98-
dynamicCallbackUrl = config.oauthRedirectURI ?? ""
99+
dynamicConsumerKey = config.remoteAccessConsumerKey
100+
dynamicCallbackUrl = config.oauthRedirectURI
101+
dynamicScopes = config.oauthScopes.sorted().joined(separator: " ")
99102
}
100103
}
101104

@@ -104,7 +107,7 @@ struct ConfigPickerView: View {
104107
private func handleDefaultConfig() {
105108
isLoading = true
106109

107-
SalesforceManager.shared.revertToBootConfig()
110+
SalesforceManager.shared.bootConfigRuntimeSelector = nil
108111

109112
// Use default bootconfig - no additional setup needed
110113
onConfigurationCompleted()
@@ -113,11 +116,27 @@ struct ConfigPickerView: View {
113116
private func handleDynamicBootconfig() {
114117
isLoading = true
115118

116-
// Use the values from the text fields
117-
SalesforceManager.shared.overrideBootConfig(
118-
consumerKey: dynamicConsumerKey,
119-
callbackUrl: dynamicCallbackUrl
120-
)
119+
SalesforceManager.shared.bootConfigRuntimeSelector = { _ in
120+
// Create dynamic BootConfig from user-entered values
121+
// Parse scopes from space-separated string
122+
let scopesArray = self.dynamicScopes
123+
.split(separator: " ")
124+
.map { String($0) }
125+
.filter { !$0.isEmpty }
126+
127+
var configDict: [String: Any] = [
128+
"remoteAccessConsumerKey": self.dynamicConsumerKey,
129+
"oauthRedirectURI": self.dynamicCallbackUrl,
130+
"shouldAuthenticate": true
131+
]
132+
133+
// Only add scopes if not empty
134+
if !scopesArray.isEmpty {
135+
configDict["oauthScopes"] = scopesArray
136+
}
137+
138+
return BootConfig(configDict)
139+
}
121140

122141
// Proceed with login
123142
onConfigurationCompleted()

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ struct DefaultConfigView: View {
7272
.frame(maxWidth: .infinity, alignment: .leading)
7373
.background(Color(.systemGray6))
7474
.cornerRadius(4)
75+
76+
Text("Scopes:")
77+
.font(.caption)
78+
.foregroundColor(.secondary)
79+
Text(defaultScopes)
80+
.font(.system(.caption, design: .monospaced))
81+
.padding(8)
82+
.frame(maxWidth: .infinity, alignment: .leading)
83+
.background(Color(.systemGray6))
84+
.cornerRadius(4)
7585
}
7686
.padding(.horizontal)
7787
}
@@ -100,5 +110,12 @@ struct DefaultConfigView: View {
100110
private var defaultCallbackUrl: String {
101111
return SalesforceManager.shared.bootConfig?.oauthRedirectURI ?? ""
102112
}
113+
114+
private var defaultScopes: String {
115+
guard let scopes = SalesforceManager.shared.bootConfig?.oauthScopes else {
116+
return "(none)"
117+
}
118+
return scopes.isEmpty ? "(none)" : scopes.sorted().joined(separator: ", ")
119+
}
103120
}
104121

native/SampleApps/AuthFlowTester/AuthFlowTester/Views/DynamicConfigView.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import SalesforceSDKCore
3131
struct DynamicConfigView: View {
3232
@Binding var consumerKey: String
3333
@Binding var callbackUrl: String
34+
@Binding var scopes: String
3435
let isLoading: Bool
3536
let onUseConfig: () -> Void
3637
@State private var isExpanded: Bool = false
@@ -72,12 +73,21 @@ struct DynamicConfigView: View {
7273
.textFieldStyle(RoundedBorderTextFieldStyle())
7374
.autocapitalization(.none)
7475
.disableAutocorrection(true)
76+
77+
Text("Scopes (space-separated):")
78+
.font(.caption)
79+
.foregroundColor(.secondary)
80+
TextField("e.g. id api refresh_token", text: $scopes)
81+
.font(.system(.caption, design: .monospaced))
82+
.textFieldStyle(RoundedBorderTextFieldStyle())
83+
.autocapitalization(.none)
84+
.disableAutocorrection(true)
7585
}
7686
.padding(.horizontal)
7787
}
7888

7989
Button(action: onUseConfig) {
80-
Text("Use dynamic bootconfig")
90+
Text("Use dynamic config")
8191
.font(.headline)
8292
.foregroundColor(.white)
8393
.frame(maxWidth: .infinity)

native/SampleApps/AuthFlowTester/AuthFlowTester/Views/OAuthConfigurationView.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ struct OAuthConfigurationView: View {
5656

5757
InfoRowView(label: "Configured Callback URL:",
5858
value: configuredCallbackUrl)
59+
60+
InfoRowView(label: "Configured Scopes:",
61+
value: configuredScopes)
5962
}
6063
}
6164
.padding()
@@ -81,5 +84,10 @@ struct OAuthConfigurationView: View {
8184
private var configuredCallbackUrl: String {
8285
return UserAccountManager.shared.oauthCompletionURL ?? ""
8386
}
87+
88+
private var configuredScopes: String {
89+
let scopes = UserAccountManager.shared.scopes
90+
return scopes.isEmpty ? "(none)" : scopes.sorted().joined(separator: ", ")
91+
}
8492
}
8593

0 commit comments

Comments
 (0)