UserCookieAuthentication in Mono 3.4.1

后端 未结 1 977
清酒与你
清酒与你 2021-02-06 03:04

When ever I add the line below to my Startup class I get the exception below. This is a self hosted exe running from mono (Ubuntu). It works fine in windows. I\'ve narrowed it d

相关标签:
1条回答
  • 2021-02-06 03:40

    Okay this is happening because OWIN uses DpapiDataProtector by default and DPAPI is a windows API (Data Protection API) and does not work in mono. Luckily you can override the default in your cookie options. Below is an example where AesDataProtectorProvider is a custom IDataProtector that I found here: Using Oauth tickets across several services?

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                TicketDataFormat =
                    new SecureDataFormat<AuthenticationTicket>(DataSerializers.Ticket,
                        new AesDataProtectorProvider("testing"), TextEncodings.Base64)
            });
    

    With this code my project starts in Mono again.

    UPDATE:

    You can also have a custom IDataProtectionProvider and have all of owin use that with this:

    app.SetDataProtectionProvider(new CustomIDataProtectionProvider());
    
    0 讨论(0)
提交回复
热议问题