❔ How to configure an external provider in .Net8 Blazor with individual auth?
Hey guys,
I'm having problems adding an external authentication provider to the basic Blazor WebApp template.
When doing it like this the
oidc
flow works fine, but now navigating to "Account/Manage" gives an "Error: Unable to load user with ID 'BattleNetId'".
This seems to happen, because GetUserAsync(principal)
in UserAccessor.cs
tries to fetch a user with the BattleNetId
from AspNetUsers
instead of doing a lookup in AspNetUserLogins
first.
Is the way I registered that external provider even correct, because I don't entirely understand those AddCookie calls, but without that I get a runtime Error.
How do I "correctly" fetch the user if he is logged in using an external provider?34 Replies
Adding
options.SignInScheme = IdentityConstants.ExternalScheme;
to the provider config now results in the new user being stored and fetched correctly.what Blazor framework is this?
It's the .Net8 rc2 Blazor WebApp template created in Rider with individual authentication.
okay
what Blazor framework is this?
Sorry I'm confused, what you want to know specifically.
All the code I shared is from the template which uses EFCore and Identity. With a a Nugget for the additional provider.
It all runs server side.
so, Blazor Server?
Yes, currently I haven't registered the WASM services and don't have anything running as WASM or Auto component.
do you plan to?
that's a weird thing to say if you're actually using Blazor Server
I may want to try running mostly in auto. But that will prove difficult with database access. And I haven't thought about it that much
auto?
The new .NET 8 Auto InteractiveAuto mode that fetches the wasm runtime in the background and switches to wasm on reload
that sounds horrifying
the server-side pre-rendering option, basically
anyway
so
gives an "Error: Unable to load user with ID 'BattleNetId'"what gives this error?
UserAccessor redirects to the Error Page with this explicit string when it can't find the user.
what is
UserAccessor
?A class in the template that is used to get the user from the db.
let's see it
Can't rn don't have my laptop
mm-kay
That's the method that's called from there. The rest of the class is just dependency injection
I just found that in a history I sadly can't share the rest rn.
sure
so, either the user doesn't exist in the database, or
principal
doesn't contain a user ID (or whatever userManager
uses to lookup a user
is BattleNetId
the ID of a test user you created?The priciple contains a claim from the external provider that carries the id of that external provider. The BattleNetid (Sorry seems like that original question wasn't too clear)
is
BattleNetId
the ID of a valid user?
in the database?It does a lookup for this external id on the user table and doesn't find anything. Because the user itself has its own id.
What should happen is, that it looks up in AspUserLogins (or however that table is called exactly). There a mapping of external provider+Id to internal userid is stored.
okay
so
the principal is likely malformed
let's look at it
I will come back to you with this tomorrow if that's fine. I'm on a trip right now and as I mentioned can't really post or test any code.
But thanks for trying to help!
this is a chat app
that's how it works
respond when you can
Still rude to be in a conversation and just stop responding imo .
meh
you already stated you don't have access to your code at the moment
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.is one of those blacked-out values
"BattleNetId"
?In the first collapsed claim the nameidentifier is the id. The rest are the name
but are any of them
"BattleNetId"
?
presumably not
so, I guess our assumption was wrong then
principal
seems to be fine, let's dig into GetUserAsync()
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.