Skip to content

Commit

Permalink
Add usefull extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
MRmlik12 committed Jan 9, 2022
1 parent f191ca2 commit 3f51463
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 11 deletions.
44 changes: 44 additions & 0 deletions src/Vulder.SharedKernel/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Text;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;

namespace Vulder.SharedKernel;

public static class Extensions
{
public static void AddDefaultJwtConfiguration(this IServiceCollection services, IConfiguration configuration)
{
var authSection = configuration.GetSection("Jwt");
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options =>
{
options.SaveToken = true;
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey =
new SymmetricSecurityKey(Encoding.UTF8.GetBytes(authSection.GetValue<string>("Key"))),
ValidateIssuer = true,
ValidIssuer = authSection.GetValue<string>("Issuer"),
ValidateAudience = true,
ValidAudience = authSection.GetValue<string>("Audience"),
RequireExpirationTime = true,
ValidateLifetime = true
};
});
}

public static void AddDefaultCorsPolicy(this IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy("CORS", corsPolicyBuilder =>
{
corsPolicyBuilder.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});
});
}
}
9 changes: 0 additions & 9 deletions src/Vulder.SharedKernel/Regexes.cs

This file was deleted.

7 changes: 5 additions & 2 deletions src/Vulder.SharedKernel/Vulder.SharedKernel.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MediatR" Version="9.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="MongoDB.Bson" Version="2.12.4" />
</ItemGroup>

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<PackageVersion>0.1.6</PackageVersion>
<Title>Vulder.SharedKernel</Title>
<Authors>MRmlik12</Authors>
Expand Down

0 comments on commit 3f51463

Please sign in to comment.