Обходной лист (#12)
Co-authored-by: gorbenko.pavel <gorbenko.pavel@tansu.kz> Reviewed-on: http://git.tnsu.kz/gorbenko.pavel/tnsu-approval-route/pulls/12
This commit was merged in pull request #12.
This commit is contained in:
@@ -20,11 +20,11 @@ public static class AuthSetup
|
||||
var tenantId = configuration["Entra:TenantId"];
|
||||
var audience = configuration["Entra:Audience"];
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(tenantId) && !string.IsNullOrWhiteSpace(audience))
|
||||
AddEntraAuth(services, configuration, tenantId, audience);
|
||||
else
|
||||
AddDevAuth(services);
|
||||
if (string.IsNullOrWhiteSpace(tenantId) || string.IsNullOrWhiteSpace(audience))
|
||||
throw new InvalidOperationException(
|
||||
"Entra:TenantId и Entra:Audience обязательны — локального Dev-режима без них больше нет.");
|
||||
|
||||
AddEntraAuth(services, configuration, tenantId, audience);
|
||||
return services;
|
||||
}
|
||||
|
||||
@@ -125,26 +125,4 @@ public static class AuthSetup
|
||||
options.DefaultPolicy = options.GetPolicy(AuthPolicies.Any)!;
|
||||
});
|
||||
}
|
||||
|
||||
private static void AddDevAuth(IServiceCollection services)
|
||||
{
|
||||
services.AddAuthentication(AuthSchemes.Dev)
|
||||
.AddScheme<AuthenticationSchemeOptions, DevAuthHandler>(AuthSchemes.Dev, _ => { });
|
||||
|
||||
// Те же имена политик, но поверх Dev-схемы: иначе контроллер с
|
||||
// [Authorize(Policy = ...)] падал бы локально с «политика не найдена».
|
||||
services.AddAuthorization(options =>
|
||||
{
|
||||
foreach (var name in new[] { AuthPolicies.Delegated, AuthPolicies.AppOnly, AuthPolicies.Any })
|
||||
{
|
||||
options.AddPolicy(name, policy =>
|
||||
{
|
||||
policy.AuthenticationSchemes.Add(AuthSchemes.Dev);
|
||||
policy.RequireAuthenticatedUser();
|
||||
});
|
||||
}
|
||||
|
||||
options.DefaultPolicy = options.GetPolicy(AuthPolicies.Any)!;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user