Synaps
Search…
iOS
Synaps integrates its workflow easily on iOS devices without extra packages or SDK. Thanks to ASWebAuthenticationSession component, iOS lets you access our iframe integration easily. Here is a guided tour of how integrating Synaps on native iOS.

1. Create a Synaps app

To start, you need to create an app. After logged in to your Synaps Manager interface, just click on New app. Go to integration tab and copy your Synaps API Key

2. Integrate Synaps Sessions with your Private API

As you are dealing with a mobile app, no sensitive information should appear on it. You should store no credentials, passwords, API Keys directly in your mobile codebase as it can easily be accessed by anyone.
The most common way to deal with sensitive information is to call your Private API and set a authorization mechanism using access token for instance. This mechanism will lets you call the API with a time-based token and will keep every sensitive data in your backend.
Synaps API Key is a sensitive information. This key will lets you generate new verification sessions and access sessions information.
Synaps Session ID is not a sensitive information. This Session ID has been built for front-end. It can be exposed publicly without any problem because it exposes no user information. It has been designed to only upload information.
As you are designing an iOS app and as it is considered as a front-end (publicly accessible), your goal is to call your private API that will generates a Synaps Session ID for you.

3. Integrate Synaps Flow with ASWebAuthenticationSession to your app

ASWebAuthenticationSession has been introduced by Apple to lets you open a Safari Modal easily on your app. As Safari is the most easiest way to get access to devices capabilities such as camera, Synaps integrates very well with it. It is compatible with iOS 13+.
We are going to design a simple view of an app where we will be able to open up the Synaps Flow in a SFSafariViewController modal.
    1.
    Create a Single View App using Xcode
