Skip to content

Commit ecb52c4

Browse files
authored
Merge pull request forcedotcom#3946 from wmathurin/dyn_consumer_key
Allow consumer key to be defined at runtime by application
2 parents 362007b + 90df65a commit ecb52c4

35 files changed

+2409
-39
lines changed

.github/DangerFiles/TestOrchestrator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
SCHEMES = ['SalesforceSDKCommon', 'SalesforceAnalytics', 'SalesforceSDKCore', 'SmartStore', 'MobileSync']
1111

1212
modifed_libs = Set[]
13+
1314
for file in (git.modified_files + git.added_files);
1415
scheme = file.split("libs/").last.split("/").first
1516
if SCHEMES.include?(scheme)

.github/workflows/nightly.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
strategy:
3232
fail-fast: false
3333
matrix:
34-
app: [RestAPIExplorer, MobileSyncExplorer]
34+
app: [RestAPIExplorer, MobileSyncExplorer, AuthFlowTester]
3535
ios: [^26, ^18, ^17]
3636
include:
3737
- ios: ^26

.github/workflows/pr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ jobs:
120120
strategy:
121121
fail-fast: false
122122
matrix:
123-
app: [RestAPIExplorer, MobileSyncExplorer]
123+
app: [RestAPIExplorer, MobileSyncExplorer, AuthFlowTester]
124124
ios: [^26, ^18]
125125
include:
126126
- ios: ^26

SalesforceMobileSDK.xcworkspace/contents.xcworkspacedata

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SalesforceMobileSDK.xcworkspace/xcshareddata/xcschemes/Everything.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@
266266
buildForAnalyzing = "YES">
267267
<BuildableReference
268268
BuildableIdentifier = "primary"
269-
BlueprintIdentifier = "B716A3E3218F6EEA009D407F"
269+
BlueprintIdentifier = "F27137B928405BB8003B3D69"
270270
BuildableName = "SalesforceSDKCommonTestApp.app"
271271
BlueprintName = "SalesforceSDKCommonTestApp"
272272
ReferencedContainer = "container:libs/SalesforceSDKCommon/SalesforceSDKCommon.xcodeproj">

SalesforceMobileSDK.xcworkspace/xcshareddata/xcschemes/UnitTests.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@
266266
buildForAnalyzing = "YES">
267267
<BuildableReference
268268
BuildableIdentifier = "primary"
269-
BlueprintIdentifier = "B716A3E3218F6EEA009D407F"
269+
BlueprintIdentifier = "F27137B928405BB8003B3D69"
270270
BuildableName = "SalesforceSDKCommonTestApp.app"
271271
BlueprintName = "SalesforceSDKCommonTestApp"
272272
ReferencedContainer = "container:libs/SalesforceSDKCommon/SalesforceSDKCommon.xcodeproj">

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,19 @@ NS_SWIFT_NAME(SalesforceManager)
203203
*/
204204
@property (nonatomic, copy) SFSDKUserAgentCreationBlock userAgentString NS_SWIFT_NAME(userAgentGenerator);
205205

206+
/**
207+
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.
216+
*/
217+
@property (nonatomic, copy, nullable) SFSDKAppConfigRuntimeSelectorBlock appConfigRuntimeSelectorBlock NS_SWIFT_NAME(bootConfigRuntimeSelector);
218+
206219
/** Use this flag to indicate if the APP will be an identity provider. When enabled this flag allows this application to perform authentication on behalf of another app.
207220
*/
208221
@property (nonatomic,assign) BOOL isIdentityProvider NS_SWIFT_NAME(isIdentityProvider);
@@ -310,6 +323,17 @@ NS_SWIFT_NAME(SalesforceManager)
310323
*/
311324
- (id <SFBiometricAuthenticationManager>)biometricAuthenticationManager;
312325

