.net - ASP.NET TicketDataFormat.Unprotect(cookieValue) returns null -
i trying decrypt authentication cookie set .net 4.6.2 mvc app created following in startup.auth:
ticketdataformat = new aspnetticketdataformat( new dataprotectorshim( dataprotectionprovider.create(new directoryinfo(@"c:\keys\")) .createprotector("blah")))
this i'm doing try , decrypt it:
// create data protector facilitate in decrypting cookie. var provider = dataprotectionprovider.create(new directoryinfo(keydirectory)); var dataprotector = provider.createprotector(dataprotectorpurpose); // decrypt cookie, obtaining authentication ticket. var ticketdataformat = new ticketdataformat(dataprotector); var ticket = ticketdataformat.unprotect(cookievalue);
this working fine until started identity customisation. have created new identityuser inherits identityuser can add few fields. failing read identity maybe?
thanks
i have solved through lot of playing about.
it turned out combination of following issues:
- the purpose , sub purposes strings provided dataprotectionprovider createprotector method not set "microsoft.aspnetcore.authentication.cookies.cookieauthenticationmiddleware", "cookies", "v2". had them string value reading docs, thought string, long same between apps needing share cookie.
- one of apps using version 1.1.2 of microsoft.aspnetcore.dataprotection nuget package, whereas other using version 1.1.1. upgraded 1.1.1 -> 1.1.2.
all seems work fine now. having custom user identity in 1 app not in other not matter, cookie can still understood , claimsidentity extracted.
Comments
Post a Comment