Добавлено управление сессиями
This commit is contained in:
@@ -35,6 +35,22 @@ public class Program
|
||||
.AddEntityFrameworkStores<ApplicationDbContext>()
|
||||
.AddDefaultTokenProviders();
|
||||
|
||||
// Session
|
||||
builder.Services.AddDistributedSqlServerCache(options =>
|
||||
{
|
||||
options.ConnectionString = builder.Configuration.GetConnectionString("DefaultConnection");
|
||||
options.SchemaName = "dbo";
|
||||
options.TableName = "SessionCache";
|
||||
});
|
||||
|
||||
builder.Services.AddSession(options =>
|
||||
{
|
||||
options.IdleTimeout = TimeSpan.FromDays(30);
|
||||
options.Cookie.HttpOnly = true;
|
||||
options.Cookie.IsEssential = true;
|
||||
options.Cookie.SameSite = SameSiteMode.Lax;
|
||||
});
|
||||
|
||||
// JWT
|
||||
var jwtKey = builder.Configuration["Jwt:Key"] ?? throw new Exception("Jwt:Key missing");
|
||||
builder.Services.AddAuthentication(options =>
|
||||
@@ -70,12 +86,15 @@ public class Program
|
||||
options.SignInScheme = IdentityConstants.ExternalScheme;
|
||||
});
|
||||
|
||||
builder.Services.AddHttpContextAccessor();
|
||||
builder.Services.AddAuthorization();
|
||||
builder.Services.AddAutoMapper(t => t.AddProfile<AppMappingProfile>());
|
||||
builder.Services.AddScoped<JwtService>();
|
||||
builder.Services.AddScoped<UserSessionService>();
|
||||
builder.Services.AddScoped<YandexMusicService>();
|
||||
builder.Services.AddScoped<SharedPlaylistService>();
|
||||
builder.Services.AddScoped<TrackAdditionLogService>();
|
||||
builder.Services.AddScoped<JwtService>();
|
||||
builder.Services.AddScoped<TrackRemovalLogService>();
|
||||
builder.Services.AddDataProtection();
|
||||
|
||||
builder.Services.AddHttpClient();
|
||||
@@ -123,6 +142,7 @@ public class Program
|
||||
app.UseCors("Production");
|
||||
}
|
||||
|
||||
app.UseSession();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user