AspNet Core CookieAuthentication with injected SessionStore

后端 未结 1 1701
暗喜
暗喜 2021-02-19 08:53

During migration of an ASPNetCore 1.1 Project to ASPNetCore 2.0, we stumbled upon a Problem with the Cookie-AuthN and its SessionStore.

ASP.NET Core 1

相关标签:
1条回答
  • 2021-02-19 09:48

    After long search I came accross this discussion https://github.com/aspnet/Security/issues/1338 where they mentioned IPostConfigureOptions interface. I put that together and this works for me:

    1) Implement interface IPostConfigureOptions<CookieAuthenticationOptions>

    public class PostConfigureCookieAuthenticationOptions : IPostConfigureOptions<CookieAuthenticationOptions>
    {
        private readonly ITicketStore _ticketStore;
    
        public PostConfigureCookieAuthenticationOptions(ITicketStore ticketStore)
        {
            _ticketStore = ticketStore;
        }
    
        public void PostConfigure(string name, CookieAuthenticationOptions options)
        {
            options.SessionStore = _ticketStore;
        }
    }
    

    2) Register this implementation to the container in Startup.ConfigureServices method

    services.AddSingleton<IPostConfigureOptions<CookieAuthenticationOptions>, PostConfigureCookieAuthenticationOptions>();

    0 讨论(0)
提交回复
热议问题