Sometimes I write literary content with substance and longstanding impact, and sometimes I just write stuff down that I might need to remember in the future.
Wen migrating a .NET Core 2.2 IdentityServer4 project to .NET Core 3.1 I had a number of struggles. The biggest one was that the IdentityServer threw the following error:
idsrv was not authenticated. Failure message: Unprotect ticket failed
After scouring the entire internet all I got was responses alluding to the fact that I needed to have the same data protection key on both instances of my website. The only problem with that was that I only had one single instance. Since I was also faffing about with changing DataProtection (unwisely, but hey, I like to live dangerously on my free time) – this was a very effective distraction that kept me debugging the wrong thing for ages.
After starting off from a blank .NET Core 3.1 template and adding all the crust from my old site I finally stumbled upon the difference.
In my earlier migration attempt I had mistakenly put:
app.UseEndpoints(o =>
{
o.MapControllers();
});
Now, my main problem was that I had made multiple changes between testing, which is a cardinal sin I only allow myself in my free time, which is why it is so precious now. If you had only made this change and run the website you would notice that it isn’t running, probably. But since I changed a bunch of stuff at once I had a challenge figuring out what went wrong.
In the default template the writing was different and gave completely different results:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
And lo, not only did the website load with the default IdS4 development mode homepage, the unprotect errors went away(!!).
The main lesson here is: Don’t be stupid, change one thing at a time – even if you think you know what you’re doing.