【发布时间】:2019-01-23 15:51:19
【问题描述】:
我目前遇到了一个奇怪的问题。我们正在托管一个使用 Identity Server 4 作为联合网关的 ASP.CORE 2.1 应用程序。
第一次使用 Chrome 导航到该站点时,它是空的 - 在控制台中只留下一个小提示,表明 CORB 已阻止某些内容。
查看 fiddler 似乎它阻止了回发到应用程序 /signin-oidc 中间件的“隐藏”表单。
但奇怪的是,刷新后一切正常,CORB 不再是问题。查看提琴手中相应的“好”响应,相同的标题是相同的。
我可以验证来自 Identity Server 的 form_post 没有到达提琴手中的应用程序,调试 OpenID 事件和每个请求,我得到了 nada。
app.Use(async (context, next) =>
{
if (!context.User.Identity.IsAuthenticated)
{
// look to see if bearer is present instead of cookies
string auth = context.Request.Headers["Authorization"];
if (string.IsNullOrEmpty(auth) || !auth.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
{
// request needs to be authenticated
await context.ChallengeAsync();
}
else
{
await next();
}
}
else
{
// all is good, continue
await next();
}
});
为什么 CORB 会阻止初始请求?它可以是浏览器导航与刷新中的一种行为吗?
这是我正在调试的事件的客户端配置:
services.AddAuthentication(opts =>
{
opts.DefaultChallengeScheme = "oidce";
opts.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie(opts =>
{
opts.SessionStore = new MemoryCacheTicketRepository();
opts.ExpireTimeSpan = TimeSpan.FromHours(2);
})
.AddIdentityServerAuthentication("Bearer", opts =>
{
...
})
.AddOpenIdConnect("oidce", opts =>
{
...
opts.Events = new Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectEvents()
{
OnAuthenticationFailed = async p =>
{
var test = p;
},
OnAuthorizationCodeReceived = async p =>
{
var test = p;
},
OnMessageReceived = async p =>
{
var test = p;
},
OnRemoteFailure = async p =>
{
var test = p;
},
OnTicketReceived = async p =>
{
var test = p;
},
OnTokenResponseReceived = async p =>
{
var test = p;
},
OnTokenValidated = async p =>
{
var test = p;
}
};
});
由于好的或坏的响应上的标题没有区别,我猜'Access-Control-Allow-Headers' 和'Content-Type' 不是问题。会是什么?
【问题讨论】:
-
大约 6 个月前遇到过同样的问题。我的一位同事开发人员得出的结论是,当您刷新源时是用户而不是静默重定向,因此 csps 很放松。这也是特定于 chrome 的,在 safari 和 Opera 中,我们在刷新 iirc 后无法让它工作。
-
你有没有为 Chrome 修复它?
-
是的,我们添加了 csp 标头以允许来自我们的 id 提供者的表单发布。
-
正如您在上面的提琴手图像中看到的那样,身份服务器响应中存在 Content-Security-Policy 标头。还是您将其包含在其他地方?
-
不需要将 csps 添加到登录 oidc 端点所在的客户端应用程序中。
标签: asp.net-core identityserver4 openid-connect