如何使用多个CookieAuthenticationOptions?

时间:2017-03-09 20:33:18

标签: cookies owin

我的OWINStartup代码中有2个cookieAuthenticationoptions,但只有第一个才能获得荣誉。

我找不到任何信息。在线,如果有人可以帮助我,如果有可能的话,我们将非常感激。这是我的代码:

        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

        // Enable clients to authenticate using cookies
        var cookieOptions = new CookieAuthenticationOptions
        {
            AuthenticationType = "type1",
            LoginPath = new PathString("/"),
            SlidingExpiration = true,
            Provider =
                    new CookieAuthenticationProvider
                    {
                        OnValidateIdentity = OnValidateIdentityAsync,
                        OnException = OnCookieException,
                        OnResponseSignIn = OnResponseSignIn,
                    },
        };

        // For auth tokens to properly work for both delve.office.com and <region>.delve.office.com
        // we use a separate auth cookie per region/deployment.
        if (!IsDevBox.Value)
        {
            cookieOptions.CookieName = AuthCookieNameWithoutSuffix + CookieHelper.GetCookieSuffix();
            cookieOptions.CookieDomain = AuthCookieDomain;
        }

        // Enable clients to authenticate using cookies
        var cookieOptions_BearerToken = new CookieAuthenticationOptions
        {
            AuthenticationType = "type2",
            CookieName = "BearerToken",
            LoginPath = new PathString("/"),
            SlidingExpiration = true,
            Provider =
                    new CookieAuthenticationProvider
                    {
                        OnValidateIdentity = OnValidateIdentityAsync_BearerToken,
                        OnException = OnCookieException,
                        OnResponseSignIn = OnResponseSignIn,
                    },
        };

        app.UseCookieAuthentication(cookieOptions);
        app.UseCookieAuthentication(cookieOptions_BearerToken);

如果我只使用BearerToken选项,它可以工作 - 但在上述情况下,它没有得到尊重。有什么想法吗?

非常感谢!

0 个答案:

没有答案