@@ -608,26 +608,38 @@ - (BOOL)authenticateWithRequest:(SFSDKAuthRequest *)request
608608 initWithFrontdoorBridgeUrl: frontDoorBridgeUrl
609609 codeVerifier: codeVerifier];
610610 }
611- authSession.oauthCoordinator .loginHint = loginHint;
611+ // Login for Admin: when the request carries a My Domain override (set by
612+ // loginViewControllerDidSelectLoginForAdmin: in phase-2 Welcome Discovery),
613+ // route the browser session to the resolved My Domain and forward the
614+ // captured login hint, while leaving request.loginHost — and therefore
615+ // every other restart path — pointed at the originally configured host.
616+ BOOL useLfaOverride = request.loginAsAdmin && request.loginAsAdminMyDomain .length > 0 ;
617+ if (useLfaOverride) {
618+ authSession.credentials .domain = request.loginAsAdminMyDomain ;
619+ authSession.oauthCoordinator .loginHint = request.loginAsAdminLoginHint ;
620+ } else {
621+ authSession.oauthCoordinator .loginHint = loginHint;
622+ }
623+ NSString *appConfigLoginHost = useLfaOverride ? request.loginAsAdminMyDomain : request.loginHost ;
612624 NSString *sceneId = authSession.sceneId ;
613625 self.authSessions [sceneId] = authSession;
614-
626+
615627 if (self.nativeLoginEnabled && !self.shouldFallbackToWebAuthentication ) {
616628 authSession.oauthCoordinator .useNativeAuth = YES ;
617629 }
618-
630+
619631 dispatch_async (dispatch_get_main_queue (), ^{
620632 [SFSDKWebViewStateManager removeSessionForcefullyWithCompletionHandler: ^{
621633 // Get app config for the login host. If appConfigRuntimeSelectorBlock is set,
622634 // it will be invoked to select the appropriate config. Otherwise, returns the default appConfig.
623- [[SalesforceSDKManager sharedManager ] appConfigForLoginHost: request.loginHost callback: ^(SFSDKAppConfig* appConfig) {
635+ [[SalesforceSDKManager sharedManager ] appConfigForLoginHost: appConfigLoginHost callback: ^(SFSDKAppConfig* appConfig) {
624636 authSession.credentials .clientId = appConfig.remoteAccessConsumerKey ;
625637 authSession.credentials .redirectUri = appConfig.oauthRedirectURI ;
626638 authSession.credentials .scopes = [appConfig.oauthScopes allObjects ];
627639 [authSession.oauthCoordinator authenticateWithCredentials: authSession.credentials];
628640 }];
629641 }];
630-
642+
631643 });
632644 return self.authSessions [sceneId].isAuthenticating ;
633645}
@@ -702,6 +714,9 @@ - (void)restartAuthentication:(SFSDKAuthSession *)session {
702714 [self dismissAuthViewControllerIfPresentForScene: scene completion: ^{
703715 __strong typeof (weakSelf) strongSelf = weakSelf;
704716 strongSelf.authSessions [scene.session.persistentIdentifier].isAuthenticating = NO ;
717+ // LFA passes its hint via the request's loginAsAdminLoginHint override
718+ // (consulted in authenticateWithRequest:); other restart paths intentionally
719+ // pass nil so a hint set on a prior session does not bleed across server changes.
705720 [strongSelf authenticateWithRequest: session.oauthRequest
706721 loginHint: nil
707722 completion: session.authSuccessCallback
@@ -1032,9 +1047,14 @@ - (void)oauthCoordinatorDidCancelBrowserAuthentication:(SFOAuthCoordinator *)coo
10321047 }
10331048
10341049 // When "Login for Admin" initiated the browser auth, clear the flag and
1035- // restart the WebView login flow instead of showing the server picker.
1050+ // its My Domain / login hint overrides, then restart the WebView login
1051+ // flow against the originally configured host instead of showing the
1052+ // server picker. For Welcome Discovery, this means the user lands back
1053+ // on the discovery page and re-picks an account.
10361054 if (coordinator.authSession .oauthRequest .loginAsAdmin ) {
10371055 coordinator.authSession .oauthRequest .loginAsAdmin = NO ;
1056+ coordinator.authSession .oauthRequest .loginAsAdminMyDomain = nil ;
1057+ coordinator.authSession .oauthRequest .loginAsAdminLoginHint = nil ;
10381058 [self restartAuthentication: coordinator.authSession];
10391059 return ;
10401060 }
@@ -1125,6 +1145,26 @@ - (void)loginViewControllerDidReload:(SFLoginViewController *)loginViewControlle
11251145- (void )loginViewControllerDidSelectLoginForAdmin : (SFLoginViewController *)loginViewController {
11261146 NSString *sceneId = loginViewController.view .window .windowScene .session .persistentIdentifier ;
11271147 SFSDKAuthSession *session = self.authSessions [sceneId];
1148+ SFOAuthCoordinator *coordinator = session.oauthCoordinator ;
1149+
1150+ // Phase-1 Welcome Discovery: a discovery host is loaded but the user has not
1151+ // yet picked an account, so credentials.domain is still the discovery host
1152+ // and we have no My Domain to advance to. Switching to ASWebAuthenticationSession
1153+ // here would launch the browser against welcome.salesforce.com — wrong UX.
1154+ // No-op until phase 2 lands.
1155+ SFDomainDiscoveryCoordinator *discoveryCoordinator = [[SFDomainDiscoveryCoordinator alloc ] init ];
1156+ if ([discoveryCoordinator isDiscoveryDomain: session.oauthRequest.loginHost] && !coordinator.domainUpdated ) {
1157+ [SFSDKCoreLogger w: [self class ] format: @" %@ : Login for Admin is not available before a My Domain has been selected on the Welcome Discovery page; ignoring." , NSStringFromSelector (_cmd )];
1158+ return ;
1159+ }
1160+
1161+ // Phase-2 Welcome Discovery (or a non-discovery host): record the resolved
1162+ // My Domain and login hint as LFA-scoped overrides on the request. The
1163+ // request's loginHost is left untouched so that Reload / Clear Cache /
1164+ // post-cancel restart continue to use the originally configured host.
1165+ // These overrides are in-memory only and are cleared on LFA cancel.
1166+ session.oauthRequest .loginAsAdminMyDomain = coordinator.credentials .domain .length > 0 ? coordinator.credentials .domain : nil ;
1167+ session.oauthRequest .loginAsAdminLoginHint = coordinator.loginHint .length > 0 ? coordinator.loginHint : nil ;
11281168 session.oauthRequest .loginAsAdmin = YES ;
11291169 [self restartAuthenticationForViewController: loginViewController];
11301170}
0 commit comments