-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
63 lines (54 loc) · 2 KB
/
Program.cs
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using RemoteMultiSiteMobileBasedExpenseManager.SqlServer;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Cors;
using System.Text;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using RemoteMultiSiteMobileBasedExpenseManager.Repositories;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
var connectionString = builder.Configuration.GetConnectionString("ConRemoteMultiSiteExpenseManager");
builder.Services.AddControllers();
builder.Services.AddDbContext<DbContextEntities>(opt => opt.UseSqlServer(connectionString));
builder.Services.AddCors(x => {
x.AddPolicy("ExpenseCors", p =>
{
p.WithOrigins("https://localhost:7103")
.AllowAnyHeader()
.AllowAnyMethod()
.AllowAnyOrigin();
});
});
builder.Services.AddCors(cors => {
cors.AddDefaultPolicy(p => {
p.WithOrigins("https://localhost:7103")
.AllowAnyHeader()
.AllowAnyMethod()
.AllowAnyOrigin();
});
});
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => {
options.TokenValidationParameters = new TokenValidationParameters()
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidIssuer = builder.Configuration["Jwt:Issuer"],
ValidAudience = builder.Configuration["Jwt:Audience"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"])),
};
});
builder.Services.AddScoped<IProjectsRepository, ProjectsDbRepository>();
builder.Services.AddScoped<IUserRepository, UserRepository>();
//builder.Services.AddAuthorization(options => {
// options.AddPolicy("Umar", o => o.RequireRole("Admin"));
//});
var app = builder.Build();
// Configure the HTTP request pipeline.
app.UseHttpsRedirection();
app.UseCors();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();