SSO IDのApp Userの検索
SSO IDのApp Userの検索
ユーザーがSSOプロバイダを使用してBox Platformアプリケーションにログインする際、まず必要なのは、Boxユーザーレコードが作成された前回のログイン試行から、そのユーザーがすでに存在するかどうかを確認することです。
Boxユーザーが検出されたら、そのユーザーとしてBox APIにアクセスするために、ユーザーアクセストークンを作成するかas-user呼び出しを実行する必要があります。
Boxユーザーが検出されない場合は、そのSSOユーザーレコードに関連付けられた新しいユーザーを作成する必要があります。
既存のユーザーの検索には、会社ユーザーのリストを取得エンドポイントを使用できます。external_app_user_idとloginのどちらのメソッドを使用しているかによって、クエリは若干異なります。
external_app_user_idを使用したユーザーの検索
格納されているexternal_app_user_id値を使用して会社ユーザーを検索するには、SSOプロバイダの次の情報が必要になります。
- UID (必須): SSOユーザーレコードの一意の識別子です。
取得したら、パラメータでexternal_app_user_id定義を指定して、会社ユーザーのリストを取得エンドポイントにリクエストを実行します。
Node
 
const ssoUID = 'SSO User Unique ID';
// Check enterprise users for matching external_app_user_id against SSO UID
client.enterprise.getUsers({ "external_app_user_id": ssoUID })
.then((users) => {
    if (users.total_count > 0) {
        // User found, fetch user ID
        const userId = users.entries[0].id;
    } else {
        // User not found - create new user record
    }
});
Java
 
String ssoUID = "SSO User Unique ID";
// Check enterprise users for matching external_app_user_id against SSO UID
URL url = new URL("https://api.box.com/2.0/users?external_app_user_id=" + ssoUID);
BoxAPIRequest request = new BoxAPIRequest(client, url, "GET");
BoxJSONResponse jsonResponse = (BoxJSONResponse) request.send();
JsonObject jsonObj = jsonResponse.getJsonObject();
JsonValue totalCount = jsonObj.get("total_count");
if (totalCount.asInt() > 0) {
    // User found, fetch
    // Fetch user ID
    JsonArray entries = (JsonArray) jsonObj.get("entries");
    JsonObject userRecord = (JsonObject) entries.get(0);
    JsonValue userId = userRecord.get("id");
} else {
    // User not found - create new user record
}
Python
 
sso_uid = 'SSO User Unique ID'
# Validate is user exists
url = f'https://api.box.com/2.0/users?external_app_user_id={sso_uid}'
headers = {'Authorization': 'Bearer ' + access_token}
response = requests.get(url, headers=headers)
user_info = response.json()
if (user_info['total_count'] == 0):
    # User not found - create new user record
else:
    # User found, fetch user ID
    user = user_info['entries'][0]
    user_id = user['id']
メールアドレスを使用したユーザーの検索
loginのメールアドレスを使用して会社ユーザーを検索するには、SSOプロバイダの次の情報が必要になります。
- メールアドレス (必須): SSOユーザーレコードの一意のメールアドレスです。
取得したら、filter_termとしてメールアドレスを指定して、会社ユーザーのリストを取得エンドポイントにリクエストを実行します。これは、メールアドレスまたは名前を使用した検索に使用できるようになります。
Node
 
const ssoEmail = 'ssouser@email.com';
client.enterprise.getUsers({filter_term: ssoEmail})
    .then(users => {
        if (users.total_count > 0) {
            // User found, fetch user ID
            const userId = users.entries[0].id;
        } else {
            // User not found - create new user record
        }
    });
Java
 
String ssoEmail = "ssouser@email.com";
Iterable<BoxUser.Info> users = BoxUser.getAllEnterpriseUsers(client, ssoEmail);
Python
 
sso_email = 'ssouser@email.com'
users = client.users(user_type='all', filter_term=ssoEmail)
if (users['total_count'] == 0):
    # User not found - create new user record
else:
    # User found, fetch user ID
    user = users['entries'][0]
    user_id = user['id']