首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Microsoft使用子域登录

Microsoft使用子域登录
EN

Stack Overflow用户
提问于 2021-04-08 17:31:13
回答 1查看 17关注 0票数 0

使用本指南:https://docs.microsoft.com/en-us/azure/active-directory/develop/tutorial-v2-asp-webapp我已经将Microsoft Login添加到两个项目中。该项目是作为同一个域的子域,我想让他们共享登录。在CookieAuthenticationOptions上,我尝试设置了CookieDomain。这就是我的Startup.cs中的内容

代码语言:javascript
复制
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
        });

然而,这打破了一些东西,导致微软登录重定向我来回几次。

EN

回答 1

Stack Overflow用户

发布于 2021-04-08 21:08:26

根据:ASP.NET Core Sharing Identity Cookie across azure web apps on default domain (*.azurewebsites.net)

.azurewebsites.net被列入黑名单。使用我自己的域名解决了这个问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67001183

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档