Add a New Trusted Device

Steps

There are 2 steps that's needed to add a new Trusted Device:
  1. 1.
    ​Show the QR Code of the New Device
  2. 2.
    ​Scan the New Device's QR Code using the Trusted Device
Scan the New Device's QR Code using the Trusted Device

Step 1: Show the QR Code of the New Device

To show the QR Code of the new device:
Example:
1
class SomeUIVC: UIViewController {
2
var cotter: Cotter?
3
​
4
override func viewDidLoad() {
5
super.viewDidLoad()
6
​
7
self.cotter = Cotter(
8
apiSecretKey: "588d6f67-0981-4718-899b-bcd512de1aca",
9
apiKeyID: "w4FK6Zz0XIhtGY3o5biI",
10
cotterURL: "https://www.cotter.app/api/v0",
11
userID: "[email protected]",
12
configuration: [:]
13
)
14
}
15
​
16
// On Button Click
17
@IBAction func registerThisDeviceAsTrusted(_ sender: UIButton) {
18
func callback(token:String, err: Error?) {
19
if err != nil {
20
print(err?.localizedDescription)
21
self.textLabel.text = "Failed to register new device!"
22
return
23
}
24
self.textLabel.text = "Successfully registered new device!"
25
}
26
​
27
/* Open QR Code that can be scanned from the Trusted Device. */
28
self.cotter?.registerNewDevice(vc: self, cb: callback)
29
}
30
}
Copied!
This will open a View Controller with a QR Code that can be scanned from the Trusted Device. After registration is done, the above-defined callback function would be called.
For the above callback, a text label in the SomeUIVC view controller will be populated to let the user know whether registration succeeded or failed. Otherwise, if desired, the user can also perform a segue to another view controller (on success or failure) in the callback function as well.
Different Cases of Registering a New Device as a Trusted Device

Case 1: Successfully registered as a Trusted Device

Once it's scanned and registered successfully as, the View Controller will show a success image, and close after 3 seconds.

Case 2: The new device is still not registered as a Trusted Device after 3 minutes

If after 3 minutes, the new device is still not registered as a Trusted Device, it will show an error message.

Step 2: Scanning the QR Code from a Trusted Device

To scan the QR Code from a Trusted Device, call the function:
1
class SomeUIVC: UIViewController {
2
var cotter: Cotter?
3
​
4
override func viewDidLoad() {
5
super.viewDidLoad()
6
​
7
self.cotter = Cotter(
8
apiSecretKey: "588d6f67-0981-4718-899b-bcd512de1aca",
9
apiKeyID: "w4FK6Zz0XIhtGY3o5biI",
10
cotterURL: "https://www.cotter.app/api/v0",
11
userID: "[email protected]",
12
configuration: [:]
13
)
14
}
15
​
16
// On Button Click
17
@IBAction func executeScanOfOtherDevice(_ sender: UIButton) {
18
/* Open a View Controller that opens the Camera to scan the
19
QR Code on the other non-trusted device. We do not need
20
to pass in a callback, as the user will be redirected
21
back to this view controller. */
22
self.cotter?.scanNewDevice(vc: self, cb: nil)
23
}
24
}
Copied!
This will open a View Controller that opens the Camera. It will ask for permission to access the camera. When the QR Code is detected and scanned, it will automatically attempt to register the new device. After scanning is done, the user will be redirected back to the above SomeUIVC view controller.
Scanning the New Device's QR Code from the Trusted Device
When the QR Code is detected and registered, the SDK will automatically show whether it was successful or if there's an error.

πŸŽ‰ You're done!

Now you can authenticate from the new device without requiring approval.
Last modified 1yr ago