ユーザープロファイルの更新に向けてIDプロバイダー接続を構成する
アップストリームIDプロバイダーの接続設定を更新して、ユーザープロファイルのルート属性の更新がいつ許可されるかをAuth0 DashboardやManagement APIで制御することができます。
特に設定を変更しない限り、Auth0以外のIDプロバイダー(Google、Facebook、Xなど)によって提供されるユーザープロファイル属性は、ユーザーがログインするたびにIDプロバイダーから更新されるため、直接編集することはできません。
正規化ユーザープロファイルのルート属性であるname、nickname、given_name、family_name、pictureを編集可能にするには、接続がAuth0と同期されるように構成して、ユーザー属性がユーザープロファイルの作成時のみIDプロバイダーに更新されるようにしなければなりません。
ルート属性を個別に編集するか、Management APIを使用して一括インポートすることができます。
Dashboardを使用する
[Auth0 Dashboard]>[Authentication(認証)]に移動し、接続の種類をデータベース、ソーシャル、エンタープライズ、パスワードレスから選択します。
接続名を選択して設定を確認します。
[Advanced(詳細設定)]セクションで[Sync user profile attributes at each login(毎回のログインでユーザープロファイル属性を同期する)]をオンまたはオフに設定し、[Save(保存)]を選択します。
Management APIを使用する
この手順を完了させる前に、必ず接続のoptions
オブジェクトに既存の値を取得して、現在の値がオーバーライドされないようにします。これを行わないと、更新後、元のオブジェクトに欠けているパラメーターが失われてしまいます。
接続更新エンドポイントにPATCH
呼び出しを行います。必ず、呼び出しに元のoptions値を含めて、現在の値が上書きされないようにしてください。また、CONNECTION_ID
、MGMT_API_ACCESS_TOKEN
、ATTRIBUTE_UPDATE_VALUE
のプレースホルダーの値をそれぞれ接続ID、Management APIのアクセストークン、属性の更新値に置き換えます。
curl --request PATCH \
--url 'https://{yourDomain}/api/v2/connections/CONNECTION_ID' \
--header 'authorization: Bearer MGMT_API_ACCESS_TOKEN' \
--header 'cache-control: no-cache' \
--header 'content-type: application/json' \
--data '{"options":{"set_user_root_attributes": "ATTRIBUTE_UPDATE_VALUE"}}'
Was this helpful?
var client = new RestClient("https://{yourDomain}/api/v2/connections/CONNECTION_ID");
var request = new RestRequest(Method.PATCH);
request.AddHeader("content-type", "application/json");
request.AddHeader("authorization", "Bearer MGMT_API_ACCESS_TOKEN");
request.AddHeader("cache-control", "no-cache");
request.AddParameter("application/json", "{\"options\":{\"set_user_root_attributes\": \"ATTRIBUTE_UPDATE_VALUE\"}}", 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/connections/CONNECTION_ID"
payload := strings.NewReader("{\"options\":{\"set_user_root_attributes\": \"ATTRIBUTE_UPDATE_VALUE\"}}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("content-type", "application/json")
req.Header.Add("authorization", "Bearer MGMT_API_ACCESS_TOKEN")
req.Header.Add("cache-control", "no-cache")
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/connections/CONNECTION_ID")
.header("content-type", "application/json")
.header("authorization", "Bearer MGMT_API_ACCESS_TOKEN")
.header("cache-control", "no-cache")
.body("{\"options\":{\"set_user_root_attributes\": \"ATTRIBUTE_UPDATE_VALUE\"}}")
.asString();
Was this helpful?
var axios = require("axios").default;
var options = {
method: 'PATCH',
url: 'https://{yourDomain}/api/v2/connections/CONNECTION_ID',
headers: {
'content-type': 'application/json',
authorization: 'Bearer MGMT_API_ACCESS_TOKEN',
'cache-control': 'no-cache'
},
data: {options: {set_user_root_attributes: 'ATTRIBUTE_UPDATE_VALUE'}}
};
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 MGMT_API_ACCESS_TOKEN",
@"cache-control": @"no-cache" };
NSDictionary *parameters = @{ @"options": @{ @"set_user_root_attributes": @"ATTRIBUTE_UPDATE_VALUE" } };
NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://{yourDomain}/api/v2/connections/CONNECTION_ID"]
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/connections/CONNECTION_ID",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => "{\"options\":{\"set_user_root_attributes\": \"ATTRIBUTE_UPDATE_VALUE\"}}",
CURLOPT_HTTPHEADER => [
"authorization: Bearer MGMT_API_ACCESS_TOKEN",
"cache-control: no-cache",
"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 = "{\"options\":{\"set_user_root_attributes\": \"ATTRIBUTE_UPDATE_VALUE\"}}"
headers = {
'content-type': "application/json",
'authorization': "Bearer MGMT_API_ACCESS_TOKEN",
'cache-control': "no-cache"
}
conn.request("PATCH", "/{yourDomain}/api/v2/connections/CONNECTION_ID", 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/connections/CONNECTION_ID")
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 MGMT_API_ACCESS_TOKEN'
request["cache-control"] = 'no-cache'
request.body = "{\"options\":{\"set_user_root_attributes\": \"ATTRIBUTE_UPDATE_VALUE\"}}"
response = http.request(request)
puts response.read_body
Was this helpful?
import Foundation
let headers = [
"content-type": "application/json",
"authorization": "Bearer MGMT_API_ACCESS_TOKEN",
"cache-control": "no-cache"
]
let parameters = ["options": ["set_user_root_attributes": "ATTRIBUTE_UPDATE_VALUE"]] as [String : Any]
let postData = JSONSerialization.data(withJSONObject: parameters, options: [])
let request = NSMutableURLRequest(url: NSURL(string: "https://{yourDomain}/api/v2/connections/CONNECTION_ID")! 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?
値 | 説明 |
---|---|
CONNECTION_ID |
root属性の更新を許可する接続のID。 |
MGMT_API_ACCESS_TOKEN |
update:connections のスコープを持つManagement APIのアクセストークン。 |
ATTRIBUTE_UPDATE_VALUE |
ユーザープロファイルのroot属性の更新を許可する時間を示します。有効な値はon_first_login とon_each_login です。新しい接続ではon_each_login が既定値になります。 |