Daniel
Daniel
Explore posts from servers
KKinde
Created by Daniel on 2/13/2025 in #💻┃support
Protect Next.js API Routes?
Hi, I have succesfully implemented Kinde to protect my Next.js application. Works nice. I have decided to go with Next.js for the backend API and database fetching as well and by default they're also protected by the standard Kinde configuration with <KindeProvider>. Problem is, I need to be able to call the api routes from other clients as well and for simplicity Postman but I can't seem to just do a request with a access token (generated in Kinde portal). The application want to redirect me to the login route when doing HTTP requests from Postman. Is it possible to protect pages and api routes but in a way where I am allowed to call the api routes with authentication by Kinde?
7 replies
KKinde
Created by Daniel on 2/6/2025 in #💻┃support
Kinde & .NET Blazor Server?
Hi, New to Kinde and exploring if it's the right choice for a new project in .NET Blazor. I tried setting up a demo project according to the docs which I understand is more generic .NET-oriented. I do not seem to get Kinde to work in .NET Blazor and read that it might be the case that it is not yet supported: https://community.kinde.com/blazor-server-net-8-kinde-user-login-integration-663TnBGmt3J6 I have added the configuration to the program.cs and use :NET built--in authentication and authroization mechanisms for protecting razor pages. Latest error I now have is: AuthenticationFailureException: OpenIdConnectAuthenticationHandler: message.State is null or empty. I get this when navigating to url/signin-oidc Ayone that have experience using .NET Blazor and Kinde?
47 replies
CC#
Created by Daniel on 2/2/2025 in #help
Inject User and Claims to DbContext using Factory
I've put the last 2 days trying to figure out how to solve a problem which I believe have to do with the combination of Blazor Server, State management and EF Core via Factory. I need to get TenantID from Users Claims to be able to resolve a connection string, dynamically. What I have come up to is that following registering of DbContext does not work when multiple users log in and out within same circuit i Blazor. The connection string is not updated:
builder.Services.AddDbContextFactory<TenantAppContext>((sp, option) =>
{
var tenantHelper = sp.GetRequiredService<ITenantHelper>();
var tenantConnectionString = tenantHelper.GetTenantConnectionString();
if (tenant != null)
{
option.UseSqlServer(tenantConnectionString);
}
});
builder.Services.AddDbContextFactory<TenantAppContext>((sp, option) =>
{
var tenantHelper = sp.GetRequiredService<ITenantHelper>();
var tenantConnectionString = tenantHelper.GetTenantConnectionString();
if (tenant != null)
{
option.UseSqlServer(tenantConnectionString);
}
});
One way I think I can get it to work is by injecting IHttpContextAccessor _httpContextAccessor; into the DbContext and get the claim that way. Would this be okay? according to the majority of the documentation I should use AuthenticationStateProvider but that is not possible to inject to the db context since I can't inject scoped services. In the end I need to add a global query filter to my context
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyGlobalFilter<BaseEntity>(e => !e.IsDeleted && e.TenantId == _helper.GetTenant());

}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyGlobalFilter<BaseEntity>(e => !e.IsDeleted && e.TenantId == _helper.GetTenant());

}
Appreciate any guidance and help solving this in a good way.
3 replies