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を使用する場合にも利用できません。

デバイスを記憶

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

Amplify.Auth.rememberDevice(
() -> Log.i("AuthQuickStart", "Remember device succeeded"),
error -> Log.e("AuthQuickStart", "Remember device failed with error " + error.toString())
);
Amplify.Auth.rememberDevice(
{ Log.i("AuthQuickStart", "Remember device succeeded") },
{ Log.e("AuthQuickStart", "Remember device failed with error", it) }
)
try {
Amplify.Auth.rememberDevice()
Log.i("AuthQuickStart", "Remember device succeeded")
} catch (error: AuthException) {
Log.e("AuthQuickStart", "Remember device failed with error", error)
}
RxAmplify.Auth.rememberDevice()
.subscribe(
() -> Log.i("AuthQuickStart", "Remember device succeeded"),
error -> Log.e("AuthQuickStart", "Remember device failed with error " + error.toString())
);

デバイスを忘れる

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

Amplify.Auth.forgetDevice(
() -> Log.i("AuthQuickStart", "Forget device succeeded"),
error -> Log.e("AuthQuickStart", "Forget device failed with error " + error.toString())
);
Amplify.Auth.forgetDevice(
{ Log.i("AuthQuickStart", "Forget device succeeded") },
{ Log.e("AuthQuickStart", "Forget device failed with error", it) }
)
try {
Amplify.Auth.forgetDevice()
Log.i("AuthQuickStart", "Forget device succeeded")
} catch (error: AuthException) {
Log.e("AuthQuickStart", "Forget device failed with error", error)
}
RxAmplify.Auth.forgetDevice()
.subscribe(
() -> Log.i("AuthQuickStart", "Forget device succeeded"),
error -> Log.e("AuthQuickStart", "Forget device failed with error " + error.toString())
);

デバイスを取得

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

Amplify.Auth.fetchDevices(
devices -> {
for (AuthDevice device : devices) {
Log.i("AuthQuickStart", "Device: " + device);
}
},
error -> Log.e("AuthQuickStart", "Fetch devices failed with error: " + error.toString()));
Amplify.Auth.fetchDevices(
{ devices ->
devices.forEach { Log.i("AuthQuickStart", "Device: " + it) }
},
{ Log.e("AuthQuickStart", "Fetch devices failed with error", it) }
)
try {
Amplify.Auth.fetchDevices().forEach { device ->
Log.i("AuthQuickStart", "Device: $device")
}
} catch (error: AuthException) {
Log.e("AuthQuickStart", "Fetch devices failed with error", error)
}
RxAmplify.Auth.fetchDevices()
.subscribe(
device -> Log.i("AuthQuickStart", "Device: " + device);
error -> Log.e("AuthQuickStart", "Fetch devices failed with error: " + error.toString())
);

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