-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
41 lines (29 loc) · 1.12 KB
/
Program.cs
File metadata and controls
41 lines (29 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.Security.Claims;
using ApiIdentityEndpoint.Data;
using ApiIdentityEndpoint.Models;
using DotNetEnv;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
Env.Load();
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var connectionString = Env.GetString("CONNECTION_STRING");
builder.Services.AddDbContext<AppDbContext>(options => options.UseSqlServer(connectionString));
builder.Services.AddAuthentication();
builder.Services.AddAuthorization();
builder.Services.AddIdentityApiEndpoints<User>().AddEntityFrameworkStores<AppDbContext>();
var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI();
app.MapSwagger();
app.MapGet("/", () => "Hello World!");
app.MapGet("/.", (ClaimsPrincipal user) => user.Identity!.Name).RequireAuthorization();
app.MapIdentityApi<User>();
app.MapPost("/logout", async (SignInManager<User> signInManager, [FromBody] object empty) =>
{
await signInManager.SignOutAsync();
return Results.Ok();
});
app.Run();