Azure active directory Azure AD-不同租户中主帐户和来宾帐户之间的链接

Azure active directory Azure AD-不同租户中主帐户和来宾帐户之间的链接,azure-active-directory,Azure Active Directory,我们正在与下面的用例作斗争,在一个高度规范的环境中,审计正在对所有Azure广告进行。感谢您的帮助 上下文: 公司中有1个主要Azure AD租户,是O365租户 (标记为“用户租户”) 中的多个其他Azure广告租户 作为“应用程序”承租人的公司: 各 部门/业务部门有自己的应用程序租户(适用于 隔离目的),以管理其Azure资源(一个或多个) 订阅) 邀请来自用户租户(O365)的某些用户访问 某些应用程序租户(Azure)作为来宾帐户 要解决的用例: 员工将离开公司并从“用户”租

我们正在与下面的用例作斗争,在一个高度规范的环境中,审计正在对所有Azure广告进行。感谢您的帮助

上下文:

  • 公司中有1个主要Azure AD租户,是O365租户 (标记为“用户租户”)
  • 中的多个其他Azure广告租户 作为“应用程序”承租人的公司:
    • 各 部门/业务部门有自己的应用程序租户(适用于 隔离目的),以管理其Azure资源(一个或多个) 订阅)
    • 邀请来自用户租户(O365)的某些用户访问 某些应用程序租户(Azure)作为来宾帐户
要解决的用例:

  • 员工将离开公司并从“用户”租户(O365)中删除
  • 公司需要将该员工从其作为来宾帐户添加到的所有“应用程序”租户中删除
  • 是否有一种方法可以根据O365租户自动/以编程方式识别并删除该员工在不同AAD租户中的所有帐户
  • AAD帐户(主帐户>来宾帐户)之间是否存在公共“链接”,我们可以利用该链接来识别/删除AAD用户
  • 变通办法?最佳实践

根据您的描述,您可以在主租户中注册一个多租户应用程序: 创建应用程序后,为其创建一个秘密,并记下其应用程序ID秘密,我们稍后将使用它连接到您的租户:

授予此应用程序Microsoft Graph API的“User.ReadWrite.All”权限,因为我们将调用Microsoft Graph API来删除用户: 不要忘记单击“授予租户管理员许可”按钮以完成分配过程

通过链接让其他租户的管理员同意使用此应用程序:

https://login.microsoftonline.com/<your tenant ID>/adminConsent?client_id=<your multi-tenant app ID>
https://login.microsoftonline.com//adminConsent?client_id=
此应用程序将作为服务原则添加到其他租户中: 因此,我们可以使用此应用程序通过所有租户执行一些操作

只需运行下面的Powershell即可从您的所有租户中删除一个用户,我已经在我这方面进行了测试,它适用于我。顺便说一句,请在运行之前删除所有目录角色,否则如果用户被分配了一些管理员角色,您将得到403错误

#config your multi tenant app id and secret here.
$appid = "<YOUR MULTI TENANT APP ID>"
$secret = "<YOUR MULTI TENANT APP SECRET>"
$userEmailaddress = "<EMAIL ADDRESS OF THE USER YOU WANT TO DELETE>"

#config all your tenents here
$tenants = "<TENANT 1 ID/NAME>","TENANT 2 ID/NAME",...

