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

Azure Functions Python应用:如何启用IdentityModelEventSource.ShowPII属性

在Azure Functions Python API中启用PII以排查AAD身份验证问题

你在Azure Functions上托管的Python API遇到AAD身份验证错误,错误信息中的Issuer和ValidIssuer等敏感信息(PII)被隐藏,官方文档仅提供了.NET环境下的启用方法,以下是Python环境的解决方案:

错误信息

{
    "code": 401,
    "message": "IDX10205: Issuer validation failed. Issuer: '[PII of type 'System.String' is hidden. 
               For more details, see https://aka.ms/IdentityModel/PII.]'. 
               Did not match: validationParameters.ValidIssuer: 
               '[PII of type 'System.String' is hidden. For more details, see https://aka.ms/IdentityModel/PII.]' 
               or validationParameters.ValidIssuers: '[PII of type 'System.String' 
               is hidden. For more details, see https://aka.ms/IdentityModel/PII.]'. 
               For more details, see https://aka.ms/IdentityModel/issuer-validation. "
}

启用PII日志的方法

1. 本地调试环境(修改local.settings.json)

在local.settings.json的Values节点中添加环境变量IdentityModel_PII_Logging_enabled并设置为true:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "IdentityModel_PII_Logging_enabled": "true"
  }
}

2. 生产环境(Azure门户配置)

  1. 登录Azure门户,找到你的Functions应用
  2. 进入配置 > 应用程序设置
  3. 添加新的应用设置:
    • 名称:IdentityModel_PII_Logging_enabled
    • 值:true
  4. 保存并重启Functions应用

说明

启用后,错误日志会显示真实的Issuer和ValidIssuer值,你可以直接对比两者是否匹配,常见问题包括:

  • Issuer URL格式不一致(比如是否包含尾部斜杠)
  • ValidIssuer配置的租户ID或域名错误
  • 应用注册中的受众(Audience)配置不匹配

排查完成后,建议关闭PII日志(将值设为false),避免敏感信息泄露。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 05:10:27