This content has been archived.

Table of Contents

Authenticating with the Mashup SDK on iOS

With the Pega® Mashup SDK, you can authenticate with a Pega Platform instance in a native iOS mobile app in several ways. When you obtain an authenticated request, you can access an embedded Pega Platform application in a hybrid web view. For example, you can use the Mashup SDK to create or open a case, open a harness, or run an activity.


Before you continue, make sure that you have read the following information:

Make sure that you also have access to the Mashup SDK API documentation that is included with the Pega Mashup SDK distribution package.

If you plan to use classes that come from the Mashup SDK framework in your source file, make sure that you define PegaMashupSDK imports.

If you plan to use methods that rely on the CustomAuthenticator, create the required classes that authenticate the user based on your selected authentication method.

Configure user authentication in the Interface Builder

To configure user authentication with a custom authenticator, you can modify an existing storyboard in an iOS app that you created when following the instructions provided in Creating a case in mobile apps using the Mashup SDK for iOS.

  1. In the Outline view of the Interface Builder, delete the authentication scene (PMSnapStartLoginController).
  2. In the Project navigator pane, create a class that adopts the PMSnapStartAuthenticationDelegate protocol.
    import PegaMashupSDK  
    class CustomAuthenticator: NSObject, PMSnapStartAuthenticationDelegate {  
      func authenticatedRequest(completionHandler: @escaping (URLRequest?, Error?) -  
      > Void) {   
        // call the completionHandler with an authenticated request or pass an error 
        // for example, use OAuth2 authentication and set the OAuth2 access token in
        // the authorization header of the authenticated request  
    The authenticationRequest method must pass the authenticated request as the first argument of the completionHandler handler.
  3. From the Object Library, drag a generic object to the create case scene (SnapStartCreateController), and in the Identity inspector, set the custom class of the object to CustomAuthenticator.
  4. In the Outline view of the Interface Builder, right-click the Snapstart Create Case Controller icon to display the list of available outlets, and connect the authenticationDelegate outlet with the Custom Authenticator object.
  5. Connect the More info button to the create case scene, and select Show from the Action Segue menu.

Configure user authentication using code

For smoother operation and instant transition to the web view controller on login, you can use code to authenticate the user.

You can authenticate the user with basic authentication.

  1. In the Outline view of the Interface Builder, delete the create case scene (SnapStartCreateController).
  2. In the initial scene, display the Assistant editor and control-drag from the button to the view controller code to create an action for the button.
  3. In the function that is the action for the button, paste the following code that executes basic authentication:
let serverURL = URL(string: "http://<SERVER_NAME>:<PORT>/prweb/")!  
let user = "username";  
let password = "password";  
let caseClass = "Wb-MachineryIssue-Case"  
  // Create a basic authenticator with credentials
let authenticator = PMSnapStartBasicAuthenticator(serverURL: serverURL, user: user, password: password)  
  // Use the authenticator to create a case  
let snapStart = PMSnapStart(authenticationDelegate: authenticator)  
let snapStartVC = snapStart.createCaseController(className: caseClass, delegate: nil)  
navigationController?.pushViewController(snapStartVC, animated: true)  

You can also use code to authenticate the user with custom authentication, using your selected authentication method. To do this, replace the code for the button action with the following code that executes custom authentication:

let caseClass = "Wb-MachineryIssue-Case"  
  // Create a custom authenticator  
let authenticator = CustomAuthenticator()  
  // Use the authenticator to create a case  
let snapStart = PMSnapStart(authenticationDelegate: authenticator)  
let snapStartVC = snapStart.createCaseController(className: caseClass, delegate: nil)  
navigationController?.pushViewController(snapStartVC, animated: true)  

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.