Refactor authentication schemes for sender and receiver
Updated `AuthScheme` to introduce a distinct `Sender` scheme and renamed the `Receiver` scheme for clarity. Updated `Program.cs` to use the new `Sender` scheme in JWT authentication and explicitly associate authentication schemes with `Sender` and `Receiver` policies. Removed the deprecated `AuthPolicy.ReceiverTFA` policy. These changes improve the separation and maintainability of authentication and authorization logic.
This commit is contained in:
@@ -136,7 +136,7 @@ try
|
||||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
})
|
||||
.AddJwtBearer(opt =>
|
||||
.AddJwtBearer(AuthScheme.Sender, opt =>
|
||||
{
|
||||
opt.TokenValidationParameters = new TokenValidationParameters
|
||||
{
|
||||
@@ -240,13 +240,13 @@ try
|
||||
builder.Services.AddAuthorizationBuilder()
|
||||
.AddPolicy(AuthPolicy.SenderOrReceiver, policy => policy.RequireRole(Role.Sender, Role.Receiver.Full))
|
||||
|
||||
.AddPolicy(AuthPolicy.Sender, policy => policy.RequireRole(Role.Sender))
|
||||
|
||||
.AddPolicy(AuthPolicy.Sender, policy => policy
|
||||
.RequireRole(Role.Sender)
|
||||
.AddAuthenticationSchemes(AuthScheme.Sender))
|
||||
.AddPolicy(AuthPolicy.Receiver, policy => policy
|
||||
.AddAuthenticationSchemes(AuthScheme.Receiver)
|
||||
.RequireAuthenticatedUser()
|
||||
.RequireRole(Role.Receiver.Full, "receiver"))
|
||||
|
||||
.AddPolicy(AuthPolicy.ReceiverTFA, policy => policy.RequireRole(Role.Receiver.TFA));
|
||||
|
||||
// User manager
|
||||
|
||||
Reference in New Issue
Block a user