Skip to main content


         This documentation site is for previous versions. Visit our new documentation site for current releases.      
 

This content has been archived and is no longer being updated.

Links may not function; however, this content may be relevant to outdated versions of the product.

Authenticating with the Mashup SDK on iOS in Pega 7.2.1

Updated on July 19, 2016

The Pega Mashup SDK includes an Objective-C API Authentication module that allows a user to set the Pega 7 Platform instance URL, log in and log out from this Pega 7 Platform instance, and also check whether the user is currently logged in, all from a native iOS app. This article describes the API.

Obtaining the authentication object

To instantiate the authentication object, you must first create NSURLSessionConfiguration (session configuration object) to specify the timeout interval for logging in and whether to store credentials. You can set additional properties in the session configuration object. Next, you must call the initWithURL() method, passing it the session configuration object as the parameter.

The following example shows the Objective-C code.

NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
config.timeoutIntervalForRequest = 30.0;
config.URLCredentialStorage = nil;
NSURL *URL = [NSURL URLWithString:@"http://test.server.com:8243/prweb"];
NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
AHCPRPCAuthentication *authenticationService = [[AHCPRPCAuthentication alloc] initWithURL:URL session:session];”

After you create an instance of the authentication object and configure it, you can use it to log in, log out, or check its current login status.

Logging in

To log in to the Pega 7 Platform instance, you must call the loginWithCredential() method on the instance of the authentication object, passing it the user name and password credentials as the first parameter and the completion handler as the second parameter. The completionHandler()returns the URL of the Pega 7 Platform instance if you were successful logging in or an error code if you were unsuccessful.

The following Objective-C code demonstrates how to do this.

NSURLCredential *credential = [NSURLCredential credentialWithUser:@"jsmith" password:@"mypassword" persistence:NSURLCredentialPersistenceNone];
[authenticationService loginWithCredential:credential completionHandler:^(NSURL *portalURL, NSError *error){
  // add your code depending if were successful logging in or not
}

After you log in, to be able to log in to the Pega 7 Platform instance as another user, you must log out before calling the loginWithCredential() method again.

The error codes for the Authentication module on iOS are defined as follows:

CF_EXPORT NSString *const AHCPRPCAuthenticationErrorDomain;
typedef NS_ENUM(NSInteger, AHCPRPCAuthenticationError) {
  AHCPRPCAuthenticationErrorInternal = 1,
  AHCPRPCAuthenticationErrorIllegalArgument = 2,
  AHCPRPCAuthenticationErrorFailed = 3,
  AHCPRPCAuthenticationErrorServer = 4,
  AHCPRPCAuthenticationErrorNetwork = 5,
  AHCPRPCAuthenticationErrorClientVersionMismatch = 6
};

Logging out

To log out from the Pega 7 Platform instance from your iOS app, you must call the logout() method on the authentication object instance. This action also clears cookies for the current or previous Pega 7 Platform session.

[self.authenticationService logout];

Checking login status

To find out whether your iOS app is currently logged in to the Pega 7 Platform instance, you must call the isLoggedInWithCompletionHandler() method on the instance of the authentication object. It returns a Boolean value that indicates whether the app is currently logged in and also an error code if the login status checking was unsuccessful.

[self.authenticationService isLoggedInWithCompletionHandler:^(BOOL isLoggedIn, NSError *error){
  // add your code here
}];

Related articles

Pega Mobile SDKMashup SDKSetting up the Mashup SDK for iOS app development in Pega 7.2.1Using the SnapStart module with the Mashup SDK on iOS in Pega 7.2.1

Tags

Pega Platform 7.2.1 Pega Mobile Mashup Mobile Pega Express Consumer Services Consumer Services Manufacturing Financial Services Consumer Services Communications and Media Government Healthcare and Life Sciences Healthcare and Life Sciences Insurance

Have a question? Get answers now.

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

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega.com is not optimized for Internet Explorer. For the optimal experience, please use:

Close Deprecation Notice
Contact us