Sign In with Device
Cotter's iOS SDK offers the easiest way to integrate "Sign in with device" to your ios app. You can simply call a function and it does most of the heavy lifting and authentication for you.
Last updated
Cotter's iOS SDK offers the easiest way to integrate "Sign in with device" to your ios app. You can simply call a function and it does most of the heavy lifting and authentication for you.
Last updated
Concepts: Learn about how Sign in with Device works.
There are major updates planned for this feature. Contact us in Slack so we can help you prepare for it.
Authenticating users using Trusted Devices with Cotter's iOS SDK consists of the following steps:
Import and Initialize Cotter
Calling functions to register devices a Trusted Device
Calling functions to authenticate from Trusted and Non-Trusted Device
Set Allowed Methods in the Dashboard to allow Trusted Devices
Create a User: Create a user in Cotter by specifying your user ID.
We use Cocoapods as our SDK host. If you're using Cocoapods, add this to your Podfile
Then simply run pod install
You need to set allowed methods for authenticating your users. To allow TRUSTED DEVICES, go to https://dev.cotter.app/rules
Remember to select the correct project in the dropdown list.
Check out Create a User API Reference for a full description
You can now use the SDK to enroll and verify Trusted Devices for the user you just created.
In your main view controller, initialize Cotter with API keys, Cotter's URL to use (prod/test), and your User ID.
Production Endpoint: https://www.cotter.app/api/v0
Example:
Right after your user finished their registration to your app, you should automatically register the device as a Trusted Device (or prompt your user if they want to make this device as a Trusted Device).
To enroll the current device as a TrustedDevice, call the CotterAPIService.shared.enrollTrustedDevice
function, which takes in a userID
as String
and a Callback function as parameters.
Example:
JSON Result:
This method is only for the first Trusted Device. You will get an error if you attempt to enroll another Trusted Device using enrollDevice when there's already a Trusted Device for the account. To enroll other devices, see Add a new Trusted Device.
To authenticate a device, call the cotter?.loginWithTrustedDevice
function, which takes in the current view controller and a Callback function as parameters. This will automatically detect whether the current device is a Trusted Device or not.
Example:
JSON Result:
An Event
is an Authentication Event, where your app requests Cotter's SDK to authenticate the user. EVENT_NAME
refers to what type of authentication event was requested. Example: LOGIN
event, TRANSACTION
event, UPDATE_PROFILE
event, etc.
When an Authentication Event is requested using method TRUSTED_DEVICE
, there are 2 possible cases:
If the current device is a Trusted Device, it should automatically be approved, and you will receive a JSON result containing the requested Event
and whether or not it's approved. The approval is based on whether or not the signature included in the request from the SDK is valid.
You should see a result that the event is not new, and that it's approved. This is because the signature from the Trusted Device is sufficient to prove that the device is authorized.
The callback that you provided to the cotter?.loginWithTrustedDevice
function will be called on login success or failure. For instance, as seen in the above example, if the login is approved, the callback function will be called with no error, and you can redirect the user to the Dashboard View Controller. However, if the login is not approved, then an error will exist and you can redirect the user to the Error Page View Controller.
When passing this Event Response to your backend, you need to check if this JSON is valid and if it comes from Cotter's server.
Checkout how to verify the OAuth Tokens from Cotter here:
We'll cover this in the next guide: