Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(migrations):fix migrations #77

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions AnalysisData/AnalysisData/Authorization.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Text;
using AnalysisData.Repository.RoleRepository.Abstraction;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.IdentityModel.Tokens;

namespace AnalysisData;
Expand All @@ -14,7 +15,7 @@ public Authorization(IRoleRepository roleRepository)
_roleRepository = roleRepository;
}

public async Task ConfigureServices(IServiceCollection services)
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
Expand All @@ -25,24 +26,25 @@ public async Task ConfigureServices(IServiceCollection services)
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = "yourIssuer",
ValidAudience = "yourAudience",
ValidIssuer = "",
ValidAudience = "",
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("yourSecretKey"))
};
});

services.AddAuthorization();
}

public async Task InitializeRolesAsync(IServiceProvider serviceProvider)
{
var goldRoles = await _roleRepository.GetRolesByPolicyAsync("Gold");
var silverRoles = await _roleRepository.GetRolesByPolicyAsync("Silver");
var bronzeRoles = await _roleRepository.GetRolesByPolicyAsync("Bronze");
services.AddAuthorization(options =>
{
options.AddPolicy("gold", policy =>
policy.RequireRole(goldRoles.ToArray()));
options.AddPolicy("silver", policy =>
policy.RequireRole(silverRoles.ToArray()));

options.AddPolicy("bronze", policy =>
policy.RequireRole(bronzeRoles.ToArray()));
});

var authorizationOptions = serviceProvider.GetRequiredService<AuthorizationOptions>();

authorizationOptions.AddPolicy("gold", policy => policy.RequireRole(goldRoles.ToArray()));
authorizationOptions.AddPolicy("silver", policy => policy.RequireRole(silverRoles.ToArray()));
authorizationOptions.AddPolicy("bronze", policy => policy.RequireRole(bronzeRoles.ToArray()));
}
}
Loading
Loading