ユーザーのパスワードを変更する
Overview
重要なコンセプト
Auth0 DashboardまたはManagement APIを使ってパスワードのリセットをトリガーする
このトピックでは、データベース内のユーザーのパスワードをリセットする各種方法をご紹介します。パスワードを変更できるのは、データベース接続のユーザーに限ります。ソーシャル接続またはエンタープライズ接続を使ってサインインしているユーザーは、IDプロバイダー(GoogleやFacebookなど)のパスワードをリセットする必要があります。以下の手順はユーザーのメールアドレスがわかっている場合のみ有効です。
ユーザーパスワードの変更には、2つの基本的な方法があります。
インタラクティブなパスワードリセットフローをトリガーしてユーザーにリンクをメール送信する。ユーザーは、リンクからAuth0パスワードリセットページを開いて新しいパスワードを入力します。
Auth0 Management APIまたはAuth0 Dashboardを使って新しいパスワードを直接設定する。
他のトピックをお探しですか?
カスタムのパスワードリセットページを設定する方法については、「パスワードリセットページをカスタマイズする」をお読みください。
パスワードの変更後にカスタムの動作を実装するには、「アクションのトリガー:post-change-password」をお読みください。
ご自身のAuth0ユーザーアカウントのパスワードをリセットするには、「アカウントパスワードをリセットする」をお読みください。
インタラクティブなパスワードリセットフローをトリガーする
インタラクティブなパスワードリセットフローをトリガーする方法は、ユニバーサルログインページ経由とAuthentication API経由の2つがあり、どちらが適しているかはユースケースによって決まります。
ユニバーサルログインページ
アプリケーションがユニバーサルログインを使用している場合、ユーザーは、ログイン画面のLockウィジェットを使ってパスワードリセットメールをトリガーします。ユニバーサルログインを使う場合、ユーザーは[Don't remember your password?(パスワードをお忘れの場合)]というリンクをクリックして、メールアドレスを入力します。すると、POST要求がAuth0に送られ、パスワードリセットのプロセスがトリガーされます。ユーザーはパスワードリセットのメールを受信します。
Authentication API(認証API)
アプリケーションがAuthentication APIを通じたインタラクティブなパスワードリセットフローを採用している場合は、POST
呼び出しを行います。email
フィールドにパスワードを変更する必要があるユーザーのメールアドレスを入力します。呼び出しが成功すると、ユーザーはパスワードリセットのメールを受信します。
APIをブラウザーから呼び出す場合は、送信元URLが許可されていることを確認してください:
[Auth0 Dashboard]>[Applications(アプリケーション)]>[Applications(アプリケーション)]に移動して、URLを[Allowed Origins (CORS)(許可されているオリジン(CORS))]のリストに追加します。
カスタムデータベース接続の場合は、Authentication APIでchangePassword
を呼び出す前にデータベースにそのユーザーが存在しないかどうかをチェックします。
curl --request POST \
--url 'https://{yourDomain}/dbconnections/change_password' \
--header 'content-type: application/json' \
--data '{"client_id": "{yourClientId}","email": "","connection": "Username-Password-Authentication"}'
Was this helpful?
var client = new RestClient("https://{yourDomain}/dbconnections/change_password");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/json");
request.AddParameter("application/json", "{\"client_id\": \"{yourClientId}\",\"email\": \"\",\"connection\": \"Username-Password-Authentication\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Was this helpful?
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://{yourDomain}/dbconnections/change_password"
payload := strings.NewReader("{\"client_id\": \"{yourClientId}\",\"email\": \"\",\"connection\": \"Username-Password-Authentication\"}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("content-type", "application/json")
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}/dbconnections/change_password")
.header("content-type", "application/json")
.body("{\"client_id\": \"{yourClientId}\",\"email\": \"\",\"connection\": \"Username-Password-Authentication\"}")
.asString();
Was this helpful?
var axios = require("axios").default;
var options = {
method: 'POST',
url: 'https://{yourDomain}/dbconnections/change_password',
headers: {'content-type': 'application/json'},
data: {
client_id: '{yourClientId}',
email: '',
connection: 'Username-Password-Authentication'
}
};
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 = @{ @"content-type": @"application/json" };
NSDictionary *parameters = @{ @"client_id": @"{yourClientId}",
@"email": @"",
@"connection": @"Username-Password-Authentication" };
NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://{yourDomain}/dbconnections/change_password"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];
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}/dbconnections/change_password",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\"client_id\": \"{yourClientId}\",\"email\": \"\",\"connection\": \"Username-Password-Authentication\"}",
CURLOPT_HTTPHEADER => [
"content-type: application/json"
],
]);
$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("")
payload = "{\"client_id\": \"{yourClientId}\",\"email\": \"\",\"connection\": \"Username-Password-Authentication\"}"
headers = { 'content-type': "application/json" }
conn.request("POST", "/{yourDomain}/dbconnections/change_password", payload, 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}/dbconnections/change_password")
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["content-type"] = 'application/json'
request.body = "{\"client_id\": \"{yourClientId}\",\"email\": \"\",\"connection\": \"Username-Password-Authentication\"}"
response = http.request(request)
puts response.read_body
Was this helpful?
import Foundation
let headers = ["content-type": "application/json"]
let parameters = [
"client_id": "{yourClientId}",
"email": "",
"connection": "Username-Password-Authentication"
] as [String : Any]
let postData = JSONSerialization.data(withJSONObject: parameters, options: [])
let request = NSMutableURLRequest(url: NSURL(string: "https://{yourDomain}/dbconnections/change_password")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data
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?
パスワードリセットメール
パスワードリセットのプロセスがどの方法でトリガーされた場合でも、ユーザーに、パスワードのリセット用リンクがメールで届きます。

ユーザーがリンクをクリックすると、パスワードリセットページに移動します。
ユーザーが新しいパスワードを入力・送信すると、新しい資格情報でログインできるようになった旨が表示されます。
パスワードリセットについての注意事項:
メール内のリセット用リンクは1回しか使用できません。
ユーザーが複数のパスワードリセットメールを受信した場合は、直近のメール内のリンクのみが有効です。
[URL Lifetime(ライフタイム)]フィールドは、リンクの有効期間を示します。Auth0 Dashboardからパスワード変更メールをカスタマイズしてリンクのライフタイムを変更できます。
Auth0 Actionsを使ってパスワードリセットフローに他の要素を含めることもできます。詳細については、「パスワードリセットフロー」をお読みください。
クラシックログインでは、パスワードリセットの完了後にユーザーをリダイレクトするURLを構成できます。このURLが、成功したというサインとメッセージを受け取ります。詳細については、「メールテンプレートをカスタマイズする」の「リダイレクト先URLの構成」セクションをお読みください。
ユニバーサルログインでは、成功するとユーザーをデフォルトのログインルートにリダイレクトし、ユニバーサルログインフローの一部としてエラーケースを処理します。このエクスペリエンスでは、メールテンプレートにあるリダイレクトURLが無視されます。
パスワードリセットチケットを生成する
Management APIにはCreate a Password Change Ticketエンドポイントがあり、パスワードのリセットメールの場合と同じようにURLが生成されます。メール配信方式が適切でない場合は、生成されたURLを使用できます。デフォルトのフローでは、メールの配信がユーザーのIDを検証しますが(偽装者によるメール受信箱へのアクセスを防ぐため)、チケットのURLを使用する場合は、アプリケーションが何らかの手段でユーザーのIDを検証しなければなりません。
新しいパスワードを直接設定する
パスワードリセットメールを送らずに、ユーザーの新しいパスワードを直接設定するには、Management APIまたはAuth0 Dashboardのいずれかを使います。
Management APIの使用
独自のパスワードリセットフローを実装したい場合は、Management APIへのサーバー要求からユーザーパスワードを直接変更できます。それには、Update a UserエンドポイントにPATCH
呼び出しを行います。
curl --request PATCH \
--url 'https://{yourDomain}/api/v2/users/%7BuserId%7D' \
--header 'authorization: Bearer {yourMgmtApiAccessToken}' \
--header 'content-type: application/json' \
--data '{"password": "newPassword","connection": "connectionName"}'
Was this helpful?
var client = new RestClient("https://{yourDomain}/api/v2/users/%7BuserId%7D");
var request = new RestRequest(Method.PATCH);
request.AddHeader("content-type", "application/json");
request.AddHeader("authorization", "Bearer {yourMgmtApiAccessToken}");
request.AddParameter("application/json", "{\"password\": \"newPassword\",\"connection\": \"connectionName\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Was this helpful?
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://{yourDomain}/api/v2/users/%7BuserId%7D"
payload := strings.NewReader("{\"password\": \"newPassword\",\"connection\": \"connectionName\"}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("content-type", "application/json")
req.Header.Add("authorization", "Bearer {yourMgmtApiAccessToken}")
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.patch("https://{yourDomain}/api/v2/users/%7BuserId%7D")
.header("content-type", "application/json")
.header("authorization", "Bearer {yourMgmtApiAccessToken}")
.body("{\"password\": \"newPassword\",\"connection\": \"connectionName\"}")
.asString();
Was this helpful?
var axios = require("axios").default;
var options = {
method: 'PATCH',
url: 'https://{yourDomain}/api/v2/users/%7BuserId%7D',
headers: {
'content-type': 'application/json',
authorization: 'Bearer {yourMgmtApiAccessToken}'
},
data: {password: 'newPassword', connection: 'connectionName'}
};
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 = @{ @"content-type": @"application/json",
@"authorization": @"Bearer {yourMgmtApiAccessToken}" };
NSDictionary *parameters = @{ @"password": @"newPassword",
@"connection": @"connectionName" };
NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://{yourDomain}/api/v2/users/%7BuserId%7D"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
[request setHTTPMethod:@"PATCH"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];
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/%7BuserId%7D",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => "{\"password\": \"newPassword\",\"connection\": \"connectionName\"}",
CURLOPT_HTTPHEADER => [
"authorization: Bearer {yourMgmtApiAccessToken}",
"content-type: application/json"
],
]);
$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("")
payload = "{\"password\": \"newPassword\",\"connection\": \"connectionName\"}"
headers = {
'content-type': "application/json",
'authorization': "Bearer {yourMgmtApiAccessToken}"
}
conn.request("PATCH", "/{yourDomain}/api/v2/users/%7BuserId%7D", payload, 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/%7BuserId%7D")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Patch.new(url)
request["content-type"] = 'application/json'
request["authorization"] = 'Bearer {yourMgmtApiAccessToken}'
request.body = "{\"password\": \"newPassword\",\"connection\": \"connectionName\"}"
response = http.request(request)
puts response.read_body
Was this helpful?
import Foundation
let headers = [
"content-type": "application/json",
"authorization": "Bearer {yourMgmtApiAccessToken}"
]
let parameters = [
"password": "newPassword",
"connection": "connectionName"
] as [String : Any]
let postData = JSONSerialization.data(withJSONObject: parameters, options: [])
let request = NSMutableURLRequest(url: NSURL(string: "https://{yourDomain}/api/v2/users/%7BuserId%7D")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "PATCH"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data
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?
Auth0 Dashboardを使ってユーザーパスワードを手動で設定する
Auth0テナントの管理者権限を持っていれば誰でも、[Auth0 Dashboard]>[User Management(ユーザー管理)]>[Users(ユーザー)]からユーザーのパスワードを手動で変更できます。
パスワードを変更したいユーザーの名前を選択します。
ページ下部の[Danger Zone(危険ゾーン)]に移動します。
赤い[Change Password(パスワード変更)]ボックスで[Change(変更)]を選択します。
新しいパスワードを入力して、[Save(保存)]を選択します。