326+
/**
327+
* Asynchronously retrieves the app config (aka boot config) for the specified login host.
328+
*
329+
* If an appConfigRuntimeSelectorBlock is set, it will be invoked to select the appropriate config.
330+
* If the block is not set or returns nil, the default appConfig will be returned.
331+
*
332+
* @param loginHost The selected login host
333+
* @param callback The callback invoked with the selected app config
334+
*/
335+
- (void)appConfigForLoginHost:(nullable NSString *)loginHost callback:(nonnull void (^)(SFSDKAppConfig * _Nullable))callback NS_SWIFT_NAME(bootConfig(forLoginHost:callback:));
336+
313337
/**
314338
* Creates the NativeLoginManager instance.
315339
*

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,19 @@ - (void)biometricAuthenticationFlowDidComplete:(NSNotification *)notification {
915915
return [SFScreenLockManagerInternal shared];
916916
}
917917

918+
#pragma mark - Runtime App Config (aka Bootconfig) Override
919+
920+
- (void) appConfigForLoginHost:(nullable NSString *)loginHost callback:(nonnull void (^)(SFSDKAppConfig * _Nullable))callback {
921+
if (self.appConfigRuntimeSelectorBlock) {
922+
self.appConfigRuntimeSelectorBlock(loginHost, ^(SFSDKAppConfig *config) {
923+
// Fall back to default appConfig if the selector block returns nil
924+
callback(config ?: self.appConfig);
925+
});
926+
} else {
927+
callback(self.appConfig);
928+
}
929+
}
930+
918931
#pragma mark - Native Login
919932

920933
- (id <SFNativeLoginManager>)useNativeLoginWithConsumerKey:(nonnull NSString *)consumerKey
@@ -965,7 +978,7 @@ - (void)biometricAuthenticationFlowDidComplete:(NSNotification *)notification {
965978

966979
return nativeLogin;
967980
}
968-
981+
969982
@end
970983

971984
NSString *SFAppTypeGetDescription(SFAppType appType){

libs/SalesforceSDKCore/SalesforceSDKCore/Classes/OAuth/JwtAccessToken.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ import Foundation
3030

3131
/// Struct representing a JWT Header
3232
public struct JwtHeader: Codable {
33-
let algorithm: String?
34-
let type: String?
35-
let keyId: String?
36-
let tokenType: String?
37-
let tenantKey: String?
38-
let version: String?
33+
public let algorithm: String?
34+
public let type: String?
35+
public let keyId: String?
36+
public let tokenType: String?
37+
public let tenantKey: String?
38+
public let version: String?
3939

4040
enum CodingKeys: String, CodingKey {
4141
case algorithm = "alg"
@@ -49,13 +49,13 @@ public struct JwtHeader: Codable {
4949

5050
/// Struct representing a JWT Payload
5151
public struct JwtPayload: Codable {
52-
let audience: [String]?
53-
let expirationTime: Int?
54-
let issuer: String?
55-
let notBeforeTime: Int?
56-
let subject: String?
57-
let scopes: String?
58-
let clientId: String?
52+
public let audience: [String]?
53+
public let expirationTime: Int?
54+
public let issuer: String?
55+
public let notBeforeTime: Int?
56+
public let subject: String?
57+
public let scopes: String?
58+
public let clientId: String?
5959

6060
enum CodingKeys: String, CodingKey {
6161
case audience = "aud"
@@ -71,9 +71,9 @@ public struct JwtPayload: Codable {
7171
/// Class representing a JWT Access Token
7272
@objc(SFSDKJwtAccessToken)
7373
public class JwtAccessToken : NSObject {
74-
let rawJwt: String
75-
let header: JwtHeader
76-
let payload: JwtPayload
74+
public let rawJwt: String
75+
public let header: JwtHeader
76+
public let payload: JwtPayload
7777

7878
/// Initializer to parse and decode the JWT string
7979
@objc public init(jwt: String) throws {
@@ -116,7 +116,7 @@ public class JwtAccessToken : NSObject {
116116
}
117117

118118
/// Helper method to decode Base64 URL-encoded strings
119-
private static func decodeBase64Url(_ string: String) throws -> String {
119+
public static func decodeBase64Url(_ string: String) throws -> String {
120120
var base64 = string
121121
.replacingOccurrences(of: "-", with: "+")
122122
.replacingOccurrences(of: "_", with: "/")
@@ -133,7 +133,7 @@ public class JwtAccessToken : NSObject {
133133
}
134134

135135
/// Custom errors for JWT decoding
136-
enum JwtError: Error {
136+
public enum JwtError: Error {
137137
case invalidFormat
138138
case invalidBase64
139139
}

libs/SalesforceSDKCore/SalesforceSDKCore/Classes/Test/SFSDKTestCredentialsData.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ NS_ASSUME_NONNULL_BEGIN
3939
@property (nonatomic, readonly) NSString *redirectUri;
4040
@property (nonatomic, readonly) NSString *loginHost;
4141
@property (nonatomic, readonly) NSString *communityUrl;
42+
@property (nonatomic, readonly) NSString *username;
43+
@property (nonatomic, readonly) NSString *displayName;
4244

4345
@end
4446

0 commit comments

Comments
 (0)