New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] NullReferenceException when multiple authentication schemes are configured #765
Comments
I removed Finbuckle.Multitenant and Authentication worked perfectly fine |
My project is: https://github.com/fullstackhero/dotnet-webapi-boilerplate |
So I have been digging around in the code of Finbuckl.Multitenant and it seems to be in EntityTypeBuilderExtensions.cs where the expression is built, TenantInfo.Id seems to be null so the expression fails. But no idea why IMultiTenantDbContext.TenantInfo is null... @AndrewTriesToCode your help would be highly appreciated as I have been trying to fix this bug for days now... |
Hi, sure I will take a look this weekend. Quick question, at what point in the application is the db context being created? App startup? During a request? |
Appreciate it very much! The dbcontext is created during a request (scoped).
|
@JonasDev17 it took me a while to get to the root of it. Long story short the tenant isn't set because the the In your Finbuckle config I added the desired scheme and I got the person profile back as expected:
Alternatively you could make the jwt scheme the default authenticate scheme in your authentication setup. Let me know if this resolves the issue for you and if so please update the item on Stack Overflow. I need to check the docs and if this behavior isn't there then add a description. Now, it occurs to me that you might want to try claims on a few different schemes. The |
@AndrewTriesToCode thank you so much, that worked! However as you already mentioned, I need to try claims on multiple schemes, as I want to be able to use tokens from two different auth providers. |
I have same issue. |
Min, did the solution for @JonasDev17 above also work for you? |
I saw that FSH didn't implement Finbuckle as sample: https://github.com/Finbuckle/Finbuckle.MultiTenant/tree/main/samples/net6.0 |
@AndrewTriesToCode please add new api project sample which use Asp.Net Core Identity + Finbuckle.MultiTenant + Jwt authentication. For newbie, I tried build but I can't |
This is exactly what I'm experiencing #642 |
@min-hung do you mind opening a separate issue for your situation and provide some of your setup code? |
Seems like when you configure multiple authentication schemes, it fails to get the TenantInfo.
I have asked about it here:
https://stackoverflow.com/questions/77372700/c-sharp-asp-net-core-nullreferenceexception-when-using-multiple-authentication?noredirect=1#comment136403049_77372700
The text was updated successfully, but these errors were encountered: