diff options
| author | transtrike <transtrike@gmail.com> | 2020-12-12 15:04:45 +0200 |
|---|---|---|
| committer | transtrike <transtrike@gmail.com> | 2020-12-12 15:04:45 +0200 |
| commit | 8bd7295dc4694c1c0ed6fbc05d390223bfc4ef05 (patch) | |
| tree | 380757557eb7ac15809e5f04d224c2e494a327fd /API/Extensions | |
| parent | 29b2a82d7ef2613b3e56eba7ed959243a98ae92d (diff) | |
| download | DevHive-8bd7295dc4694c1c0ed6fbc05d390223bfc4ef05.tar DevHive-8bd7295dc4694c1c0ed6fbc05d390223bfc4ef05.tar.gz DevHive-8bd7295dc4694c1c0ed6fbc05d390223bfc4ef05.zip | |
Added Extensions Methods
Diffstat (limited to 'API/Extensions')
| -rw-r--r-- | API/Extensions/ConfigureDatabase.cs | 42 | ||||
| -rw-r--r-- | API/Extensions/ConfigureJWT.cs | 21 | ||||
| -rw-r--r-- | API/Extensions/ConfigureSwagger.cs | 23 |
3 files changed, 86 insertions, 0 deletions
diff --git a/API/Extensions/ConfigureDatabase.cs b/API/Extensions/ConfigureDatabase.cs new file mode 100644 index 0000000..57560e2 --- /dev/null +++ b/API/Extensions/ConfigureDatabase.cs @@ -0,0 +1,42 @@ +using Microsoft.Extensions.DependencyInjection; +using API.Database; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Data.Models.Classes; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Builder; + +namespace API.Extensions +{ + public static class DatabaseExtensions + { + public static void DatabaseConfiguration(this IServiceCollection services, IConfiguration configuration) + { + services.AddDbContext<DevHiveContext>(options => + options.UseNpgsql(configuration.GetConnectionString("DEV"))) + .AddAuthentication() + .AddJwtBearer(); + + services.AddIdentity<User, Roles>() + .AddEntityFrameworkStores<DevHiveContext>(); + + services.AddAuthentication(); + + services.Configure<IdentityOptions>(options => + { + options.User.RequireUniqueEmail = true; + + options.Password.RequiredLength = 5; + }); + } + + public static void UseDatabaseConfiguration(this IApplicationBuilder app) + { + app.UseHttpsRedirection(); + app.UseRouting(); + + app.UseAuthentication(); + app.UseAuthorization(); + } + } +}
\ No newline at end of file diff --git a/API/Extensions/ConfigureJWT.cs b/API/Extensions/ConfigureJWT.cs new file mode 100644 index 0000000..f5862f5 --- /dev/null +++ b/API/Extensions/ConfigureJWT.cs @@ -0,0 +1,21 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.OpenApi.Models; + +namespace API.Extensions +{ + public static class JWTExtensions + { + public static void JWTConfiguration(this IServiceCollection services) + { + + } + + public static void UseJWTConfiguration(this IApplicationBuilder app) + { + + + + } + } +}
\ No newline at end of file diff --git a/API/Extensions/ConfigureSwagger.cs b/API/Extensions/ConfigureSwagger.cs new file mode 100644 index 0000000..249eca0 --- /dev/null +++ b/API/Extensions/ConfigureSwagger.cs @@ -0,0 +1,23 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.OpenApi.Models; + +namespace API.Extensions +{ + public static class SwaggerExtensions + { + public static void SwaggerConfiguration(this IServiceCollection services) + { + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "API", Version = "v1" }); + }); + } + + public static void UseSwaggerConfiguration(this IApplicationBuilder app) + { + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1")); + } + } +}
\ No newline at end of file |
