Ignore:
Timestamp:
10/28/25 10:44:31 (11 months ago)
Author:
GitHub <noreply@…>
Branches:
master
Children:
43459e1, ff7f308
Parents:
c11d3a3 (diff), 1e58098 (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.
git-author:
Boris Gjorgjievski <69085722+imbrsk@…> (10/28/25 10:44:31)
git-committer:
GitHub <noreply@…> (10/28/25 10:44:31)
Message:

Merge pull request #3 from stefansaveski/feature/refresh-token

Feature/refresh token

File:
1 edited

Legend:

Unmodified
Added
Removed
  • iknow-api/Program.cs

    rc11d3a3 r7a1fe00  
     1using System.Text;
     2using iknow_api.Data;
     3using iknow_api.Repositories;
     4using iknow_api.Services;
     5using Microsoft.AspNetCore.Authentication.JwtBearer;
     6using Microsoft.EntityFrameworkCore;
     7using Microsoft.IdentityModel.Tokens;
     8
    19var builder = WebApplication.CreateBuilder(args);
     10builder.Services.AddAuthentication(options =>
     11{
     12    options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
     13    options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
     14})
     15.AddJwtBearer(options =>
     16{
     17    options.RequireHttpsMetadata = false; // only for development
     18    options.SaveToken = true;
     19    options.TokenValidationParameters = new TokenValidationParameters
     20    {
     21        ValidateIssuer = true,
     22        ValidIssuer = "iknow-api",
    223
     24        ValidateAudience = true,
     25        ValidAudience = "iknow-api",
     26
     27        ValidateLifetime = true,
     28
     29        ValidateIssuerSigningKey = true,
     30        IssuerSigningKey = new SymmetricSecurityKey(
     31            Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"]))
     32    };
     33});
    334// Add services to the container.
    4 
    535builder.Services.AddControllers();
    6 // Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
    736builder.Services.AddOpenApi();
    837
     38// Register DbContext
     39builder.Services.AddDbContext<AppDbContext>(options =>
     40    options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
     41
     42// Register your services
     43builder.Services.AddScoped<IAuthService, AuthService>();
     44builder.Services.AddScoped<IRefreshTokenService, RefreshTokenService>();
     45builder.Services.AddScoped<IUserRepository, UserRepository>();
     46builder.Services.AddScoped<IRefreshTokenRepository, RefreshTokenRepository>();
     47builder.Services.AddAuthorization();
    948var app = builder.Build();
    1049
     
    1655
    1756app.UseHttpsRedirection();
    18 
     57app.UseAuthentication(); // <-- must come BEFORE UseAuthorization
    1958app.UseAuthorization();
    20 
    2159app.MapControllers();
    2260
Note: See TracChangeset for help on using the changeset viewer.