CI/CD: Add GitLab CI/CD pipeline for Hostinger deployment
- Updated .gitlab-ci.yml with complete build, test, and deploy stages - Added authentication redirect fix in Program.cs (302 redirect for admin routes) - Fixed Cookie vs Bearer authentication conflict for admin panel - Configure pipeline to build from .NET 9.0 source - Deploy to Hostinger VPS with proper environment variables - Include rollback capability for production deployments 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -140,12 +140,33 @@ if (string.IsNullOrEmpty(jwtKey))
|
||||
var jwtIssuer = builder.Configuration["Jwt:Issuer"] ?? "LittleShop";
|
||||
var jwtAudience = builder.Configuration["Jwt:Audience"] ?? "LittleShop";
|
||||
|
||||
builder.Services.AddAuthentication("Cookies")
|
||||
builder.Services.AddAuthentication(options =>
|
||||
{
|
||||
options.DefaultScheme = "Cookies";
|
||||
options.DefaultChallengeScheme = "Cookies";
|
||||
})
|
||||
.AddCookie("Cookies", options =>
|
||||
{
|
||||
options.LoginPath = "/Admin/Account/Login";
|
||||
options.LogoutPath = "/Admin/Account/Logout";
|
||||
options.AccessDeniedPath = "/Admin/Account/AccessDenied";
|
||||
options.Events = new Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationEvents
|
||||
{
|
||||
OnRedirectToLogin = context =>
|
||||
{
|
||||
// For admin routes, always redirect to login page
|
||||
if (context.Request.Path.StartsWithSegments("/Admin"))
|
||||
{
|
||||
context.Response.StatusCode = 302;
|
||||
context.Response.Headers["Location"] = context.RedirectUri;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
// For API routes, return 401
|
||||
context.Response.StatusCode = 401;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
};
|
||||
})
|
||||
.AddJwtBearer("Bearer", options =>
|
||||
{
|
||||
@@ -166,7 +187,7 @@ builder.Services.AddAuthorization(options =>
|
||||
options.AddPolicy("AdminOnly", policy =>
|
||||
policy.RequireAuthenticatedUser()
|
||||
.RequireRole("Admin")
|
||||
.AddAuthenticationSchemes("Cookies", "Bearer")); // Support both cookie and JWT
|
||||
.AddAuthenticationSchemes("Cookies")); // Only use cookies for admin panel
|
||||
options.AddPolicy("ApiAccess", policy =>
|
||||
policy.RequireAuthenticatedUser()
|
||||
.AddAuthenticationSchemes("Bearer")); // JWT only for API access
|
||||
|
||||
Reference in New Issue
Block a user