Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.
Gen1 DocsLegacy

Page updated Aug 21, 2024

デバイスの管理

Amplify Authを使用すると、監査、MFAなど、ユーザーが使用するデバイスを追跡できます。開始する前に、デバイスステータスの用語を理解することが重要です:

  • 追跡中: ユーザーが新しいデバイスでサインインするたびに、クライアントは成功した認証イベントの終了時にデバイスキーを与えられます。このデバイスキーを使用して、ConfirmDevice APIを呼び出すために使用されるソルトとパスワード検証器を生成します。この時点で、デバイスは 追跡中 と見なされます。デバイスが追跡中の状態になると、Amazon Cognito コンソールを使用して、追跡を開始した時刻、最後の認証時刻、およびそのデバイスに関する他の情報を確認できます。
  • 記憶: 記憶されたデバイスも追跡されます。ユーザー認証時に、記憶されたデバイスに割り当てられたデバイスキーとシークレットペアを使用してデバイスを認証し、ユーザーが以前にサインインするために使用した同じデバイスであることを確認します。
  • 記憶されていない: 記憶されていないデバイスは、追跡されたデバイスであり、Cognitoはユーザーにデバイスを記憶することを「オプトイン」することを要求するように設定されていますが、ユーザーはデバイスを記憶することにオプトインしていません。このユースケースは、ユーザーが自分が所有していないデバイスからアプリケーションにサインインする場合に使用されます。
  • 忘れられた: 忘れられたデバイスは、記憶されることから削除されたデバイスです。

注: デバイス追跡と記憶機能は、外部プロバイダーとの連携サインインを使用する場合、デバイスがアップストリームアイデンティティプロバイダーで追跡されるため、利用できません。これらの機能は、CognitoのホストされたUIを使用する場合にも利用できません。

デバイスを記憶

以下を使用してデバイスを記憶できます:

func rememberDevice() async {
do {
try await Amplify.Auth.rememberDevice()
print("Remember device succeeded")
} catch let error as AuthError {
print("Remember device failed with error \(error)")
} catch {
print("Unexpected error: \(error)")
}
}
func rememberDevice() -> AnyCancellable {
Amplify.Publisher.create {
try await Amplify.Auth.rememberDevice()
}.sink {
if case let .failure(authError) = $0 {
print("Remember device failed with error \(authError)")
}
}
receiveValue: {
print("Remember device succeeded")
}
}

デバイスを忘れる

デバイスを忘れることもできますが、忘れられたデバイスは記憶されたり追跡されたりしないことに注意してください。

func forgetDevice() async {
do {
try await Amplify.Auth.forgetDevice()
print("Forget device succeeded")
} catch let error as AuthError {
print("Forget device failed with error \(error)")
} catch {
print("Unexpected error: \(error)")
}
}
func forgetDevice() -> AnyCancellable {
Amplify.Publisher.create {
try await Amplify.Auth.forgetDevice()
}.sink {
if case let .failure(authError) = $0 {
print("Forget device failed with error \(authError)")
}
}
receiveValue: {
print("Forget device succeeded")
}
}

デバイスを取得

以下を使用してデバイスのリストを取得できます:

func fetchDevices() async {
do {
let fetchDeviceResult = try await Amplify.Auth.fetchDevices()
for device in fetchDeviceResult {
print(device.id)
}
} catch let error as AuthError {
print("Fetch devices failed with error \(error)")
} catch {
print("Unexpected error: \(error)")
}
}
func fetchDevices() -> AnyCancellable {
Amplify.Publisher.create {
try await Amplify.Auth.fetchDevices()
}.sink {
if case let .failure(authError) = $0 {
print("Fetch devices failed with error \(authError)")
}
}
receiveValue: { fetchDeviceResult in
for device in fetchDeviceResult {
print(device.id)
}
}
}

これで、デバイスを記憶、忘れる、および取得するように設定できました。