Layer7 API Management

 View Only

CA MAS Proximity Login using QRCode + iOS (Swift 3.0) sample 

Feb 13, 2017 10:59 AM

Hello everybody!

 

I wrote an iOS app to demonstrate how to use the CA MAS Proximity Login feature to transfer the current session to a different device, using the same app. The use case behind it is very simple and the following diagram will give you an idea of what's happening behind the scenes:

 

 

 

What are you going to need to do this demo?

 

 

The second device can be either a real one or the iOS simulator, available within the Xcode. I'm using CocoaPods to add some frameworks to my project, so you MUST use the QRCode.xcworkspace when opening the downloaded project, otherwise it WILL NOT work.

 

Once you open the project you have to add YOUR OWN msso_config.json, pointing your project to your own CA API Gateway and also add your code signing information, under the project's general:

 

You can change the bundle identifier if you want, just keep in mind you will have to change the Keychain entitlements to match whatever you have used.

Once you have configured the project to match your environment, you're good to give it a go. Just clean up and run the project into your real iOS device. The app itself is very simple and the following image will give you detailed information about the 4 buttons:

 

 

  1. This is the main button of the app. It will use the device's camera to read the QRCode when opening the app using the second device
  2. This is will show you whether the user is authenticated or not. If the user IS authenticated, then this will be filled up.
  3. This is the login button. Tap it to trigger the MAG default user authentication screen
  4. Logout button, to refresh your demo

 

The following video will show you how to do the first login:

 

 

Now that you have the app running into your real device, it's time to run it into your second device or the iOS simulator. I'm going to use my iPad for that. Once the app opens into your second device, tap the login button to triggers the default login screen. At this time, you will not enter the authentication though. Grab your first device and tap the button 1 to scan the QRCode presented at the login screen and then transfer the session from the first into the second device:

 

 

When comes to the code, this is what I'm doing once a QR Code is detected:

 

Code snippet

//Sharing the session using the MAS SDK
MASProximityLoginQRCode.authorizeAuthenticateUrl(metadataObj.stringValue) { (completed: Bool, error: Error?) in


if (error != nil) {

print("Error sharing the session")
//Present an Alert showing the results
let alertController = UIAlertController(title: "Error", message: "The session could not be shared!", preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alertController.addAction(defaultAction)
self.present(alertController, animated: true, completion: nil)


}

print("The session has been shared!")

//Present an Alert showing the results
let alertController = UIAlertController(title: "MAS Proximity Login", message: "The session has been successfully shared!", preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alertController.addAction(defaultAction)
self.present(alertController, animated: true, completion: nil)

return

}

 

I'm also listening to notifications by clicking here

 

I hope this can help you. See you next time.

Statistics
0 Favorited
2 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Related Entries and Links

No Related Resource entered.