この文章は Salesforce 機械翻訳システムを使用して翻訳されました。詳細はこちらをご参照ください。
英語に切り替える

Apex を使用した 2 要素認証の実装

2 要素認証プロセスを実装するには、System.UserManagement クラスで Apex メソッドを使用します。このメソッドでは、メール、電話 (SMS)、Salesforce Authenticator の検証方法をペアにして、一方で検証サービスを開始し、もう一方で検証サービスを完了します。パスワードまたは時間ベースのワンタイムパスワード (TOTP) による検証方法の場合は、2 つ目の方法のみで検証サービスを完了できます。
使用可能なインターフェース: Salesforce Classic (使用できない組織もあります) および Lightning Experience の両方
使用可能なエディション: Essentials Edition、Group Edition、Professional Edition、Enterprise Edition、Performance Edition、Unlimited Edition、Developer Edition、および Contact Manager Edition

使用する Apex 設定は、検証方法によって異なります。
  • メール、SMS、Salesforce Authenticator の検証方法を使用する 2 要素認証サービスを実装する場合は、initVerificationMethodverifyVerificationMethod を使用します。
  • パスワードまたは TOTP 検証方法を使用する 2 要素認証サービスを実装する場合は、verifyVerificationMethod を使用します。

2 要素認証の Apex メソッド

メールを使用した 2 要素認証の Apex コードの例を以下に示します。

1public void initVerification() {
2// user will receive code on their registered verified email 
3 identifier = UserManagement.initVerificationMethod(Auth.VerificationMethod.EMAIL);
4}
5
6public Auth.VerificationResult verifyVerification() {
7// requiring identifier from the initVerification
8// the code will need to be entered in this method
9return UserManagement.verifyVerificationMethod(identifier, code , Auth.VerificationMethod.EMAIL);
10}

以下は SMS を使用した場合です。

1public void initVerification() {
2// user will receive code on their registered verified phone
3 identifier = UserManagement.initVerificationMethod(Auth.VerificationMethod.SMS);
4}
5
6public Auth.VerificationResult verifyVerification() {
7// requiring identifier from the initVerification
8// the code will need to be entered in this method
9return UserManagement.verifyVerificationMethod(identifier, code , Auth.VerificationMethod.SMS);
10}

次の例は、Salesforce Authenticator を使用した 2 要素認証の Apex コードを示しています。

1public void initVerification() {
2// user will receive push notification on their registered 2FA devices
3 identifier = UserManagement.initVerificationMethod(Auth.VerificationMethod.SALESFORCE_AUTHENTICATOR);
4}
5
6public Auth.VerificationResult verifyVerification() {
7// requiring identifier from the initVerification
8// user will need to take the action on their registered 2FA devices
9return UserManagement.verifyVerificationMethod(identifier, '' , Auth.VerificationMethod.SALESFORCE_AUTHENTICATOR);
10}

次の 2 つの例は、パスワード検証や TOTP 検証に verifyVerificationMethod のみを使用する 2 要素認証の Apex コードを示しています。

1public Auth.VerificationResult verifyVerification() {
2// user will enter their password as a param in the verifyVerificationMethod for password verification method
3return UserManagement.verifyVerificationMethod('', password , Auth.VerificationMethod.PASSWORD);
4}
1public Auth.VerificationResult verifyVerification() {
2// user will enter their registered time-based one-time password (TOTP) code (token)
3return UserManagement.verifyVerificationMethod('', code , Auth.VerificationMethod.TOTP);
4}