Configuring an iOS App as an Identity Provider Client
- In the init() method of your AppDelegate class, specify the URI scheme for the identity
provider you’re using:
- Swift
-
1SalesforceManager.shared.identityProviderURLScheme = "sampleidpapp" - Objective-C
-
1[SalesforceSDKManager sharedManager].idpAppURIScheme = @"sampleidpapp";
- In your app's info.plist file, add the URI scheme defined in your
identity provider clients’ connected
app:
1<key>CFBundleURLTypes</key> 2<array> 3 <dict> 4 <key>CFBundleURLSchemes</key> 5 <array> 6 <string>sampleidpclientapp</string> 7 </array> 8 </dict> 9</array> - In your AppDelegate class implementation, find the
following method and reinstate the commented code as follows:
- Swift
-
1func application(_ app: UIApplication, 2 open url: URL, 3 options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { 4 return UserAccountManager.shared.handleIdentityProviderCommand( 5 from: url, with: options) 6} - Objective-C
-
1- (BOOL)application:(UIApplication *)app 2 openURL:(NSURL *)url 3 options:(NSDictionary<UIApplicationOpenURLOptionsKey,id>*)options { 4 5 return [[SFUserAccountManager sharedInstance] 6 handleIDPAuthenticationResponse:url options:options]; 7}
Your app is now ready for use as an identity provider client.
(Optional) Configure Your IDP Client App to Use Keychain
After you set up your IDP app to initiate authentication, update the client to complete the flow. You can use these methods to handle the incoming IDP URL.
- Swift
-
1public func handleIdentityProviderCommand(from url: URL, 2with options: [AnyHashable: Any], 3completion: @escaping (Result<(UserAccount, AuthInfo), 4UserAccountManagerError>) -> Void) -> Bool { 5 return __handleIDPAuthenticationCommand(url, options: options, completion: { (authInfo, userAccount) in 6 completion(Result.success((userAccount, authInfo))) 7 }) { (authInfo, error) in 8 completion(Result.failure(.loginFailed(underlyingError: error, authInfo: authInfo))) 9 } 10} - Objective-C
-
1- (BOOL)handleIDPAuthenticationCommand:(NSURL *)url 2options:(nonnull NSDictionary *)options 3completion:(nullable SFUserAccountManagerSuccessCallbackBlock)completionBlock 4failure:(nullable SFUserAccountManagerFailureCallbackBlock)failureBlock NS_REFINED_FOR_SWIFT;
(Optional) Customizing the Login Flow Selection View in the Client App
Mobile SDK provides template apps for both identity providers and their client apps. The client template defines a view that lets the user choose to log in through an identity provider or the Salesforce login screen. When a user opens an app built from the client template, the app presents this view if
- the user hasn’t yet logged in, or
- the current user hasn't been set.
To customize the login style selection view, a client app extends the UIViewController class and also must implement the SFSDKLoginFlowSelectionView protocol.
1@protocol SFSDKLoginFlowSelectionViewDelegate<NSObject>
2/**
3 * Used to notify the SDK of user selection on the login flow selection view
4 * @param controller instance invoking this delegate
5 * @param appOptions addl. name value pairs sent from the sdk for
6 * the SFSDKLoginFlowSelectionView
7 */
8-(void)loginFlowSelectionIDPSelected:(UIViewController *)controller
9 options:(NSDictionary *)appOptions;
10
11/**
12 * Used to notify the SDK of user selection on the login flow selection view
13 * @param controller instance invoking this delegate
14 * @param appOptions addl. name value pairs sent from the sdk for
15 * the SFSDKLoginFlowSelectionView
16 */
17-(void)loginFlowSelectionLocalLoginSelected:(UIViewController *)controller
18 options:(NSDictionary *)appOptions;
19
20@end1@protocol SFSDKLoginFlowSelectionView<NSObject>
2 @property (weak,nonatomic) id <SFSDKLoginFlowSelectionViewDelegate>selectionFlowDelegate;
3 @property (nonatomic,strong) NSDictionary *appOptions;
4@endDuring the client app’s identity provider flow, Mobile SDK sets up an instance of the selectionFlowDelegate and appOptions properties defined in this protocol. You use these artifacts in your view controller to notify Mobile SDK of the user's login method selection. For example, assume that you’ve implemented the SFSDKUserSelectionView protocol in a UIViewController class named IDPLoginNavViewController. You then can use that view controller as the user selection dialog box by setting the idpLoginFlowSelectionAction on the SalesforceSDKManager shared instance, as follows:
1//optional : Customize the Login Flow Selection screen
2[SalesforceSDKManager sharedManager].idpLoginFlowSelectionAction = ^UIViewController<SFSDKLoginFlowSelectionView> *{
3 IDPLoginNavViewController *controller =[[IDPLoginNavViewController alloc] init];
4 return controller;
5}