【问题标题】:Azure AD - Link between primary and guest accounts in different tenantsAzure AD - 不同租户中的主要帐户和来宾帐户之间的链接
【发布时间】:2019-10-30 17:15:35
【问题描述】:

我们正在努力处理下面的用例,在一个高度监管的环境中,审计正在对所有 Azure AD 运行。任何帮助表示赞赏。

上下文:

  • 公司1个主要Azure AD租户,为O365租户 (标记为“用户租户”)
  • 中的多个其他 Azure AD 租户 公司,即“应用”租户:
    • 每个 部门/业务部门有自己的应用程序租户(对于 隔离目的),管理其 Azure 资源(一个或多个 订阅)
    • 邀请用户租户 (O365) 中的一些用户 一些应用程序租户 (Azure) 作为来宾帐户

用例解决:

  • 员工即将离开公司并从“用户”租户 (O365) 中删除
  • 公司需要将该员工从他/她作为访客帐户添加到的所有“应用程序”租户中删除
  • 有没有一种方法可以根据 O365 租户自动/以编程方式识别并删除该员工在不同 AAD 租户中的所有帐户?
  • 我们可以利用 AAD 帐户(主要 > 访客)之间的公共“链接”来识别/删除 AAD 用户吗?
  • 解决方法?最佳做法?

【问题讨论】:

  • 所以你正在寻找一种方法来删除所有已知 Azure AD 租户中的来宾用户,一旦主租户删除用户?

标签: azure-active-directory


【解决方案1】:

根据您的描述,您可以在主租户中注册一个多租户应用 创建应用程序后,为其创建一个秘密并记下它的 应用程序 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>

并且此应用程序将作为服务原则添加到其他租户中: 这样我们就可以使用这个应用程序通过所有租户执行一些操作。

只需运行下面的 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}
    }

}

如果您有任何进一步的疑虑,请随时告诉我。

【讨论】:

  • 嗨@ChristopheG。 ,你的问题解决了吗?是否需要进一步的帮助?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-09-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-06
  • 2020-07-10
  • 1970-01-01
相关资源
最近更新 更多