Mobile App Services Foundation for Mobile App Development

Sangharsh Aglave, Software Engineer

Welcome to CA Mobile App Services (MAS) blogs. MAS aims at saving your development time by providing complex mobile features wrapped in simple to use methods. Sounds interesting! So, stay with us for the exciting journey of using our MAS services for your Cordova-based apps. This blog post will walk you through the cool features of MAS, and will guide you to create a basic beginner app.

Let’s consider a coffee house as analogy to explain MAS. To enter the coffee house, you need proper credentials to get in and access the services. Once you are in the coffee house, you see a bustling place with people occupying tables. Consider the tables as groups and the people as the users.

The group administrator directs you to a table. You can create your own groups (if you’re that lonely). The server can let you access or deny access to certain services depending on your credentials. You can send messages to individuals or groups. You can also store your coffee, and retrieve it later. In the context of MAS, this situation represents the following four major components of MAS:

MAS Foundation

Authenticates users, manages users, apps, and device registration. Sounds difficult? Trust us, it is quite simple with our MAS Foundation module.

Identity Management

Manages identity of the users, creates and manages ad-hoc groups. Implements SCIM 2.0 standards to simplify user management.

Messaging

Secures communication among groups is achieved by our robust MAS Connecta APIs.

Storage

Provides local and cloud storage facility with enterprise-grade encryption.

Now that you know the benefits of our wares, let us start building a basic Cordova app using the MAS Foundation to login and access a protected API.

What do you need to start?

• A PC or MAC
• Mobile device or a simulator
• Xcode or Android Studio or a terminal
• Mobile API Gateway (MAG)
   MAG shares the msso_config.json file that provides the address of the MAG server to the Cordova app.
• Ionic

Follow the instructions to create a basic Cordova app to start a project:

1.       Run the following command in the terminal:

ionic start masFoundation

You just created a folder named masFoundation, where you have an app with a default template ready for you.

2.       Add iOS or Android mobile platform as follows:

Ensure that you have the Android Studio or an iOS xcodeproj ready in the platform folder.

ionic platform add ios

OR

ionic platform add android

3.       Now, add our esteemed plugin to the mix. Download or clone the MAS Foundation from GitHub repository.

4.       To add the plugin to your cordova project, run the following command:

ionic plugin add PATH_TO_PLUGIN

where "PATH_TO_PLUGIN" is the location of the plugin on your machine.

Now let us dive down to the platform specific setup.  Let us view the iOS setup first. The Android setup section will be below.

iOS

1.     Download the SDK libraries from the CAAPIM Releases repository.
2.     Navigate to the “MAS-*latestVersion*-CR1/iOS” folder, and download the iOS-MobileSDK-<version>.zip file.
3.     Open the Cordova iOS project in Xcode, and add the MASFoundation.framework, MASUI.framework, and MASUIResources.bundle files.
4.     Configure the following property in the “.plist” file located in the Resources folder of the project:   

<key>NSLocationWhenInUseUsageDescription</key> <string>The application needs a location to use the MAS backend services</string>

A screenshot for your reference:

5.       In the capabilities section of the Target, enable the keychain sharing and add a singleSignOn keychain group options.

6.       Now, add the msso_config.json file to your project. Place this file anywhere inside the Xcodeproject, preferably in the Resources folder. 

Android

1.     Download the SDK libraries from the CAAPIM Releases repository.
2.     Navigate to the “MAS-*latestVersion*-CR1/Android” folder, and download the Android-MobileSDK-<version>.zip file.
3.     Open the ionic Android project in Android Studio and add the libraries to the libs directory of your project.

4.    Open the Cordova project in Android Studio, and add the MAS, Bouncycastle, and QRCode authentication dependencies in the build.gradle file.

dependencies
{
// MAS Integration begin
compile `com.ca.mas.core:mobile-api-gateway-sdk-<build-version>@aar`
compile `com.ca.mas:mobile-app-service-sdk-<build-version>@aar`
compile `com.ca.mas.ui:mobile-app-service-sdk-ui-<build-version>@aar`
compile `com.madgag:scprov-jdk15on:1.47.0.3`
compile `com.madgag:sc-light-jdk15on:1.47.0.3`
// MAS Integration end
//Third party library for QRCode authentication
compile `com.google.zxing:core:3.2.0`
}
 

5. Navigate to the module that contains the MAS integration in the build.gradle file, add the repository section that contains the libs path:

// MAS Integration begin
repositories {

mavenCentral()
flatDir {
dirs 'libs'
}
}
// MAS Integration end

6.     Add a valid “msso_config.json” of your gateway into the assets folder of your project.

7. Update the minSdkVersion in AndroidManifest.xml file to 19 or more if the Android Studio recommends the current version of the Android SDK.

8. Update the target to android-23 or latest as required.

Congratulations!! You created your app. Now, the coding starts. Wait.. we have a sample app ready for you. Download the sample app and follow the instructions:

1.     Copy the www folder from the project to your www folder.
The SDK needs to set login and OTP authentication callbacks before an API request. The callbacks are invoked if the requested API requires user login, or the API is OTP protected. The initialization does this job.

The initialization method is as follows:

var mas = new MASPlugin.MAS();
mas.init(successHandler, errorHandler);

2.     Set the grant flow to password.

mas.grantFlow(successHandler,errorHandler, MAS.MASPlugin.MASGrantFlow.MASGrantFlowPassword);

3.     Lastly, call the start method as follows:

mas.start(successHandler, errorHandler);

We have successfully started the SDK now. Woohoo!!! Everything else from now on is just a method call away.

4.     Do you want to login? Call the following method:

var MASUser = new MASPlugin.MASUser();
MASUser.loginWithUsernameAndPassword(successHandler, errorHandler, username, password);

Alternatively, you can summon our inbuilt login screen by calling any API. The API requires a user to log in. In our sample app, we handle the login internally, so you don’t have to do anything.


A lot of other features that MAS Foundation provides are documented at our MAS Official Documentation.
 

Sangharsh Aglave, Software Engineer, CA Technologies

Sangharsh Aglave is a Software Engineer at CA Technologies. He works in the API Management Business Unit where he works on mobile technologies on the Mobile App Services product.

Sangharsh graduated from the Computer Science Department at Indian Institute of Technology, Kanpur in 2015. He worked as a summer intern at CA and consequently joined CA as a college recruit after graduation. He has a keen interest in mobile technologies and has worked on both iOS and Android platforms. He also likes to explore emerging fields in Computer Science like machine learning and artificial intelligence.

Chat
What would you like to chat about?
Support
Contact
Call us at1-800-225-5224
Call us at1-800-225-5224
Contact Us