iOS – Sign in with Device
Cotter's Passwordless SDK authenticates your user using the FIDO protocol. It allows a seamless, fast, and secure way for your user to login to your iOS App. Authenticate your users in 4 simple steps:
In this guide we'll allow users to Sign In with Device using Cotter's SDK.
We use Cocoapods as our SDK host. Add
pod 'Cotter'
to your podfile then run pod install
.In your app's
AppDelegate.swift
, initialize Cotter with your API keys.import Cotter // IMPORTANT: IMPORT COTTER AS DEPENDENCY
...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Cotter.configureWithLaunchOptions(
launchOptions: launchOptions,
apiSecretKey: <your-secret-key>,
apiKeyID: <your-api-id>
)
}
To register, simply call the following function anywhere in your app. Make sure you do
import Cotter
at the start of the swift file.Passwordless.shared.register(
identifier: <user-email>
)
When a user logs in, call the following function in your view controller
Passwordless.shared.parentVC = self
Passwordless.shared.login(
identifier: <user-email>,
cb: { (token: CotterOAuthToken?, err:Error?) in
if err != nil {
// case 1: handle error as necessary
}
if token == nil {
// case 2: user is unauthorized
}
// case 3: user is authorized
})
Then you can handle 3 cases mentioned in the comments in any way you like.
That's it! You have successfully build a seamless, fast, and secure login mechanism with Cotter.