Changeset ff7f308 for iknow-api/Program.cs
- Timestamp:
- 10/28/25 10:48:10 (11 months ago)
- Branches:
- master
- Children:
- dced479
- Parents:
- 7a1fe00 (diff), 43459e1 (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:48:10)
- git-committer:
- GitHub <noreply@…> (10/28/25 10:48:10)
- File:
-
- 1 edited
-
iknow-api/Program.cs (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
iknow-api/Program.cs
r7a1fe00 rff7f308 1 using System.Text; 2 using iknow_api.Data; 3 using iknow_api.Repositories; 4 using iknow_api.Services; 5 using Microsoft.AspNetCore.Authentication.JwtBearer; 6 using Microsoft.EntityFrameworkCore; 7 using Microsoft.IdentityModel.Tokens; 1 var builder = WebApplication.CreateBuilder(args); 8 2 9 var builder = WebApplication.CreateBuilder(args); 10 builder.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", 3 // Add services to the container. 23 4 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 });34 // Add services to the container.35 5 builder.Services.AddControllers(); 6 // Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi 36 7 builder.Services.AddOpenApi(); 37 8 38 // Register DbContext39 builder.Services.AddDbContext<AppDbContext>(options =>40 options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));41 42 // Register your services43 builder.Services.AddScoped<IAuthService, AuthService>();44 builder.Services.AddScoped<IRefreshTokenService, RefreshTokenService>();45 builder.Services.AddScoped<IUserRepository, UserRepository>();46 builder.Services.AddScoped<IRefreshTokenRepository, RefreshTokenRepository>();47 builder.Services.AddAuthorization();48 9 var app = builder.Build(); 49 10 … … 55 16 56 17 app.UseHttpsRedirection(); 57 app.UseAuthentication(); // <-- must come BEFORE UseAuthorization 18 58 19 app.UseAuthorization(); 20 59 21 app.MapControllers(); 60 22
Note:
See TracChangeset
for help on using the changeset viewer.
