使用本指南:https://docs.microsoft.com/en-us/azure/active-directory/develop/tutorial-v2-asp-webapp我已经将Microsoft Login添加到两个项目中。该项目是作为同一个域的子域,我想让他们共享登录。在CookieAuthenticationOptions上,我尝试设置了CookieDomain。这就是我的Startup.cs中的内容
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
CookieAuthenticationOptions options = new CookieAuthenticationOptions {
CookieName = "mytestcookie",
CookieDomain = ".azurewebsites.net",
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie
};
app.UseCookieAuthentication(options);
var ss1 = app.GetDefaultSignInAsAuthenticationType();
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions {
ClientId = clientId,
Authority = authority,
RedirectUri = redirectUri,
PostLogoutRedirectUri = redirectUri,
Scope = OpenIdConnectScope.OpenIdProfile + " email",
SignInAsAuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
ResponseType = OpenIdConnectResponseType.CodeIdToken,
Notifications = new OpenIdConnectAuthenticationNotifications {
AuthenticationFailed = OnAuthenticationFailed,
RedirectToIdentityProvider = notification => {
if (notification.ProtocolMessage.RequestType == OpenIdConnectRequestType.Authentication) {
if ((IsAjaxRequest(notification.Request) || IsApiRequest(notification.Request)) && notification.Response.StatusCode == (int)HttpStatusCode.Unauthorized) {
notification.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
notification.HandleResponse();
return Task.FromResult(0);
}
}
return Task.FromResult(0);
},
},
UseTokenLifetime = false
});然而,这打破了一些东西,导致微软登录重定向我来回几次。
发布于 2021-04-08 21:08:26
根据:ASP.NET Core Sharing Identity Cookie across azure web apps on default domain (*.azurewebsites.net)
.azurewebsites.net被列入黑名单。使用我自己的域名解决了这个问题。
https://stackoverflow.com/questions/67001183
复制相似问题