#check and delete user by email address in all tenants 
foreach($tenant in $tenants){

    #get token to call microsoft graph api to delete users 
    $body=@{
        "grant_type"="client_credentials";
        "resource"="https://graph.microsoft.com";
        "client_id"=$appid;
        "client_secret" = $secret
    }
 
    $result=Invoke-RestMethod -Uri "https://login.windows.net/$tenant/oauth2/token" -Method POST -Body $body 


    #get user object from tenant 
    $userguestPrefix = $userEmailaddress.Replace('@','_')
    $searchURL = "https://graph.microsoft.com/v1.0/users?`$filter=startswith(userPrincipalName,'$userEmailaddress') or startswith(userPrincipalName,'$userguestPrefix')"

    $searchUserResult = Invoke-RestMethod -Uri $searchURL -Method GET -Headers @{'Authorization'='Bearer '+$result.access_token}

    #remove the user from tenant
    if($searchUserResult.value.Length -eq 1){
        echo "remove:"$searchUserResult.value[0].displayName" from tenant : $tenant"
        $removeURL = "https://graph.microsoft.com/v1.0/users/" + $searchUserResult.value[0].id
        Invoke-RestMethod -Uri $removeURL -Method DELETE -Headers @{'Authorization'='Bearer '+$result.access_token}
    }

}
#在此处配置您的多租户应用程序id和密码。
$appid=“”
$secret=“”
$userEmailaddress=“”
#在这里配置你所有的公寓
$tenants=“”,“租户2 ID/名称”,。。。
#在所有租户中通过电子邮件地址检查并删除用户
foreach($租户中的租户){
#获取令牌以调用microsoft graph api删除用户
$body=@{
“授权类型”=“客户端凭据”;
“资源”=”https://graph.microsoft.com";
“客户id”=$appid;
“客户机密”=$secret
}
 
$result=调用RestMethod-Uri“https://login.windows.net/$tenant/oauth2/token“-方法POST-Body$Body
#从租户获取用户对象
$userguestPrefix=$userEmailaddress.Replace('@','.'''
$searchURL=”https://graph.microsoft.com/v1.0/users?`$filter=startswith(userPrincipalName,$userEmailaddress')或startswith(userPrincipalName,$userguestPrefix')”
$searchUserResult=调用RestMethod-Uri$searchURL-Method GET-Headers@{'Authorization'='Bearer'+$result.access_token}
#从租户中删除用户
if($searchUserResult.value.Length-等式1){
echo“remove:$searchUserResult.value[0].displayName“from-tenant:$tenant”
$removeURL=”https://graph.microsoft.com/v1.0/users/“+$searchUserResult.value[0].id”
调用RestMethod-Uri$removeURL-Method DELETE-Headers@{'Authorization'='Bearer'+$result.access_token}
}
}

如果您有任何进一步的问题,请随时告诉我

根据您的描述,您可以在主租户中注册一个多租户应用程序: 创建应用程序后,为其创建一个秘密,并记下其应用程序ID秘密,我们稍后将使用它连接到您的租户:

授予此应用程序Microsoft Graph API的“User.ReadWrite.All”权限,因为我们将调用Microsoft Graph API来删除用户: 不要忘记单击“授予租户管理员许可”按钮以完成分配过程

通过链接让其他租户的管理员同意使用此应用程序:

https://login.microsoftonline.com/<your tenant ID>/adminConsent?client_id=<your multi-tenant app ID>
https://login.microsoftonline.com//adminConsent?client_id=
此应用程序将作为服务原则添加到其他租户中: 因此,我们可以使用此应用程序通过所有租户执行一些操作

只需运行下面的Powershell即可从您的所有租户中删除一个用户,我已经在我这方面进行了测试,它适用于我。顺便说一句,请在运行之前删除所有目录角色,否则如果用户被分配了一些管理员角色,您将得到403错误

#config your multi tenant app id and secret here.
$appid = "<YOUR MULTI TENANT APP ID>"
$secret = "<YOUR MULTI TENANT APP SECRET>"
$userEmailaddress = "<EMAIL ADDRESS OF THE USER YOU WANT TO DELETE>"

#config all your tenents here
$tenants = "<TENANT 1 ID/NAME>","TENANT 2 ID/NAME",...

#check and delete user by email address in all tenants 
foreach($tenant in $tenants){

    #get token to call microsoft graph api to delete users 
    $body=@{
        "grant_type"="client_credentials";
        "resource"="https://graph.microsoft.com";
        "client_id"=$appid;
        "client_secret" = $secret
    }
 
    $result=Invoke-RestMethod -Uri "https://login.windows.net/$tenant/oauth2/token" -Method POST -Body $body 


    #get user object from tenant 
    $userguestPrefix = $userEmailaddress.Replace('@','_')
    $searchURL = "https://graph.microsoft.com/v1.0/users?`$filter=startswith(userPrincipalName,'$userEmailaddress') or startswith(userPrincipalName,'$userguestPrefix')"

    $searchUserResult = Invoke-RestMethod -Uri $searchURL -Method GET -Headers @{'Authorization'='Bearer '+$result.access_token}

    #remove the user from tenant
    if($searchUserResult.value.Length -eq 1){
        echo "remove:"$searchUserResult.value[0].displayName" from tenant : $tenant"
        $removeURL = "https://graph.microsoft.com/v1.0/users/" + $searchUserResult.value[0].id
        Invoke-RestMethod -Uri $removeURL -Method DELETE -Headers @{'Authorization'='Bearer '+$result.access_token}
    }

}
#在此处配置您的多租户应用程序id和密码。
$appid=“”
$secret=“”
$userEmailaddress=“”
#在这里配置你所有的公寓
$tenants=“”,“租户2 ID/名称”,。。。
#在所有租户中通过电子邮件地址检查并删除用户
foreach($租户中的租户){
#获取令牌以调用microsoft graph api删除用户
$body=@{
“授权类型”=“客户端凭据”;
“资源”=”https://graph.microsoft.com";
“客户id”=$appid;
“客户机密”=$secret
}
 
$result=调用RestMethod-Uri“https://login.windows.net/$tenant/oauth2/token“-方法POST-Body$Body
#从租户获取用户对象
$userguestPrefix=$userEmailaddress.Replace('@','.'''
$searchURL=”https://graph.microsoft.com/v1.0/users?`$filter=startswith(userPrincipalName,$userEmailaddress')或startswith(userPrincipalName,$userguestPrefix')”
$searchUserResult=调用RestMethod-Uri$searchURL-Method GET-Headers@{'Authorization'='Bearer'+$result.access_token}