asp.net-core - 当 Azure AD 和身份服务器通过 cookie 进行消息交换时不可用?
问题描述
我正在使用 IS4 作为 Azure AD 的联合网关进行设置。在发生某些事情之前一切正常,我不再收到来自 Azure AD 的 cookie。服务器设置如下:
IdentityModelEventSource.ShowPII = true; //Add this line
services.AddIdentityServer(options =>
{
options.Events.RaiseErrorEvents = true;
options.Events.RaiseFailureEvents = true;
options.Events.RaiseInformationEvents = true;
options.Events.RaiseSuccessEvents = true;
options.PublicOrigin = settings.PublicOrigin;
options.Authentication = new AuthenticationOptions()
{
CookieLifetime = TimeSpan.FromHours(1), // ID server cookie timeout set to 10 hours
CookieSlidingExpiration = true
,
};
})
.AddInMemoryApiResources(Config.GetApis())
.AddInMemoryIdentityResources(Config.GetIdentityResources())
.AddInMemoryClients(Config.GetClients())
.AddDeveloperSigningCredential(persistKey: false)
.AddCustomUserStore()
.AddProfileService<ProfileService>();
services
.AddAuthentication(options =>
{
})
.AddOpenIdConnect("aad", "Sign-in with Azure AD", options => Configuration.Bind("AzureAd", options))
.AddCookie()
.AddLocalApi(options => options.ExpectedScope = "api");
services.Configure<OpenIdConnectOptions>("aad", options =>
{
options.Scope.Add("openid");
options.Scope.Add("profile");
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
options.SignOutScheme = IdentityServerConstants.SignoutScheme;
options.ResponseType = "id_token";
});
// preserve OIDC state in cache (solves problems with AAD and URL lenghts)
services.AddOidcStateDataFormatterCache("aad");
客户端如下:
new Client
{
ClientId = "implicit",
ClientName = "Implicit Client",
AllowAccessTokensViaBrowser = true,
RequireConsent = false,
RedirectUris = { "https://notused" },
PostLogoutRedirectUris = { "https://notused" },
AccessTokenType = AccessTokenType.Jwt,
AccessTokenLifetime = 3600,
AllowedGrantTypes = GrantTypes.Implicit,
EnableLocalLogin=false,
AllowedScopes = {
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.Email,
"api"},
},
我从Quickstarts获得了样本,并根据我的需要对其进行了调整。一切正常,直到它没有。
它在这里失败:
result = await HttpContext.AuthenticateAsync(IdentityServerConstants.ExternalCookieAuthenticationScheme);
因为它没有在上下文中找到任何 Cookie。如何解决此问题?什么时候(什么条件)Cookies 通常不存在于上下文中?(鉴于他们应该是)我没有使用 AspNet Identity。我只想要外部登录。
解决方案
推荐阅读
- r - r中的JointModel中的“纵向和事件过程中的样本量不同”
- jquery - 如何测试使用 Jquery 的 Angular 组件?
- reactjs - 如何在 Azure 云上托管 grafana?
- docker - docker 中 --net=host 参数的实际用例是什么?
- docker - Debian 映像 - 未找到 /sbin/init
- javascript - postcss 和 simple-vars - 使用对象内部的变量
- gradle - Intellij 插件,gradle 在使用 localPath 时总是下载 java-compiler-ant-tasks 的 LATEST-EAP-SNAPSHOT
- excel - 删除不同工作簿上的空行
- search - 考虑到服装等电子商务商品属性组合级别的产品可用性的 Solr 刻面
- python - AnalysisException:没有具有签名的匹配函数:rtrim(VARCHAR(40),STRING)