Device features
You can use the device related features of Amazon Cognito User Pools by enabling the Devices features. Navigate to the Cognito User Pools console, click on Devices in Left Navigation Menu and chose one of User Opt In or Always.
If you chose Always every device used by your application users is remembered.
You can read more about the device features in the following blog.
Terminology
- Tracked
When devices are tracked, a set of device credentials consisting of a key and secret key pair is assigned to every device. You can view all tracked devices for a specific user from the Amazon Cognito console device browser, which you can view by choosing a user from the Users panel. In addition, you can see some metadata (whether it is remembered, time it began being tracked, last authenticated time, etc.) associated with the device and its usage.
- Remembered
Remembered devices are also tracked. During user authentication, the key and secret pair assigned to a remembered device is used to authenticate the device to verify that it is the same device that the user previously used to sign in to the application. You can also see remembered devices from the Amazon Cognito console.
- Not Remembered
A not-remembered device is the flipside of being remembered, though the device is still tracked. The device is treated as if it was never used during the user authentication flow. This means that the device credentials are not used to authenticate the device. The new APIs in the AWS Mobile SDK do not expose these devices, but you can see them in the Amazon Cognito console.
Remember Device
This option will mark the tracked device as remembered
AWSMobileClient.default().deviceOperations.updateStatus(remembered: true) { (result, error) in // ...}
Update Device
This option will mark the tracked device as not remembered
.
AWSMobileClient.default().deviceOperations.updateStatus(remembered: false) { (result, error) in // ...}
Forget Device
This option will stop tracking the device altogether.
AWSMobileClient.default().deviceOperations.forget({ (error) in // ...})
Note: Once you call
forget
, you can update the status of the device in the same auth session. The end user will have to sign in again to remember the device.
Get Device Details
AWSMobileClient.default().deviceOperations.get { (device, error) in guard error == nil else { print(error!.localizedDescription) return } print(device!.createDate!) print(device!.deviceKey!) }
List Devices
AWSMobileClient.default().deviceOperations.list(limit: 60) { (result, error) in guard error == nil else { print(error!.localizedDescription) return } // Number of devices that are remembered print(result!.devices!.count) }