Skip to content

Commit

Permalink
Try to remove auth
Browse files Browse the repository at this point in the history
  • Loading branch information
pkirilin committed Dec 17, 2023
1 parent 58d5587 commit 391fe2d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace FoodDiary.API.Controllers.v1
{
[ApiController]
[Route("api/v1/products")]
[Authorize(Constants.AuthorizationPolicies.GoogleAllowedEmails)]
// [Authorize(Constants.AuthorizationPolicies.GoogleAllowedEmails)]
[ApiExplorerSettings(GroupName = "v1")]
public class ProductsController : ControllerBase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ public static class AuthExtensions

public static void AddFakeAuthForTests(this IServiceCollection services)
{
services.AddAuthentication(FakeSchemeName)
.AddScheme<FakeAuthenticationHandlerOptions, FakeAuthenticationHandler>(
FakeSchemeName,
"Fake auth for tests",
options => { options.UserEmail = FakeUserEmail; });

services.AddAuthorization(options =>
{
options.AddPolicy(Constants.AuthorizationPolicies.GoogleAllowedEmails, policy =>
{
policy.AddAuthenticationSchemes(FakeSchemeName)
.RequireAuthenticatedUser()
.RequireClaim(Constants.ClaimTypes.Email, FakeUserEmail);
});
});
// services.AddAuthentication(FakeSchemeName)
// .AddScheme<FakeAuthenticationHandlerOptions, FakeAuthenticationHandler>(
// FakeSchemeName,
// "Fake auth for tests",
// options => { options.UserEmail = FakeUserEmail; });
//
// services.AddAuthorization(options =>
// {
// options.AddPolicy(Constants.AuthorizationPolicies.GoogleAllowedEmails, policy =>
// {
// policy.AddAuthenticationSchemes(FakeSchemeName)
// .RequireAuthenticatedUser()
// .RequireClaim(Constants.ClaimTypes.Email, FakeUserEmail);
// });
// });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)
});
}

var dataProtectionOptionsDescriptor = services
.FirstOrDefault(d => d.ServiceType == typeof(IConfigureOptions<KeyManagementOptions>));

if (dataProtectionOptionsDescriptor is not null)
{
services.AddSingleton<IConfigureOptions<KeyManagementOptions>>(_ =>
{
return new ConfigureOptions<KeyManagementOptions>(options =>
{
options.XmlRepository = new FakeDataProtectionRepository();
});
});
}
// var dataProtectionOptionsDescriptor = services
// .FirstOrDefault(d => d.ServiceType == typeof(IConfigureOptions<KeyManagementOptions>));
//
// if (dataProtectionOptionsDescriptor is not null)
// {
// services.AddSingleton<IConfigureOptions<KeyManagementOptions>>(_ =>
// {
// return new ConfigureOptions<KeyManagementOptions>(options =>
// {
// options.XmlRepository = new FakeDataProtectionRepository();
// });
// });
// }

services.AddFakeAuthForTests();
});
Expand All @@ -69,9 +69,9 @@ public async Task InitializeAsync()
var dbContext = scope.ServiceProvider.GetRequiredService<FoodDiaryContext>();
await dbContext.Database.MigrateAsync();

var dataProtectionKeys = await dbContext.DataProtectionKeys.ToListAsync();
// var dataProtectionKeys = await dbContext.DataProtectionKeys.ToListAsync();

Console.WriteLine($"Found {dataProtectionKeys.Count} dataProtectionKeys");
// Console.WriteLine($"Found {dataProtectionKeys.Count} dataProtectionKeys");
}

public new Task DisposeAsync()
Expand Down

0 comments on commit 391fe2d

Please sign in to comment.