Blazor WASM Identity: There was an error trying to log you in: 'No account to get tokens for.'

Clearly I'm capable of making mistakes no other person has thought of!

Blazor WASM Identity: There was an error trying to log you in: 'No account to get tokens for.'

So I've setup a few Blazor projects thus far, most of which have used custom identity providers to deal with disconnected or legacy provider situations. However I've done one Blazor (and multiple MVC/RazorPages) project using the original MSAL Azure AD support which I found setting up a pain.

Imagine my joy when the new 'simple' Microsoft.Identity.Web package hits release

To be clear, it does live up to it's claims, but if you are playing late at night without paying attention, you may run into the error that is the title of this post.

So what did I mess up this time.

I asked @ChristosMatskas if there was any new guidance, and he pointed me to the new templates

I installed the new template, and followed the existing docs, setting up the new server API app in Azure AD, and the client app (this is what I messed up).

Having created the necessary entries in Azure AD, I created a new Blazor WASM project from the new templates, and successfully logged in. Having confirmed it all worked (it didn't), it got distracted by whatever was going on that day and didn't come back to the project for an hour or so, which is when I first encountered "There was an error trying to log you in: 'No account to get tokens for.'"

The troubleshooting

During the early days of Blazor, I've run into a fair amount of issues that can be resolved by manually deleting the bin and obj folders, so that was my first attempt, which made no difference.

I then attempted clearing the site data, which changed things. I was once again promoted for login, went through the login process fine, and at this stage noticed that the login process itself appeared to be fine (it wasn't), but still ended up with the same error message.

Off to DuckDuckGo I went, searching for the error message, but I found no-one else had reported this issue... clearly I'm capable of making mistakes no other person has thought of!

Knowing it was likely my own mistake (oh yes), but being utterly confused about the initial success and then failure, I reached out to @ChristosMatskas again

After some sanity checks, I re-ran the project creation with the same settings in another directory, and once again the login seemed to be working, while the original project was still failing

I was now completely bemused as to what was going on, but thankfully, reaching out to @ChristosMatskas had paid off.

The fix

It turns out the issue was very simple, I had missed a crucial step in the Azure AD client setup, I hadn't switched the app type to SPA from the default Web. I had also presumed this sort of oversight would have caused the authentication to fail completely, but instead causes the error in the title of this blog after x mins. Thankfully @AzureAndChill had the answer

The joy of modern Microsoft

I've made these sorts of 'late night' mistakes a lot over the past almost two decades! The days of struggling through MSDN and 'official' support channels are mainly over though. Thanks to @ChristosMatskas and @AzureAndChill for finding my oversight in quick order.