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

packages update project re-organization: separated authentication and… #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using System.Reflection;

namespace IdentitySample.Authentication;

Expand All @@ -18,33 +19,6 @@ public AuthenticationDbContext(DbContextOptions<AuthenticationDbContext> options
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);

builder.Entity<ApplicationUser>(user =>
{
user.Property(u => u.FirstName).HasMaxLength(256).IsRequired();
user.Property(u => u.LastName).HasMaxLength(256);
});

builder.Entity<ApplicationUserRole>(userRole =>
{
userRole.HasKey(ur => new { ur.UserId, ur.RoleId });

userRole.HasOne(ur => ur.Role)
.WithMany(r => r.UserRoles).HasForeignKey(ur => ur.RoleId).IsRequired();

userRole.HasOne(ur => ur.User)
.WithMany(u => u.UserRoles).HasForeignKey(ur => ur.UserId).IsRequired();
});

builder.Entity<Tenant>(tenant =>
{
tenant.ToTable("Tenants");
tenant.HasKey(t => t.Id);
tenant.Property(t => t.Id).ValueGeneratedOnAdd();

tenant.Property(t => t.ConnectionString).HasMaxLength(4000).IsRequired().IsUnicode(false);
tenant.Property(t => t.StorageConnectionString).HasMaxLength(4000).IsUnicode(false);
tenant.Property(t => t.ContainerName).HasMaxLength(256).IsUnicode(false);
});
builder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using IdentitySample.Authentication.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace IdentitySample.Authentication.Configurations;

