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

如何通过Python SDK配置Azure容器应用的认证选项?

解决Azure容器应用Python SDK配置AD认证后提示无身份提供商的问题

问题原因

你当前的AuthConfig配置中,Azure Active Directory的注册信息不完整,缺少**客户端ID(client_id)**这一核心参数,同时open_id_issuer的格式不符合Azure AD v2.0端点的要求,导致Azure门户无法识别有效的身份提供商配置。

修复步骤及代码示例

1. 补充AD应用注册关键参数

必须在AzureActiveDirectoryRegistration中指定client_id(即你在Azure AD中创建的应用注册的客户端ID),同时修正open_id_issuer的格式为https://login.microsoftonline.com/{租户ID}/v2.0(而非sts.windows.net)。

2. 修改后的完整AuthConfig代码

client.container_apps_auth_configs.create_or_update(
    resource_group_name=resource_group_name,
    container_app_name=container_app_name,
    auth_config_name="current",  # 系统强制要求使用"current"作为AuthConfig名称
    auth_config_envelope=AuthConfig(
        platform=AuthPlatform(
            enabled=True
        ),
        global_validation=GlobalValidation(
            unauthenticated_client_action="Return401"
        ),
        identity_providers=IdentityProviders(
            azure_active_directory=AzureActiveDirectory(
                enabled=True,
                registration=AzureActiveDirectoryRegistration(
                    client_id="YOUR-AD-APP-CLIENT-ID",  # 必填:AD应用注册的客户端ID
                    open_id_issuer="https://login.microsoftonline.com/YOUR-TENANT-ID/v2.0"  # 修正为标准格式
                ),
                login=AzureActiveDirectoryLogin(
                    login_parameters=["scope=openid profile email"]  # 可选:指定登录权限范围
                )
            )
        ),
        login=Login(
            allowed_audiences=["https://YOUR-CONTAINER-APP-URL"]  # 可选:指定允许的受众,匹配应用域名
        ),
        http_settings=HttpSettings(
            require_https=True  # 强制HTTPS,安全最佳实践
        )
    )
)

3. 关键参数说明

  • client_id:Azure AD应用注册的唯一标识,没有这个参数,Azure无法关联到有效的身份提供商。
  • open_id_issuer:必须使用login.microsoftonline.com开头的格式,这是Azure AD v2.0端点的标准地址,旧的sts.windows.net格式会导致配置无法被正确识别。
  • allowed_audiences:指定容器应用的访问URL,确保令牌的受众与应用匹配,避免认证失败。

4. 配置验证

执行代码后等待1-2分钟让配置生效,再刷新Azure门户的认证页面:

  • 若配置正确,门户会显示已配置的Azure AD身份提供商
  • 可通过访问容器应用URL测试是否自动跳转到AD登录页面

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 04:55:31