認証APIを使って認証要素を管理する
Before you start
アプリケーションに対してMFAの付与タイプを有効にします。詳細については、「付与タイプを更新する」をお読みください。
Auth0は、アプリケーションでの多要素認証(MFA)に使用しているAuthenticatorの管理に役立つ、いくつかのAPIエンドポイントを提供しています。これらのエンドポイントを使うと、認証要素を管理するためのユーザーインターフェイスをビルドすることができます。
MFA APIアクセストークンを取得する
MFA APIを呼び出して登録を管理するためには、まずMFA API用のアクセストークンを取得する必要があります。
MFA APIを認証フローの一環として使用するには、「リソース所有者のパスワード付与とMFAで認証する」で説明されている手順に従ってください。認証要素を管理するためのユーザーインターフェイスをビルドする場合は、認証中だけでなく、いつでもMFA APIで使用できるトークンを取得する必要があります。
ユニバーサルログインを使用している場合は、MFA APIを呼び出す前に、https://{yourDomain}/mfa/
オーディエンスを指定して認可エンドポイントへリダイレクトします。
ユニバーサルログイン
リソース所有者のパスワード付与(ROPG)を使用している場合には、以下の3つのオプションがあります。
リソース所有者のパスワード付与
MFAオーディエンスのトークンを要求する際、以下のスコープを要求できます。
ログイン時に
https://{yourDomain}/mfa/
オーディエンスを要求し、リフレッシュトークンを使用して後でリフレッシュします。Authenticatorをリストおよび削除する必要がある場合は、
https://{yourDomain}/mfa/
オーディエンスを指定して、/oauth/token
で再び認証することをユーザーに求めます。ユーザーは、MFAを完了しないと認証要素をリスト・削除できません。Authenticatorのリストのみを必要とする場合は、ユーザー名/パスワードで
/oauth/token
を使用して再び認証することをユーザーに求めます。エンドポイントは、mfa_required
エラー、およびAuthenticatorのリストに使用できるmfa_token
を返します。ユーザーがAuthenticatorを確認するには、パスワードを提供する必要があります。
スコープ
スコープ | 説明 |
---|---|
enroll |
新しいAuthenticatorを登録する。 |
read:authenticators |
既存のAuthenticatorを一覧表示する。 |
remove:authenticators |
Authenticatorを削除する。 |
ユーザーのAuthenticatorのリストを取得するには、MFA Authenticatorエンドポイントを呼び出します。
Authenticatorのリスト
curl --request GET \
--url 'https://{yourDomain}/mfa/authenticators' \
--header 'authorization: Bearer MFA_TOKEN'
Was this helpful?
var client = new RestClient("https://{yourDomain}/mfa/authenticators");
var request = new RestRequest(Method.GET);
request.AddHeader("authorization", "Bearer MFA_TOKEN");
IRestResponse response = client.Execute(request);
Was this helpful?
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://{yourDomain}/mfa/authenticators"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("authorization", "Bearer MFA_TOKEN")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
Was this helpful?
HttpResponse<String> response = Unirest.get("https://{yourDomain}/mfa/authenticators")
.header("authorization", "Bearer MFA_TOKEN")
.asString();
Was this helpful?
var axios = require("axios").default;
var options = {
method: 'GET',
url: 'https://{yourDomain}/mfa/authenticators',
headers: {authorization: 'Bearer MFA_TOKEN'}
};
axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
Was this helpful?
#import <Foundation/Foundation.h>
NSDictionary *headers = @{ @"authorization": @"Bearer MFA_TOKEN" };
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://{yourDomain}/mfa/authenticators"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
[request setHTTPMethod:@"GET"];
[request setAllHTTPHeaderFields:headers];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"%@", error);
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSLog(@"%@", httpResponse);
}
}];
[dataTask resume];
Was this helpful?
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{yourDomain}/mfa/authenticators",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"authorization: Bearer MFA_TOKEN"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
Was this helpful?
import http.client
conn = http.client.HTTPSConnection("")
headers = { 'authorization': "Bearer MFA_TOKEN" }
conn.request("GET", "/{yourDomain}/mfa/authenticators", headers=headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Was this helpful?
require 'uri'
require 'net/http'
require 'openssl'
url = URI("https://{yourDomain}/mfa/authenticators")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(url)
request["authorization"] = 'Bearer MFA_TOKEN'
response = http.request(request)
puts response.read_body
Was this helpful?
import Foundation
let headers = ["authorization": "Bearer MFA_TOKEN"]
let request = NSMutableURLRequest(url: NSURL(string: "https://{yourDomain}/mfa/authenticators")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers
let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
print(error)
} else {
let httpResponse = response as? HTTPURLResponse
print(httpResponse)
}
})
dataTask.resume()
Was this helpful?
応答にAuthenticatorの種類に関する情報が含まれています。
[
{
"authenticator_type": "recovery-code",
"id": "recovery-code|dev_IsBj5j3H12VAdOIj",
"active": true
},
{
"authenticator_type": "otp",
"id": "totp|dev_nELLU4PFUiTW6iWs",
"active": true,
},
{
"authenticator_type": "oob",
"oob_channel": "sms",
"id": "sms|dev_sEe99pcpN0xp0yOO",
"name": "+1123XXXXX",
"active": true
}
]
Was this helpful?
要素を管理するためのユーザーインターフェイスをエンドユーザー向けにビルドするときは、active
がfalse
のAuthenticatorを無視する必要があります。これらのAuthenticatorは、ユーザーによって確認されないため、MFAチャレンジには使用できません。
MFA APIは、Authenticatorの種類に応じて以下の登録をリストします。
鑑別工具 | アクション |
---|---|
Push and OTP(プッシュとOTP) | プッシュが有効な場合、Auth0はOTP環境も作成します。登録をリストする場合、両方が表示されます。 |
SMS and Voice(SMSと音声) | SMSと音声の両方が有効な場合、SMSまたは音声で登録すると、Auth0は電話番号に対して2つ(SMS用に1つ、音声用にもう1つ)の鑑別工具を自動作成します。 |
Email(メール) | すべての確認されたメールが鑑別工具としてリストされます。 |
Authenticatorを異なる要素で登録する方法については、以下のリンクを参照してください。
Authenticatorを登録する
また、ユーザーを登録するためにいつでもユニバーサルログインフローを使用できます。
関連するAuthenticatorを削除するには、AUTHENTICATOR_ID
を適切なAuthenticator IDに置き換えるMFA AuthenticatorエンドポイントにDELETE
要求を送信します。IDは、Authenticatorをリストした際に取得できます。
Authenticatorを削除する
Authenticatorのリストのためにmfa_token
を使用した場合、Authenticatorを削除するために、ユーザーは、MFAを完了させて、https://{yourDomain}/mfa/
のオーディエンスのアクセストークンを取得する必要があります。
curl --request DELETE \
--url 'https://{yourDomain}/mfa/authenticators/AUTHENTICATOR_ID' \
--header 'authorization: Bearer ACCESS_TOKEN'
Was this helpful?
var client = new RestClient("https://{yourDomain}/mfa/authenticators/AUTHENTICATOR_ID");
var request = new RestRequest(Method.DELETE);
request.AddHeader("authorization", "Bearer ACCESS_TOKEN");
IRestResponse response = client.Execute(request);
Was this helpful?
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://{yourDomain}/mfa/authenticators/AUTHENTICATOR_ID"
req, _ := http.NewRequest("DELETE", url, nil)
req.Header.Add("authorization", "Bearer ACCESS_TOKEN")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
Was this helpful?
HttpResponse<String> response = Unirest.delete("https://{yourDomain}/mfa/authenticators/AUTHENTICATOR_ID")
.header("authorization", "Bearer ACCESS_TOKEN")
.asString();
Was this helpful?
var axios = require("axios").default;
var options = {
method: 'DELETE',
url: 'https://{yourDomain}/mfa/authenticators/AUTHENTICATOR_ID',
headers: {authorization: 'Bearer ACCESS_TOKEN'}
};
axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
Was this helpful?
#import <Foundation/Foundation.h>
NSDictionary *headers = @{ @"authorization": @"Bearer ACCESS_TOKEN" };
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://{yourDomain}/mfa/authenticators/AUTHENTICATOR_ID"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
[request setHTTPMethod:@"DELETE"];
[request setAllHTTPHeaderFields:headers];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"%@", error);
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSLog(@"%@", httpResponse);
}
}];
[dataTask resume];
Was this helpful?
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{yourDomain}/mfa/authenticators/AUTHENTICATOR_ID",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "DELETE",
CURLOPT_HTTPHEADER => [
"authorization: Bearer ACCESS_TOKEN"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
Was this helpful?
import http.client
conn = http.client.HTTPSConnection("")
headers = { 'authorization': "Bearer ACCESS_TOKEN" }
conn.request("DELETE", "/{yourDomain}/mfa/authenticators/AUTHENTICATOR_ID", headers=headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Was this helpful?
require 'uri'
require 'net/http'
require 'openssl'
url = URI("https://{yourDomain}/mfa/authenticators/AUTHENTICATOR_ID")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Delete.new(url)
request["authorization"] = 'Bearer ACCESS_TOKEN'
response = http.request(request)
puts response.read_body
Was this helpful?
import Foundation
let headers = ["authorization": "Bearer ACCESS_TOKEN"]
let request = NSMutableURLRequest(url: NSURL(string: "https://{yourDomain}/mfa/authenticators/AUTHENTICATOR_ID")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "DELETE"
request.allHTTPHeaderFields = headers
let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
print(error)
} else {
let httpResponse = response as? HTTPURLResponse
print(httpResponse)
}
})
dataTask.resume()
Was this helpful?
Authenticatorが削除されると、204応答が返されます。
Authenticatorを削除する際、Authenticatorの種類に応じて以下のアクションが実行されます。
Authenticator | アクション |
---|---|
プッシュ通知とOTP | ユーザーがAuthenticatorのプッシュ通知を登録すると、Auth0もOTPを登録します。いずれかを削除すると、もう一方も削除されます。 |
SMSと音声 | ユーザーがSMSまたは音声を登録すると、Auth0はSMSと音声の2つのAuthenticatorを作成します。いずれかを削除すると、もう一方も削除されます。 |
メール | すべての確認済みメールがAuthenticatorとして表示されますが、削除することはできません。削除できるAuthenticatorのメールは、明示的に登録されているものだけです。 |
復旧コードを削除して新たに生成するには、Auth0のManagement APIのアクセストークンを取得し、Management APIの復旧コード再生成エンドポイントを使用します。
復旧コードを再生成する
curl --request POST \
--url 'https://{yourDomain}/api/v2/users/USER_ID/recovery-code-regeneration' \
--header 'authorization: Bearer MANAGEMENT_API_TOKEN'
Was this helpful?
var client = new RestClient("https://{yourDomain}/api/v2/users/USER_ID/recovery-code-regeneration");
var request = new RestRequest(Method.POST);
request.AddHeader("authorization", "Bearer MANAGEMENT_API_TOKEN");
IRestResponse response = client.Execute(request);
Was this helpful?
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://{yourDomain}/api/v2/users/USER_ID/recovery-code-regeneration"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("authorization", "Bearer MANAGEMENT_API_TOKEN")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
Was this helpful?
HttpResponse<String> response = Unirest.post("https://{yourDomain}/api/v2/users/USER_ID/recovery-code-regeneration")
.header("authorization", "Bearer MANAGEMENT_API_TOKEN")
.asString();
Was this helpful?
var axios = require("axios").default;
var options = {
method: 'POST',
url: 'https://{yourDomain}/api/v2/users/USER_ID/recovery-code-regeneration',
headers: {authorization: 'Bearer MANAGEMENT_API_TOKEN'}
};
axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
Was this helpful?
#import <Foundation/Foundation.h>
NSDictionary *headers = @{ @"authorization": @"Bearer MANAGEMENT_API_TOKEN" };
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://{yourDomain}/api/v2/users/USER_ID/recovery-code-regeneration"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"%@", error);
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSLog(@"%@", httpResponse);
}
}];
[dataTask resume];
Was this helpful?
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{yourDomain}/api/v2/users/USER_ID/recovery-code-regeneration",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"authorization: Bearer MANAGEMENT_API_TOKEN"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
Was this helpful?
import http.client
conn = http.client.HTTPSConnection("")
headers = { 'authorization': "Bearer MANAGEMENT_API_TOKEN" }
conn.request("POST", "/{yourDomain}/api/v2/users/USER_ID/recovery-code-regeneration", headers=headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Was this helpful?
require 'uri'
require 'net/http'
require 'openssl'
url = URI("https://{yourDomain}/api/v2/users/USER_ID/recovery-code-regeneration")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(url)
request["authorization"] = 'Bearer MANAGEMENT_API_TOKEN'
response = http.request(request)
puts response.read_body
Was this helpful?
import Foundation
let headers = ["authorization": "Bearer MANAGEMENT_API_TOKEN"]
let request = NSMutableURLRequest(url: NSURL(string: "https://{yourDomain}/api/v2/users/USER_ID/recovery-code-regeneration")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
print(error)
} else {
let httpResponse = response as? HTTPURLResponse
print(httpResponse)
}
})
dataTask.resume()
Was this helpful?
新しい復旧コードが生成され、エンドユーザーはそれをキャプチャする必要があります。例:
{
"recovery_code": "FA45S1Z87MYARX9RG6EVMAPE"
}
Was this helpful?
{
"recovery_code": "FA45S1Z87MYARX9RG6EVMAPE"
}
Was this helpful?