You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Graph API或REST API创建Azure B2C租户?

使用ARM REST API创建Azure B2C租户

目前没有直接通过Microsoft Graph API创建Azure B2C租户的端点,但可以通过Azure Resource Manager (ARM) REST API实现该需求,以下是具体方案:

前提条件

  • 持有具备所有者或全局管理员角色的服务主体,且该主体在目标Azure订阅下拥有足够权限
  • 确保订阅已注册Microsoft.AzureActiveDirectory资源提供者(未注册可先通过ARM API完成注册)

具体操作步骤

  1. 获取服务主体访问令牌
    使用服务主体的客户端ID、客户端密钥、租户ID,向Azure AD令牌端点请求针对https://management.azure.com/的访问令牌,示例请求:

    POST /{tenant-id}/oauth2/v2.0/token HTTP/1.1
    Host: login.microsoftonline.com
    Content-Type: application/x-www-form-urlencoded
    
    client_id={client-id}&scope=https%3A%2F%2Fmanagement.azure.com%2F.default&client_secret={client-secret}&grant_type=client_credentials
    
  2. 发起B2C租户创建请求
    使用获取到的令牌调用ARM API端点:

    PUT /subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/Microsoft.AzureActiveDirectory/b2cDirectories/{b2c-tenant-name}?api-version=2021-04-01 HTTP/1.1
    Host: management.azure.com
    Authorization: Bearer {access-token}
    Content-Type: application/json
    
    {
        "location": "global",
        "sku": {
            "name": "PremiumP1",
            "tier": "Premium"
        },
        "properties": {
            "createTenantProperties": {
                "countryCode": "US",
                "displayName": "My B2C Tenant"
            }
        }
    }
    

    参数说明:

    • {b2c-tenant-name} 需全局唯一,格式为{自定义名称}.onmicrosoft.com
    • location 固定为global
    • sku.name 可选PremiumP1、PremiumP2或Free(免费版有使用限制)
    • countryCode 为两位ISO国家代码(如CN、US等)
  3. 查询创建状态
    租户创建为异步操作,可通过GET请求查询进度:

    GET /subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/Microsoft.AzureActiveDirectory/b2cDirectories/{b2c-tenant-name}?api-version=2021-04-01 HTTP/1.1
    Host: management.azure.com
    Authorization: Bearer {access-token}
    

注意事项

  • 单个Azure订阅最多可创建10个B2C租户(免费版限制可能不同)
  • 租户创建完成后,核心属性(如国家代码)无法通过ARM API修改
  • 服务主体需拥有订阅级别的Microsoft.AzureActiveDirectory/b2cDirectories/write权限

内容的提问来源于stack exchange,提问作者Suvmam950

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 03:42:06