mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
AuthController work
This commit is contained in:
+38
-5
@@ -1,16 +1,41 @@
|
||||
using Govor.API.Services;
|
||||
using Govor.API.Services.Authentication;
|
||||
using Govor.Core.Infrastructure.Extensions;
|
||||
using Govor.Core.Infrastructure.Validators;
|
||||
using Govor.Core.Models;
|
||||
using Govor.Core.Repositories;
|
||||
using Govor.Core.Repositories.Users;
|
||||
using Govor.Core.Services;
|
||||
using Govor.Data;
|
||||
using Govor.Data.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
var configuration = builder.Configuration;
|
||||
var services = builder.Services;
|
||||
|
||||
builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
||||
builder.Services.Configure<JwtOption>(configuration.GetSection(nameof(JwtOption)));
|
||||
|
||||
// Add services
|
||||
|
||||
builder.Services.AddSignalR();
|
||||
|
||||
builder.Services.AddAuthorization();
|
||||
builder.Services.AddAuthentication("Bearer")
|
||||
.AddJwtBearer();
|
||||
|
||||
|
||||
builder.Services.AddControllers();
|
||||
|
||||
builder.Services.AddScoped<IPasswordHasher, PasswordHasher>();
|
||||
builder.Services.AddScoped<IJwtService, JwtService>();
|
||||
builder.Services.AddScoped<IAccountService, AuthService>();
|
||||
builder.Services.AddScoped<IUsersRepository, UsersRepository>();
|
||||
builder.Services.AddScoped<IObjectValidator<User>, UserValidator>();
|
||||
|
||||
builder.Services.AddDbContext<GovorDbContext>(
|
||||
options =>
|
||||
{
|
||||
@@ -19,22 +44,30 @@ builder.Services.AddDbContext<GovorDbContext>(
|
||||
);
|
||||
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddOpenApi();
|
||||
|
||||
builder.Services.AddAuthorization();
|
||||
builder.Services.AddSwaggerGen();
|
||||
//builder.Services.AddOpenApi();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.MapOpenApi();
|
||||
//app.MapOpenApi();
|
||||
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Map("/hello", [Authorize]() => "Hello World!");
|
||||
app.Map("/", () => "Not for browser");
|
||||
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user