Hello,
I have never used ASP.NET Core Identity before. Instead, I have been implementing authentication using ServiceStack Auth in the following way:
-
I override CredentialsAuthProvider and implemented TryAuthenticateAsync to validate credentials directly against my own table without using the UserAuth table.
-
I did not use the built-in registration or role assignment services, as they were not required.
-
Users were authenticated via JWT, and I used JwtAuthProvider with additional payload data.
-
I registered authentication as follows:
public void Configure(IWebHostBuilder builder)
{
builder
.ConfigureServices(_ => { })
.ConfigureAppHost(appHost =>
{
var appSettings = appHost.AppSettings;
var authFeature = new AuthFeature(
() => new UserSession(),
[
new MitCredentialsAuthProvider {SkipPasswordVerificationForInProcessRequests = true},
new JwtAuthProvider(appSettings)
{
AuthKeyBase64 = appSettings.GetString("AuthKeyBase64"),
RequireSecureConnection = false,
UseTokenCookie = true,
ExpireTokensIn = TimeSpan.FromHours(12),
CreatePayloadFilter = (payload, session) =>
{
payload["ConnectionName"] = ((UserSession)session).ConnectionName?.ToString();
},
PopulateSessionFilter = (session, payload, _) =>
{
if (session is not UserSession b2BSession) return;
b2BSession.ConnectionName = payload["ConnectionName"];
}
}
])
{
IncludeDefaultLogin = false,
IncludeAssignRoleServices = false,
IncludeRegistrationService = false
};
appHost.Plugins.Add(authFeature);
});
}
- I used the ConnectionName from JWT to automatically add DbInfo to all incoming requests using the following configuration:
public class ConfigureGlobalRequest : IHostingStartup
{
public void Configure(IWebHostBuilder builder) => builder
.ConfigureAppHost(appHost => appHost
.GlobalRequestFilters.Add((req, res, dto) =>
{
var session = req.GetSession() as UserSession;
req.Items[Keywords.DbInfo] = new ConnectionInfo {
NamedConnection = session?.ConnectionName
};
}));
}
I see that it is now recommended to use EndPoint routing, which requires IdentityAuth.
However, I do not need EF or Microsoft Identity.
Additionally, I need to ensure that the ConnectionName from JWT is still available in requests so I can continue injecting DbInfo into all incoming requests as before.
What would be the recommended approach to migration while preserving my current request flow?
Thanks in advance!