Once your app is created, go to the Main.storyboard and add a Verify with Synaps button. We are going to trigger its action to open up our modal.
2. Integrate ASWebAuthenticationSession in your View Controller
Go to your ViewController.swift and add the following code to your controller
1
//
2
// ViewController.swift
3
// sample-demo-kyc
4
//
5
// Created by Riwan on 01/07/2020.
6
// Copyright © 2020 Synaps. All rights reserved.
7
//
8
9
import UIKit
10
import SafariServices
11
import AuthenticationServices
12
13
class ViewController: UIViewController, SFSafariViewControllerDelegate {
14
override func viewDidLoad() {
15
super.viewDidLoad()
16
}
17
18
@IBAction func openSynaps(_ sender: Any) {
19
// Allowed scheme in your info.plist that can be called by the ASWebAuthenticationSession
20
let callbackScheme = "com.synaps.verify://back"
21
22
// Encode URL to avoid conflict with Session URL
23
let callbackSchemeEncoded = callbackScheme.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
24
25
// Session Id previously initialized using your private API
26
let sessionId = "aca98307-9ace-b7b5-7afe-9e8b2f8f"
27
28
// Primary Color
29
let primaryColor = "00707F"
30
31
// Secondary Color
32
let secondaryColor = "FFFFFF"
33
34
35
// Default lang (available: en, fr)
36
let lang = "en"
37
38
// Session URL
39
guard let sessionURL = URL(string: String(format: "https://verify.synaps.io/?session_id=%[email protected]&service=individual&lang=%[email protected]&deeplink_redirection=%[email protected]&mobile=ios&primary_color=%[email protected]&secondary_color=%[email protected]", sessionId, lang, callbackScheme, primaryColor, secondaryColor)) else { return }
40
41
// Initialize the session
42
let session = ASWebAuthenticationSession(url: sessionURL, callbackURLScheme: callbackSchemeEncoded) { callbackURL, error in
43
/* Replace this alert with your business logic */
44
let alert = UIAlertController(title: "Synaps", message: "Pull data from Synaps API using your Private API", preferredStyle: UIAlertController.Style.alert)
45
alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
46
self.present(alert, animated: true, completion: nil)
47
}
48
49
session.prefersEphemeralWebBrowserSession = true
50
session.presentationContextProvider = self
51
session.start()
52
}
53
54
}
55
56
extension ViewController: ASWebAuthenticationPresentationContextProviding {
57
func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
58
return view.window!
59
}
60
}
61
62
Copied!
openSynaps - Triggers the "Verify with Synaps" button and start the ASWebAuthenticationSession session
1
@IBAction func openSynaps(_ sender: Any) {
2
// Allowed scheme in your info.plist that can be called by the ASWebAuthenticationSession
3
let callbackScheme = "com.synaps.verify://back"
4
5
// Encode URL to avoid conflict with Session URL
6
let callbackSchemeEncoded = callbackScheme.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
7
8
// Session Id previously initialized using your private API
9
let sessionId = "aca98307-9ace-b7b5-7afe-9e8b2f8f"
10
11
// Primary Color
12
let primaryColor = "00707F"
13
14
// Secondary Color
15
let secondaryColor = "FFFFFF"
16
17
// Default lang (available: en, fr)
18
let lang = "en"
19
20
// Session URL
21
guard let sessionURL = URL(string: String(format: "https://verify.synaps.io/?session_id=%[email protected]&service=individual&lang=%[email protected]&deeplink_redirection=%[email protected]&mobile=ios&primary_color=%[email protected]&secondary_color=%[email protected]", sessionId, lang, callbackScheme, primaryColor, secondaryColor)) else { return }
22
23
// Initialize the session
24
let session = ASWebAuthenticationSession(url: sessionURL, callbackURLScheme: callbackSchemeEncoded) { callbackURL, error in
25
/* Replace this alert with your business logic */
26
let alert = UIAlertController(title: "Synaps", message: "Pull data from Synaps API using your Private API", preferredStyle: UIAlertController.Style.alert)
27
alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
28
self.present(alert, animated: true, completion: nil)
29
}
30
31
session.prefersEphemeralWebBrowserSession = true
32
session.presentationContextProvider = self
33
session.start()
34
}
Copied!
Build your Synaps Session Link
You can see in the following code block that the Synaps Session Link is static. Let's see how to build it dynamically.
1
// Allowed scheme in your info.plist that can be called by the ASWebAuthenticationSession
2
let callbackScheme = "com.synaps.verify://back"
3
4
// Encode URL to avoid conflict with Session URL
5
let callbackSchemeEncoded = callbackScheme.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
6
7
// Session Id previously initialized using your private API
8
let sessionId = "aca98307-9ace-b7b5-7afe-9e8b2f8f"
9
10
// Primary Color
11
let primaryColor = "00707F"
12
13
// Secondary Color
14
let secondaryColor = "FFFFFF"
15
16
// Default lang (available: en, fr)
17
let lang = "en"
18
Copied!
callbackScheme is the scheme that you previously added in your info.plist to authorized web browser to be redirected to your app using this scheme. In other words, you authorized anyone to go to your app simply by typing in safari com.synaps.verify://back. As ASWebAuthenticationSession is an instance of Safari, it work the same way. Once the user will click "back to app", Synaps will trigger this callbackScheme and you will be able to handle the callback.
Add custom scheme to your info.plist
As said earlier, you need to add to your info.plist the custom scheme you want to let us redirect your users to your app.
    1.
    Go to info.plist
    2.
    Right Click Add row
    3.
    Add URL Types
    4.
    Click on the "+"
    5.
    Set your URL identifier
    6.
    Set your URL schemes
Handling callback
The above chunk of the code is triggered when the user come back to your app. At this moment, you have to handle your business logic. The most common way is to call your Private API to pull data from Synaps about the current authenticated user.
1
// Initialize the session
2
let session = ASWebAuthenticationSession(url: sessionURL, callbackURLScheme: callbackSchemeEncoded) { callbackURL, error in
3
/* Replace this alert with your business logic */
4
let alert = UIAlertController(title: "Synaps", message: "Pull data from Synaps API using your Private API", preferredStyle: UIAlertController.Style.alert)
5
alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
6
self.present(alert, animated: true, completion: nil)
7
}
Copied!
The Synaps Session Link will remains approximately always the same only session_id and service parameters will change for iOS integration.
1
https://verify.synaps.io/?session_id={SESSION_ID}&service={SESSION_SERVICE}&deeplink_redirection={DEEPLINK_REDIRECTION}&mobile=ios
Copied!
If you have any technical question, don't hesitate to reach [email protected]
Last modified 2mo ago