Changeset dced479 for iknow-api


Ignore:
Timestamp:
09/14/26 21:15:01 (9 days ago)
Author:
Stefan-Saveski <stefansaveski19@…>
Branches:
master
Children:
93c368a
Parents:
ff7f308 (diff), ce1f8d4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge remote-tracking branch 'origin/Dev'

# Conflicts:
# iknow-api/Controllers/AuthController.cs
# iknow-api/DTOs/RefreshTokenDTO.cs
# iknow-api/DTOs/UserDTO.cs
# iknow-api/Data/AppDbContext.cs
# iknow-api/Migrations/AppDbContextModelSnapshot.cs
# iknow-api/Models/RefreshToken.cs
# iknow-api/Models/User.cs
# iknow-api/Program.cs
# iknow-api/Repository/Implementations/UserRepository.cs
# iknow-api/Repository/Interface/IUserRepository.cs
# iknow-api/Services/Implementations/AuthService.cs
# iknow-api/Services/Interfaces/IAuthService.cs
# iknow-api/appsettings.Development.json
# iknow-api/appsettings.json

Location:
iknow-api
Files:
31 added
2 edited

Legend:

Unmodified
Added
Removed
  • iknow-api/Program.cs

    rff7f308 rdced479  
     1using System.Text;
     2using System.Text.Json.Serialization;
     3using iknow_api.Data;
     4using iknow_api.Repositories;
     5using iknow_api.Services;
     6using Microsoft.AspNetCore.Authentication.JwtBearer;
     7using Microsoft.EntityFrameworkCore;
     8using Microsoft.IdentityModel.Tokens;
     9
    110var builder = WebApplication.CreateBuilder(args);
    211
     12// Add CORS policy
     13builder.Services.AddCors(options =>
     14{
     15    options.AddPolicy("AllowFrontend", policy =>
     16    {
     17        var allowedOrigins = builder.Configuration.GetSection("AllowedOrigins").Get<string[]>()
     18            ?? new[] { "http://localhost:3000" };
     19       
     20        policy.WithOrigins(allowedOrigins) // Your frontend URL(s)
     21              .AllowAnyHeader()
     22              .AllowAnyMethod()
     23              .AllowCredentials();
     24    });
     25});
     26
     27builder.Services.AddAuthentication(options =>
     28{
     29    options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
     30    options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
     31})
     32.AddJwtBearer(options =>
     33{
     34    options.RequireHttpsMetadata = false; // only for development
     35    options.SaveToken = true;
     36    options.TokenValidationParameters = new TokenValidationParameters
     37    {
     38        ValidateIssuer = true,
     39        ValidIssuer = "iknow-api",
     40
     41        ValidateAudience = true,
     42        ValidAudience = "iknow-api",
     43
     44        ValidateLifetime = true,
     45
     46        ValidateIssuerSigningKey = true,
     47        IssuerSigningKey = new SymmetricSecurityKey(
     48            Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"]))
     49    };
     50});
    351// Add services to the container.
    4 
    5 builder.Services.AddControllers();
    6 // Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
     52builder.Services.AddControllers()
     53    .AddJsonOptions(options =>
     54    {
     55        options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
     56        options.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
     57        options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
     58    });
    759builder.Services.AddOpenApi();
    860
     61// Register DbContext
     62builder.Services.AddDbContext<AppDbContext>(options =>
     63    options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
     64
     65// Register your services
     66builder.Services.AddScoped<IAuthService, AuthService>();
     67builder.Services.AddScoped<IUserRepository, UserRepository>(); // You'll need to add the UserRepository implementation
     68builder.Services.AddScoped<IUserService, UserService>();
     69
     70builder.Services.AddScoped<IRefreshTokenService, RefreshTokenService>();
     71builder.Services.AddScoped<IUserRepository, UserRepository>();
     72builder.Services.AddScoped<IRefreshTokenRepository, RefreshTokenRepository>();
     73builder.Services.AddAuthorization();
    974var app = builder.Build();
    1075
     
    1580}
    1681
     82// Enable CORS - must be called before UseAuthentication and UseAuthorization
     83app.UseCors("AllowFrontend");
     84
    1785app.UseHttpsRedirection();
    18 
     86app.UseAuthentication(); // <-- must come BEFORE UseAuthorization
    1987app.UseAuthorization();
    20 
    2188app.MapControllers();
    2289
  • iknow-api/appsettings.json

    rff7f308 rdced479  
    66    }
    77  },
    8   "AllowedHosts": "*"
     8  "AllowedOrigins": [
     9    "http://localhost:3000",
     10    "https://iknow-remaster.vercel.app"
     11  ],
     12  "ConnectionStrings": {
     13    "DefaultConnection": "Host=ep-divine-term-aghfotgc-pooler.c-2.eu-central-1.aws.neon.tech; Database=neondb; Username=neondb_owner; Password=REDACTED_ROTATE_ME; SSL Mode=VerifyFull; Channel Binding=Require;"
     14  },
     15  "Jwt": {
     16    "Key": "REDACTED_SET_VIA_USER_SECRETS"
     17  }
    918}
Note: See TracChangeset for help on using the changeset viewer.