-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into Feat/StartPlanningWithTDD
- Loading branch information
Showing
105 changed files
with
3,278 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"sdk": { | ||
"version": "7.0.306" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...Service.AuthSecurity/Browl.Service.AuthSecurity.API/Browl.Service.AuthSecurity.API.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.10" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.10" /> | ||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.9" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.10" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.10" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.10" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="7.0" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" /> | ||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.32.3" /> | ||
</ItemGroup> | ||
|
||
</Project> |
43 changes: 43 additions & 0 deletions
43
...ices/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Configuration/ApiConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
namespace Browl.Service.AuthSecurity.API.Configuration; | ||
|
||
public static class ApiConfig | ||
{ | ||
public static IServiceCollection AddApiConfiguration(this IServiceCollection services, IWebHostEnvironment hostEnvironment) | ||
{ | ||
_ = services.AddControllers(); | ||
|
||
IConfigurationBuilder builder = new ConfigurationBuilder() | ||
.SetBasePath(hostEnvironment.ContentRootPath) | ||
.AddJsonFile("appsettings.json", true, true) | ||
.AddJsonFile($"appsettings.{hostEnvironment.EnvironmentName}.json", true, true) | ||
.AddEnvironmentVariables(); | ||
|
||
if (hostEnvironment.IsDevelopment()) | ||
{ | ||
_ = builder.AddUserSecrets<Program>(); | ||
} | ||
|
||
return services; | ||
} | ||
|
||
public static IApplicationBuilder UseApiConfiguration(this IApplicationBuilder app, IWebHostEnvironment env) | ||
{ | ||
if (env.IsDevelopment()) | ||
{ | ||
IApplicationBuilder unused5 = app.UseDeveloperExceptionPage(); | ||
} | ||
|
||
IApplicationBuilder unused4 = app.UseHttpsRedirection(); | ||
|
||
IApplicationBuilder unused3 = app.UseRouting(); | ||
|
||
IApplicationBuilder unused2 = app.UseIdentityConfiguration(); | ||
|
||
IApplicationBuilder unused1 = app.UseEndpoints(endpoints => | ||
{ | ||
ControllerActionEndpointConventionBuilder unused = endpoints.MapControllers(); | ||
}); | ||
|
||
return app; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Configuration/DatabaseConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Browl.Service.AuthSecurity.API.Data; | ||
using Browl.Service.AuthSecurity.Domain.Entities; | ||
|
||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Browl.Service.AuthSecurity.API.Configuration; | ||
|
||
public static class DatabaseConfig | ||
{ | ||
|
||
public static IServiceCollection AddDatabaseConfiguration(this IServiceCollection services, IConfiguration configuration) | ||
{ | ||
services.AddDbContext<BrowlAuthSecurityDbContext>(options => options.UseSqlServer(configuration.GetConnectionString("DefaultConnection"))); | ||
|
||
services.AddIdentity<User, IdentityRole>() | ||
.AddEntityFrameworkStores<BrowlAuthSecurityDbContext>() | ||
.AddDefaultUI() | ||
.AddDefaultTokenProviders(); | ||
|
||
return services; | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
...Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Configuration/IdentityConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using Browl.Service.AuthSecurity.API.Data; | ||
using Browl.Service.AuthSecurity.API.Entities; | ||
|
||
using Microsoft.AspNetCore.Authentication.JwtBearer; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.IdentityModel.Tokens; | ||
|
||
using System.Text; | ||
|
||
namespace Browl.Service.AuthSecurity.API.Configuration; | ||
|
||
public static class IdentityConfig | ||
{ | ||
public static IServiceCollection AddIdentityConfiguration(this IServiceCollection services, | ||
IConfiguration configuration) | ||
{ | ||
IServiceCollection unused3 = services.AddDbContext<BrowlAuthSecurityDbContext>(options => | ||
options.UseSqlServer(configuration.GetConnectionString("DefaultConnection"))); | ||
|
||
IdentityBuilder unused2 = services.AddDefaultIdentity<IdentityUser>() | ||
.AddRoles<IdentityRole>() | ||
.AddEntityFrameworkStores<BrowlAuthSecurityDbContext>() | ||
.AddDefaultTokenProviders(); | ||
|
||
// JWT | ||
|
||
IConfigurationSection appSettingsSection = configuration.GetSection("AppSettings"); | ||
IServiceCollection unused1 = services.Configure<AppSettings>(appSettingsSection); | ||
|
||
AppSettings? appSettings = appSettingsSection.Get<AppSettings>(); | ||
byte[] key = Encoding.ASCII.GetBytes(appSettings.Secret); | ||
|
||
Microsoft.AspNetCore.Authentication.AuthenticationBuilder unused = services.AddAuthentication(options => | ||
{ | ||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; | ||
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; | ||
}).AddJwtBearer(bearerOptions => | ||
{ | ||
bearerOptions.RequireHttpsMetadata = true; | ||
bearerOptions.SaveToken = true; | ||
bearerOptions.TokenValidationParameters = new TokenValidationParameters | ||
{ | ||
ValidateIssuerSigningKey = true, | ||
IssuerSigningKey = new SymmetricSecurityKey(key), | ||
ValidateIssuer = true, | ||
ValidateAudience = true, | ||
ValidAudience = appSettings.ValidOn, | ||
ValidIssuer = appSettings.Issuer | ||
}; | ||
}); | ||
|
||
return services; | ||
} | ||
|
||
|
||
|
||
public static IServiceCollection AddJWConfiguration(this IServiceCollection services, IConfiguration configuration) | ||
{ | ||
services.AddAuthentication(x => | ||
{ | ||
x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; | ||
x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; | ||
}).AddJwtBearer(o => | ||
{ | ||
var Key = Encoding.UTF8.GetBytes(configuration["JWT:Key"]); | ||
o.SaveToken = true; | ||
o.TokenValidationParameters = new TokenValidationParameters | ||
{ | ||
ValidateIssuer = false, | ||
ValidateAudience = false, | ||
ValidateLifetime = true, | ||
ValidateIssuerSigningKey = true, | ||
ValidIssuer = configuration["JWT:Issuer"], | ||
ValidAudience = configuration["JWT:Audience"], | ||
IssuerSigningKey = new SymmetricSecurityKey(Key) | ||
}; | ||
}); | ||
|
||
return services; | ||
} | ||
|
||
public static IApplicationBuilder UseIdentityConfiguration(this IApplicationBuilder app) | ||
{ | ||
_ = app.UseAuthentication(); | ||
_ = app.UseAuthorization(); | ||
|
||
return app; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
.../Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Configuration/SwaggerConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Microsoft.OpenApi.Models; | ||
|
||
namespace Browl.Service.AuthSecurity.API.Configuration; | ||
|
||
public static class SwaggerConfig | ||
{ | ||
public static IServiceCollection AddSwaggerConfiguration(this IServiceCollection services) | ||
{ | ||
IServiceCollection unused = services.AddSwaggerGen(c => | ||
{ | ||
c.SwaggerDoc("v1", new OpenApiInfo() | ||
{ | ||
Title = "Browl Service AuthSecurity API", | ||
Description = "This API guarantees the security and proper authentication of users in the application.", | ||
Contact = new OpenApiContact() { Name = "Rondinele Guimarães", Email = "[email protected]" }, | ||
License = new OpenApiLicense() { Name = "MIT", Url = new Uri("https://opensource.org/licenses/MIT") } | ||
}); | ||
}); | ||
|
||
return services; | ||
} | ||
|
||
public static IApplicationBuilder UseSwaggerConfiguration(this IApplicationBuilder app) | ||
{ | ||
IApplicationBuilder unused1 = app.UseSwagger(); | ||
IApplicationBuilder unused = app.UseSwaggerUI(c => | ||
{ | ||
c.SwaggerEndpoint("/swagger/v1/swagger.json", "v1"); | ||
}); | ||
|
||
return app; | ||
} | ||
} |
Oops, something went wrong.