public class ApplicationUserConfiguration : IEntityTypeConfiguration<ApplicationUser>
{
public void Configure(EntityTypeBuilder<ApplicationUser> builder)
{
builder.Property(u => u.FirstName).HasMaxLength(256).IsRequired();
builder.Property(u => u.LastName).HasMaxLength(256);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using IdentitySample.Authentication.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace IdentitySample.Authentication.Configurations;

public class ApplicationUserRoleConfiguration : IEntityTypeConfiguration<ApplicationUserRole>
{
public void Configure(EntityTypeBuilder<ApplicationUserRole> builder)
{
builder.HasKey(ur => new { ur.UserId, ur.RoleId });

builder.HasOne(ur => ur.Role)
.WithMany(r => r.UserRoles).HasForeignKey(ur => ur.RoleId).IsRequired();

builder.HasOne(ur => ur.User)
.WithMany(u => u.UserRoles).HasForeignKey(ur => ur.UserId).IsRequired();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using IdentitySample.Authentication.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace IdentitySample.Authentication.Configurations;

public class TenantConfiguration : IEntityTypeConfiguration<Tenant>
{
public void Configure(EntityTypeBuilder<Tenant> builder)
{
builder.ToTable("Tenants");
builder.HasKey(t => t.Id);
builder.Property(t => t.Id).ValueGeneratedOnAdd();

builder.Property(t => t.ConnectionString).HasMaxLength(4000).IsRequired().IsUnicode(false);
builder.Property(t => t.StorageConnectionString).HasMaxLength(4000).IsUnicode(false);
builder.Property(t => t.ContainerName).HasMaxLength(256).IsUnicode(false);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="6.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="6.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.10" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace IdentitySample.BusinessLayer.Settings;
namespace IdentitySample.Authentication.Settings;

public class JwtSettings
{
Expand All @@ -11,4 +11,4 @@ public class JwtSettings
public int AccessTokenExpirationMinutes { get; init; }

public int RefreshTokenExpirationMinutes { get; init; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.AspNetCore.Authorization;

namespace IdentitySample.Authorization.Filters;

public class RoleAuthorizeAttribute : AuthorizeAttribute
{
public RoleAuthorizeAttribute(params string[] roles)
{
Roles = string.Join(",", roles);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Authorization;
using IdentitySample.Authentication;
using IdentitySample.Authorization.Requirements;
using Microsoft.AspNetCore.Authorization;

namespace IdentitySample.Authentication.Requirements;
namespace IdentitySample.Authorization.Handlers;

public class MinimumAgeHandler : AuthorizationHandler<MinimumAgeRequirement>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System.Security.Claims;
using IdentitySample.Authentication.Entities;
using IdentitySample.Authentication.Entities;
using IdentitySample.Authentication.Extensions;
using IdentitySample.Authorization.Requirements;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using System.Security.Claims;

namespace IdentitySample.Authentication.Requirements;
namespace IdentitySample.Authorization.Handlers;

public class UserActiveHandler : AuthorizationHandler<UserActiveRequirement>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="6.0.10" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\IdentitySample.Authentication\IdentitySample.Authentication.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Authorization;

namespace IdentitySample.Authentication.Requirements;
namespace IdentitySample.Authorization.Requirements;

public class MinimumAgeRequirement : IAuthorizationRequirement
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Authorization;

namespace IdentitySample.Authentication.Requirements;
namespace IdentitySample.Authorization.Requirements;

public class UserActiveRequirement : IAuthorizationRequirement
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.22.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.24.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Security.Cryptography;
using System.Text;
using IdentitySample.Authentication;
using IdentitySample.Authentication;
using IdentitySample.Authentication.Entities;
using IdentitySample.Authentication.Extensions;
using IdentitySample.BusinessLayer.Settings;
using IdentitySample.Authentication.Settings;
using IdentitySample.Contracts;
using IdentitySample.Shared.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Security.Cryptography;
using System.Text;

namespace IdentitySample.BusinessLayer.Services;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.10" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.13.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.14.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="MimeMapping" Version="1.0.1.37" />
</ItemGroup>
Expand Down
8 changes: 7 additions & 1 deletion IdentitySample/IdentitySample.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentitySample.DataAccessLa
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentitySample.Contracts", "IdentitySample.Contracts\IdentitySample.Contracts.csproj", "{F01DED0D-AE45-444C-B419-7346CDD6890B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdentitySample.StorageProviders", "IdentitySample.StorageProviders\IdentitySample.StorageProviders.csproj", "{A7CA3DBA-96B5-458F-ADB8-D88A18D06B70}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentitySample.StorageProviders", "IdentitySample.StorageProviders\IdentitySample.StorageProviders.csproj", "{A7CA3DBA-96B5-458F-ADB8-D88A18D06B70}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdentitySample.Authorization", "IdentitySample.Authorization\IdentitySample.Authorization.csproj", "{427D3DE5-C6BD-4F4B-A2FE-3FB33F278713}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -69,6 +71,10 @@ Global
{A7CA3DBA-96B5-458F-ADB8-D88A18D06B70}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A7CA3DBA-96B5-458F-ADB8-D88A18D06B70}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A7CA3DBA-96B5-458F-ADB8-D88A18D06B70}.Release|Any CPU.Build.0 = Release|Any CPU
{427D3DE5-C6BD-4F4B-A2FE-3FB33F278713}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{427D3DE5-C6BD-4F4B-A2FE-3FB33F278713}.Debug|Any CPU.Build.0 = Debug|Any CPU
{427D3DE5-C6BD-4F4B-A2FE-3FB33F278713}.Release|Any CPU.ActiveCfg = Release|Any CPU
{427D3DE5-C6BD-4F4B-A2FE-3FB33F278713}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 3 additions & 2 deletions IdentitySample/IdentitySample/IdentitySample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.10" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\IdentitySample.Authorization\IdentitySample.Authorization.csproj" />
<ProjectReference Include="..\IdentitySample.BusinessLayer\IdentitySample.BusinessLayer.csproj" />
<ProjectReference Include="..\IdentitySample.StorageProviders\IdentitySample.StorageProviders.csproj" />
</ItemGroup>
Expand Down
9 changes: 5 additions & 4 deletions IdentitySample/IdentitySample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System.Reflection;
using System.Text;
using IdentitySample.Authentication;
using IdentitySample.Authentication.Entities;
using IdentitySample.Authentication.Requirements;
using IdentitySample.Authentication.Settings;
using IdentitySample.Authorization.Handlers;
using IdentitySample.Authorization.Requirements;
using IdentitySample.BusinessLayer.Services;
using IdentitySample.BusinessLayer.Settings;
using IdentitySample.Contracts;
using IdentitySample.DataAccessLayer;
using IdentitySample.Services;
Expand All @@ -17,6 +16,8 @@
using Microsoft.IdentityModel.Tokens;
using Microsoft.Net.Http.Headers;
using Microsoft.OpenApi.Models;
using System.Reflection;
using System.Text;

var builder = WebApplication.CreateBuilder(args);
ConfigureServices(builder.Services, builder.Configuration);
Expand Down