This commit is contained in:
Landon Pierce 2022-03-30 18:46:09 -04:00
Родитель 0c024d1a85
Коммит c864bcaf19
13 изменённых файлов: 264 добавлений и 0 удалений

Просмотреть файл

@ -28,6 +28,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Saas.Application.Web", "src
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Saas.AspNetCore.Authorization", "src\Saas.Authorization\Saas.AspNetCore.Authorization\Saas.AspNetCore.Authorization.csproj", "{6B9F75FC-4739-4CA1-9347-2F4092A794B1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Saas.Permissions.Api", "src\Saas.Permissions\Saas.Permissions.Api\Saas.Permissions.Api.csproj", "{E8F9B31E-E2E7-45F7-AE9B-68409630C82E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -74,6 +76,10 @@ Global
{6B9F75FC-4739-4CA1-9347-2F4092A794B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B9F75FC-4739-4CA1-9347-2F4092A794B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B9F75FC-4739-4CA1-9347-2F4092A794B1}.Release|Any CPU.Build.0 = Release|Any CPU
{E8F9B31E-E2E7-45F7-AE9B-68409630C82E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E8F9B31E-E2E7-45F7-AE9B-68409630C82E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E8F9B31E-E2E7-45F7-AE9B-68409630C82E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E8F9B31E-E2E7-45F7-AE9B-68409630C82E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Просмотреть файл

@ -0,0 +1,23 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Saas.Permissions.Api.Models;
using System.Text.Json;
namespace Saas.Permissions.Api.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class CustomClaimsController : ControllerBase
{
[HttpPost]
public IActionResult GetCustomClaims(ADB2CRequest aDB2CRequest)
{
var responseContent = new ResponseContent()
{
extension_CustomClaim = "9183cdfa-c406-42cb-9e86-dee61ca2a324.Admin"
};
return Ok(responseContent);
}
}
}

Просмотреть файл

@ -0,0 +1,11 @@
namespace Saas.Permissions.Api.Data
{
public class Permission
{
public int Id { get; set; }
public Guid UserId { get; set; }
public string TenantId { get; set; }
public string Role { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,14 @@
namespace Saas.Permissions.Api.Data
{
public class PermissionsContext : DbContext
{
public PermissionsContext(DbContextOptions<PermissionsContext> options)
: base(options)
{
}
public DbSet<Permission> Permissions { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,47 @@
namespace Saas.Permissions.Api.Data;
public static class PermissionsDbInitializer
{
public static void ConfigureDatabase(this IHost host)
{
using IServiceScope scope = host.Services.CreateScope();
ILogger logger = scope.ServiceProvider.GetRequiredService<ILogger<PermissionsContext>>();
PermissionsContext permissionsContext = scope.ServiceProvider.GetRequiredService<PermissionsContext>();
CreateDatabase(permissionsContext, logger);
SeedDatabase(permissionsContext, logger);
}
private static void CreateDatabase(PermissionsContext permissionsContext, ILogger logger)
{
try
{
permissionsContext.Database.EnsureCreated();
}
catch (Exception ex)
{
logger.LogCritical(ex, "Unable to create the database");
throw;
}
}
private static void SeedDatabase(PermissionsContext permissionsContext, ILogger logger)
{
try
{
if (permissionsContext.Permissions.Any())
{
return; // DB has been seeded
}
//Add any code required to seed the database here
}
catch (Exception ex)
{
logger.LogCritical(ex, "Error while seeding the database");
throw;
}
}
}

Просмотреть файл

@ -0,0 +1,8 @@
namespace Saas.Permissions.Api.Models
{
public class ADB2CRequest
{
public string Email { get; set; }
public string ObjectId { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,52 @@
using System.Text.Json.Serialization;
namespace Saas.Permissions.Api.Models
{
public class ResponseContent
{
public const string ApiVersion = "1.0.0";
public ResponseContent()
{
this.version = ResponseContent.ApiVersion;
this.action = "Continue";
}
public ResponseContent(string action, string userMessage)
{
this.version = ResponseContent.ApiVersion;
this.action = action;
this.userMessage = userMessage;
if (action == "ValidationError")
{
this.status = "400";
}
}
public string version { get; }
public string action { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string userMessage { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string status { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string jobTitle { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public List<string> roles { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string extension_CustomClaim { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string scp { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,33 @@
using Saas.Permissions.Api.Data;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddDbContext<PermissionsContext>(options =>
{
options.UseSqlServer(builder.Configuration.GetConnectionString("PermissionsContext"));
});
var app = builder.Build();
app.ConfigureDatabase();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

Просмотреть файл

@ -0,0 +1,31 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:6069",
"sslPort": 44307
}
},
"profiles": {
"Saas.Permissions.Api": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7023;http://localhost:5023",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

Просмотреть файл

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
</Project>

Просмотреть файл

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

Просмотреть файл

@ -0,0 +1,12 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"PermissionsContext": "Server=(localdb)\\mssqllocaldb;Database=Saas.Permissions.Sql;Trusted_Connection=True;MultipleActiveResultSets=true"
}
}

Просмотреть файл

@ -0,0 +1,4 @@
global using Microsoft.AspNetCore.Mvc;
global using Microsoft.EntityFrameworkCore;
global using Microsoft.EntityFrameworkCore.Metadata.Builders;