I have this code:
using System.Reflection;
using PaymentGatewayApi.Common;
using ServiceStack.Auth;
using ServiceStack.Logging;
[assembly: HostingStartup(typeof(ConfigureAuth))]
namespace PaymentGatewayApi;
public class ConfigureAuth : IHostingStartup
{
private static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod()?.DeclaringType);
public void Configure(IWebHostBuilder builder) => builder
.ConfigureAppHost(appHost =>
{
appHost.Plugins.Add(new AuthFeature(() => new AuthUserSession(),
[
new CredentialsAuthProvider(appHost.AppSettings),
new JwtAuthProvider(appHost.AppSettings),
new JwtAuthProviderReader(appHost.AppSettings)
{
PopulateSessionFilter = (s, p, r) =>
{
if (p.TryGetValue(ApplicationConstants.ScopeKey, out var scopes))
{
s.Roles = scopes.FromJson<List<string>>();
Logger.Info($"Registered scopes: {s.Roles.ToJsv()}");
}
.......
r.SetItem(ApplicationConstants.RequestClientIdKey, s.UserName);
},
UseTokenCookie = false
}
])
{
MaxLoginAttempts = appHost.AppSettings.Get("Authentication:MaxLoginAttempts", 5),
IncludeDefaultLogin = false,
SessionExpiry = TimeSpan.FromMinutes(appHost.AppSettings.Get("Session:MinutesExpiration", 30)),
});
appHost.Plugins.Add(new RegistrationFeature());
Logger.Info("Registered Authentication.");
});
}
This code is in another file, where I config the databases dependencies:
//User repository
var authRepo = new OrmLiteAuthRepository<User, UserOAuthDetail>(
container.Resolve<IDbConnectionFactory>()) { UseDistinctRoleTables = false };
container.Register<IUserAuthRepository>(authRepo);
container.Register<IAuthRepository>(authRepo);
My problem is that the two providers entered into conflict. When I attempt to execute credentials login, it returns the error:
PrivateKey required to use: RS256
Why this method attempts to look for any private key to validate this data
When I attempt to execute Jwt login, it returns the error:
The input string 'cf2c40f3-9cd9-419c-916b-2e4f93821a22' was not in a correct format.
Why this method attempts to validate the token data with the database.
I don't know the problem. I have tried several possible solutions, but none are correct.
Does anyone know what could be happening or give me some guidance on where to look for the solution?