@@ -347,7 +347,7 @@ - (void)notifyDelegateOfFailure:(NSError*)error authInfo:(SFOAuthInfo *)info
347347 });
348348 }
349349 self.authInfo = nil ;
350- [self resetFrontDoorBridgeUrl ];
350+ [self resetFrontDoorBridge ];
351351}
352352
353353- (void )notifyDelegateOfSuccess : (SFOAuthInfo *)authInfo
@@ -357,7 +357,7 @@ - (void)notifyDelegateOfSuccess:(SFOAuthInfo *)authInfo
357357 [self .delegate oauthCoordinatorDidAuthenticate: self authInfo: authInfo];
358358 }
359359 self.authInfo = nil ;
360- [self resetFrontDoorBridgeUrl ];
360+ [self resetFrontDoorBridge ];
361361}
362362
363363- (void )notifyDelegateOfBeginAuthentication
@@ -553,8 +553,8 @@ - (void)loadWebViewWithUrlString:(NSString *)urlString cookie:(BOOL)enableCookie
553553 [SFSDKCoreLogger d: [self class ] format: @" %@ Loading web view for '%@ ' auth flow, with URL: %@ " , NSStringFromSelector (_cmd ), self .authInfo.authTypeDescription, [urlToLoad sfsdk_redactedAbsoluteString: @[ @" sid" ]]];
554554 dispatch_async (dispatch_get_main_queue (), ^{
555555 // If a valid overriding Salesforce Identity API UI Bridge front door bridge is present, load it.
556- if (self.overrideWithFrontDoorBridgeUrl ) {
557- [self .view loadRequest: [NSURLRequest requestWithURL: self .overrideWithFrontDoorBridgeUrl]];
556+ if (self.frontdoorBridge . overrideWithFrontDoorBridgeUrl ) {
557+ [self .view loadRequest: [NSURLRequest requestWithURL: self .frontdoorBridge. overrideWithFrontDoorBridgeUrl]];
558558
559559 } else {
560560 [self .view loadRequest: request];
@@ -580,7 +580,7 @@ - (void)beginTokenEndpointFlow {
580580 [SFSDKCoreLogger i: [self class ] format: @" %@ : Initiating authorization code flow." , NSStringFromSelector (_cmd )];
581581 request.approvalCode = self.approvalCode ;
582582 // Choose either the default generated code verifier or the code verifier matching the overriding Salesforce Identity API UI Bridge front door bridge.
583- request.codeVerifier = self.overrideWithCodeVerifier ? self.overrideWithCodeVerifier : self.codeVerifier ;
583+ request.codeVerifier = self.frontdoorBridge . overrideWithCodeVerifier ? self. frontdoorBridge .overrideWithCodeVerifier : self.codeVerifier ;
584584 [self .authClient accessTokenForApprovalCode: request completion: ^(SFSDKOAuthTokenEndpointResponse * response) {
585585 __strong typeof (weakSelf) strongSelf = weakSelf;
586586 [strongSelf handleResponse: response];
@@ -791,10 +791,8 @@ - (NSString *)approvalURLForEndpoint:(NSString *)authorizeEndpoint
791791 * Resets all state related to Salesforce Identity API UI Bridge front door bridge URL log in to its default
792792 * inactive state.
793793 */
794- -(void ) resetFrontDoorBridgeUrl {
795- self.overridingFrontDoorBridgeUrlMatchesConsumerKey = YES ;
796- self.overrideWithFrontDoorBridgeUrl = nil ;
797- self.overrideWithCodeVerifier = nil ;
794+ -(void ) resetFrontDoorBridge {
795+ self.frontdoorBridge = nil ;
798796}
799797
800798- (NSString *)scopeQueryParamString {
@@ -819,7 +817,7 @@ - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigati
819817 NSString *requestUrl = [url absoluteString ];
820818 if ([self isRedirectURL: requestUrl]) {
821819 // Determine if presence of override parameters require the user agent flow.
822- BOOL overrideWithUserAgentFlow = self.overrideWithFrontDoorBridgeUrl && !self.overrideWithCodeVerifier ;
820+ BOOL overrideWithUserAgentFlow = self.frontdoorBridge . overrideWithFrontDoorBridgeUrl && !self. frontdoorBridge .overrideWithCodeVerifier ;
823821 if ( [[SalesforceSDKManager sharedManager ] useWebServerAuthentication ] && !overrideWithUserAgentFlow) {
824822 [self handleWebServerResponse: url]; // Web server flow/URLs with query string parameters.
825823 } else {
@@ -983,3 +981,30 @@ - (NSString *)brandedAuthorizeURL{
983981}
984982
985983@end
984+
985+ @implementation SFOAuthCoordinatorFrontdoorBridge
986+
987+ - initWithFrontdoorBridgeUrl : (NSURL *)frontdoorBridgeUrl codeVerifier : (NSString *)codeVerifier {
988+ self = [super init ];
989+
990+ NSURLComponents * frontdoorBridgeUrlComponents = [NSURLComponents
991+ componentsWithURL: frontdoorBridgeUrl
992+ resolvingAgainstBaseURL: YES ];
993+ NSArray <NSURLQueryItem *> * frontdoorBridgeUrlQueryItems = frontdoorBridgeUrlComponents.queryItems ;
994+ NSString * startUrlString = [frontdoorBridgeUrlQueryItems filteredArrayUsingPredicate: [NSPredicate predicateWithFormat: @" name == 'startURL'" ]][0 ].value ;
995+ NSURL * startUrl = [[NSURL alloc ] initWithString: startUrlString];
996+ NSURLComponents * startUrlComponents = [NSURLComponents componentsWithURL: startUrl resolvingAgainstBaseURL: YES ];
997+ NSArray <NSURLQueryItem *> * startUrlQueryItems = startUrlComponents.queryItems ;
998+ NSString * frontdoorBridgeUrlClientId = [startUrlQueryItems filteredArrayUsingPredicate: [NSPredicate predicateWithFormat: @" name == 'client_id'" ]][0 ].value ;
999+
1000+ self.overridingFrontDoorBridgeUrlMatchesConsumerKey = [frontdoorBridgeUrlClientId isEqualToString: [[SalesforceSDKManager sharedManager ] appConfig ].remoteAccessConsumerKey];
1001+
1002+ if (self.overridingFrontDoorBridgeUrlMatchesConsumerKey ) {
1003+ self.overrideWithCodeVerifier = codeVerifier;
1004+ self.overrideWithFrontDoorBridgeUrl = frontdoorBridgeUrl;
1005+ }
1006+
1007+ return self;
1008+ }
1009+
1010+ @end
0 commit comments