Changeset 5eb7847
- Timestamp:
- 10/26/25 20:52:35 (11 months ago)
- Branches:
- master
- Children:
- 28759eb, 4e061d8, 4f5d8fd
- Parents:
- 8e32210
- Location:
- iknow-api
- Files:
-
- 1 deleted
- 10 edited
-
Controllers/AuthController.cs (modified) (2 diffs)
-
Data/AppDbContext.cs (modified) (1 diff)
-
Migrations/20251022202014_InitialCreate.Designer.cs (modified) (1 diff)
-
Migrations/AppDbContextModelSnapshot.cs (modified) (1 diff)
-
Models/User.cs (modified) (1 diff)
-
Program.cs (modified) (3 diffs)
-
Repository/Implementations/UserRepository.cs (modified) (1 diff)
-
Repository/Interface/IUserRepository.cs (modified) (1 diff)
-
Services/Implementations/AuthService.cs (modified) (3 diffs)
-
WeatherForecast.cs (deleted)
-
iknow-api.csproj (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
iknow-api/Controllers/AuthController.cs
r8e32210 r5eb7847 1 1 using iknow_api.DTOs; 2 2 using iknow_api.Services; 3 using Microsoft.AspNetCore.Authorization; 4 using Microsoft.AspNetCore.Authentication.JwtBearer; 3 5 using Microsoft.AspNetCore.Mvc; 4 6 … … 45 47 return Ok(new { Token = token }); 46 48 } 49 50 [Authorize] 51 [HttpGet("getstring")] 52 public async Task<IActionResult> getstring() 53 { 54 return Ok(new { message = "You are authorized!" }); 55 } 47 56 } 48 57 } -
iknow-api/Data/AppDbContext.cs
r8e32210 r5eb7847 1 1 using Microsoft.EntityFrameworkCore; 2 using iknow_api. Core.Models;2 using iknow_api.Models; 3 3 4 namespace iknow_api. Core.Data4 namespace iknow_api.Data 5 5 { 6 6 public class AppDbContext : DbContext -
iknow-api/Migrations/20251022202014_InitialCreate.Designer.cs
r8e32210 r5eb7847 6 6 using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 7 7 using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; 8 using iknow_api. Core.Data;8 using iknow_api.Data; 9 9 10 10 #nullable disable -
iknow-api/Migrations/AppDbContextModelSnapshot.cs
r8e32210 r5eb7847 5 5 using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 6 6 using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; 7 using iknow_api. Core.Data;7 using iknow_api.Data; 8 8 9 9 #nullable disable -
iknow-api/Models/User.cs
r8e32210 r5eb7847 1 1 2 2 3 namespace iknow_api. Core.Models3 namespace iknow_api.Models 4 4 { 5 5 public enum UserRole -
iknow-api/Program.cs
r8e32210 r5eb7847 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; 1 6 using Microsoft.EntityFrameworkCore; 2 using iknow_api.Core.Data; 3 using iknow_api.Services; 4 using iknow_api.Repositories; 7 using Microsoft.IdentityModel.Tokens; 5 8 6 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", 7 23 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 }); 8 34 // Add services to the container. 9 35 builder.Services.AddControllers(); … … 17 43 builder.Services.AddScoped<IAuthService, AuthService>(); 18 44 builder.Services.AddScoped<IUserRepository, UserRepository>(); // You'll need to add the UserRepository implementation 19 45 builder.Services.AddAuthorization(); 20 46 var app = builder.Build(); 21 47 … … 27 53 28 54 app.UseHttpsRedirection(); 55 app.UseAuthentication(); // <-- must come BEFORE UseAuthorization 29 56 app.UseAuthorization(); 30 57 app.MapControllers(); -
iknow-api/Repository/Implementations/UserRepository.cs
r8e32210 r5eb7847 1 using iknow_api.Core.Models; 2 using iknow_api.Core.Data; 3 using iknow_api.Core.Data; 4 using iknow_api.Core.Models; 1 using iknow_api.Models; 2 using iknow_api.Data; 3 using iknow_api.Models; 5 4 using Microsoft.EntityFrameworkCore; 6 5 -
iknow-api/Repository/Interface/IUserRepository.cs
r8e32210 r5eb7847 1 using iknow_api. Core.Models;1 using iknow_api.Models; 2 2 namespace iknow_api.Repositories 3 3 { -
iknow-api/Services/Implementations/AuthService.cs
r8e32210 r5eb7847 4 4 using BCrypt.Net; 5 5 using iknow_api.Controllers; 6 using iknow_api. Core.Models;6 using iknow_api.Models; 7 7 using iknow_api.DTOs; 8 8 using iknow_api.Repositories; … … 36 36 Bday = DateTime.SpecifyKind(registerDto.Bday, DateTimeKind.Utc), 37 37 CreatedAt = DateTime.UtcNow, 38 Role = ( Core.Models.UserRole)registerDto.Role38 Role = (Models.UserRole)registerDto.Role 39 39 }; 40 40 … … 62 62 { 63 63 new Claim("id", user.Id.ToString()), 64 new Claim(" username", user.Email ?? string.Empty),64 new Claim("email", user.Email ?? string.Empty), 65 65 new Claim("role", user.Role.ToString()) 66 66 }; -
iknow-api/iknow-api.csproj
r8e32210 r5eb7847 10 10 <ItemGroup> 11 11 <PackageReference Include="BCrypt.Net-Next" Version="4.0.3" /> 12 <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.10" /> 12 13 <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.9" /> 13 14 <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.10">
Note:
See TracChangeset
for help on using the changeset viewer.
