├── JwtTokenWithIdentity ├── Program.cs ├── Models │ ├── TokenInfo.cs │ ├── ApplicationUserTokens.cs │ ├── ResponseViewModel.cs │ ├── WeatherForecast.cs │ ├── ApplicationUser.cs │ ├── LoginViewModel.cs │ ├── Products.cs │ ├── RegisterViewModel.cs │ └── APIDbContext.cs ├── appsettings.json ├── appsettings.Development.json ├── Controllers │ ├── ProductsController.cs │ ├── WeatherForecastController.cs │ └── UserController.cs ├── Properties │ └── launchSettings.json ├── JwtTokenWithIdentity.csproj ├── Library │ └── AccessTokenGenerator.cs └── Migrations │ ├── 20250208221331_initDB.cs │ ├── APIDbContextModelSnapshot.cs │ └── 20250208221331_initDB.Designer.cs ├── README.md ├── JwtTokenWithIdentity.sln ├── .gitattributes └── .gitignore /JwtTokenWithIdentity/Program.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semihcelikol/JwtTokenWithIdentity/HEAD/JwtTokenWithIdentity/Program.cs -------------------------------------------------------------------------------- /JwtTokenWithIdentity/Models/TokenInfo.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace JwtTokenWithIdentity.Models 3 | { 4 | public class TokenInfo 5 | { 6 | public string Token { get; set; } 7 | public DateTime ExpireDate { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /JwtTokenWithIdentity/Models/ApplicationUserTokens.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | 3 | namespace JwtTokenWithIdentity.Models 4 | { 5 | public class ApplicationUserTokens : IdentityUserToken 6 | { 7 | public DateTime ExpireDate { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /JwtTokenWithIdentity/Models/ResponseViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace JwtTokenWithIdentity.Models 2 | { 3 | public class ResponseViewModel 4 | { 5 | public bool IsSuccess { get; set; } 6 | public string Message { get; set; } 7 | public TokenInfo TokenInfo { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /JwtTokenWithIdentity/Models/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace JwtTokenWithIdentity 4 | { 5 | public class WeatherForecast 6 | { 7 | public DateTime Date { get; set; } 8 | 9 | public int TemperatureC { get; set; } 10 | 11 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 12 | 13 | public string Summary { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JwtTokenWithIdentity 2 | Jwt token with identity example projects 3 | 4 | To run the project, simply edit the appsettings.json file; 5 | 6 | "ConnectionStrings": { 7 | "SqlConnection": "Server=dbname;Database=yourdbname;User Id=yourid;Password=yourpwd.;TrustServerCertificate=True; MultipleActiveResultSets=True" 8 | }, 9 | 10 | Blog: https://semihcelikol.com/net-core-web-api-jwt-identity-kullanimi/ 11 | -------------------------------------------------------------------------------- /JwtTokenWithIdentity/Models/ApplicationUser.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.ComponentModel.DataAnnotations; 6 | using System.Linq; 7 | using System.Threading.Tasks; 8 | 9 | namespace JwtTokenWithIdentity.Models 10 | { 11 | public class ApplicationUser : IdentityUser 12 | { 13 | [Required] 14 | [DisplayName("Ad soyad")] 15 | [StringLength(60)] 16 | public string FullName { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /JwtTokenWithIdentity/Models/LoginViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace JwtTokenWithIdentity.Models 8 | { 9 | public class LoginViewModel 10 | { 11 | [Required(ErrorMessage = "Email adresi zorunlu")] 12 | [EmailAddress] 13 | public string Email { get; set; } 14 | 15 | [Required(ErrorMessage = "Şifre zorunlu")] 16 | [DataType(DataType.Password)] 17 | public string Password { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /JwtTokenWithIdentity/Models/Products.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace JwtTokenWithIdentity.Models 9 | { 10 | public class Products 11 | { 12 | [Required] 13 | public int Id { get; set; } 14 | 15 | [Required] 16 | [StringLength(60)] 17 | [DisplayName("Adı")] 18 | public string Name { get; set; } 19 | 20 | [Required] 21 | [StringLength(60)] 22 | [DisplayName("Birim fiyat")] 23 | public float UnitPrice { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /JwtTokenWithIdentity/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "SqlConnection": "Server=dbname;Database=yourdbname;User Id=yourid;Password=yourpwd.;TrustServerCertificate=True; MultipleActiveResultSets=True" 4 | }, 5 | 6 | "Application": { 7 | "Secret": "CustomSecretKey111.!!!!ddd---JWTTest!!!!", 8 | "Audience": "JwtTokenWithIdentity", 9 | "Issuer": "JwtTokenWithIdentity" 10 | 11 | }, 12 | 13 | "Roles": { 14 | "Admin": "Admin", 15 | "Manager": "Manager", 16 | "User": "User" 17 | }, 18 | 19 | "Logging": { 20 | "LogLevel": { 21 | "Default": "Information", 22 | "Microsoft": "Warning", 23 | "Microsoft.Hosting.Lifetime": "Information" 24 | } 25 | }, 26 | "AllowedHosts": "*" 27 | } 28 | -------------------------------------------------------------------------------- /JwtTokenWithIdentity/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "SqlConnection": "Server=dbname;Database=yourdbname;User Id=yourid;Password=yourpwd.;TrustServerCertificate=True; MultipleActiveResultSets=True" 4 | }, 5 | 6 | "Application": { 7 | "Secret": "CustomSecretKey111.!!!!ddd---JWTTest!!!!", 8 | "Audience": "JwtTokenWithIdentity", 9 | "Issuer": "JwtTokenWithIdentity" 10 | 11 | }, 12 | 13 | "Roles": { 14 | "Admin": "Admin", 15 | "Manager": "Manager", 16 | "User": "User" 17 | }, 18 | 19 | "Logging": { 20 | "LogLevel": { 21 | "Default": "Information", 22 | "Microsoft": "Warning", 23 | "Microsoft.Hosting.Lifetime": "Information" 24 | } 25 | }, 26 | "AllowedHosts": "*" 27 | } 28 | -------------------------------------------------------------------------------- /JwtTokenWithIdentity/Controllers/ProductsController.cs: -------------------------------------------------------------------------------- 1 | using JwtTokenWithIdentity.Models; 2 | using Microsoft.AspNetCore.Authorization; 3 | using Microsoft.AspNetCore.Mvc; 4 | 5 | namespace JwtTokenWithIdentity.Controllers 6 | { 7 | [Authorize] 8 | [Route("[controller]")] 9 | [ApiController] 10 | public class ProductsController : ControllerBase 11 | { 12 | private readonly APIDbContext _context; 13 | 14 | public ProductsController(APIDbContext context) 15 | { 16 | _context = context; 17 | } 18 | 19 | [HttpGet] 20 | [Route("GetAll")] 21 | public ActionResult GetAll() 22 | { 23 | List productList = new List(); 24 | 25 | foreach (var item in _context.Products) 26 | { 27 | productList.Add(item); 28 | } 29 | 30 | return Ok(productList); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /JwtTokenWithIdentity/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:19631", 8 | "sslPort": 0 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "swagger", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "JwtTokenWithIdentity": { 21 | "commandName": "Project", 22 | "dotnetRunMessages": "true", 23 | "launchBrowser": true, 24 | "launchUrl": "swagger", 25 | "applicationUrl": "http://localhost:5000", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /JwtTokenWithIdentity/Models/RegisterViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace JwtTokenWithIdentity.Models 9 | { 10 | public class RegisterViewModel 11 | { 12 | [Required] 13 | [DisplayName("Ad soyad")] 14 | [StringLength(60)] 15 | public string FullName { get; set; } 16 | 17 | [Required(ErrorMessage = "Email adresi zorunlu")] 18 | [EmailAddress] 19 | public string Email { get; set; } 20 | 21 | [Required(ErrorMessage = "Şifre zorunlu")] 22 | [DataType(DataType.Password)] 23 | public string Password { get; set; } 24 | 25 | [DataType(DataType.Password)] 26 | [Compare("Password", ErrorMessage = "Girmiş olduğunuz parola birbiri ile eşleşmiyor.")] 27 | public string ConfirmPassword { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /JwtTokenWithIdentity/Models/APIDbContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Http; 2 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore; 4 | 5 | namespace JwtTokenWithIdentity.Models 6 | { 7 | public class APIDbContext : IdentityDbContext 8 | { 9 | public readonly IHttpContextAccessor httpContextAccessor; 10 | 11 | public APIDbContext(DbContextOptions options, IHttpContextAccessor httpContextAccessor) 12 | : base(options) 13 | { 14 | this.httpContextAccessor = httpContextAccessor; 15 | } 16 | 17 | public DbSet ApplicationUserTokens { get; set; } 18 | public DbSet Products { get; set; } 19 | 20 | 21 | protected override void OnModelCreating(ModelBuilder builder) 22 | { 23 | base.OnModelCreating(builder); 24 | 25 | builder.Entity().ToTable("Products"); 26 | builder.Entity().HasIndex(x => x.Name).IsUnique(); 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /JwtTokenWithIdentity/JwtTokenWithIdentity.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net9.0 5 | enable 6 | disable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | all 17 | runtime; build; native; contentfiles; analyzers; buildtransitive 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /JwtTokenWithIdentity.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31402.337 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JwtTokenWithIdentity", "JwtTokenWithIdentity\JwtTokenWithIdentity.csproj", "{48526166-66E1-4346-96F6-C918B3786D36}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {48526166-66E1-4346-96F6-C918B3786D36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {48526166-66E1-4346-96F6-C918B3786D36}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {48526166-66E1-4346-96F6-C918B3786D36}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {48526166-66E1-4346-96F6-C918B3786D36}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {8DFA0DE7-A7C5-46E8-9879-91380FA51E52} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /JwtTokenWithIdentity/Controllers/WeatherForecastController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.Extensions.Logging; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace JwtTokenWithIdentity.Controllers 9 | { 10 | [ApiController] 11 | [Route("[controller]")] 12 | public class WeatherForecastController : ControllerBase 13 | { 14 | private static readonly string[] Summaries = new[] 15 | { 16 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" 17 | }; 18 | 19 | private readonly ILogger _logger; 20 | 21 | public WeatherForecastController(ILogger logger) 22 | { 23 | _logger = logger; 24 | } 25 | 26 | [HttpGet] 27 | public IEnumerable Get() 28 | { 29 | var rng = new Random(); 30 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast 31 | { 32 | Date = DateTime.Now.AddDays(index), 33 | TemperatureC = rng.Next(-20, 55), 34 | Summary = Summaries[rng.Next(Summaries.Length)] 35 | }) 36 | .ToArray(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /JwtTokenWithIdentity/Library/AccessTokenGenerator.cs: -------------------------------------------------------------------------------- 1 | using JwtTokenWithIdentity.Models; 2 | using Microsoft.Extensions.Configuration; 3 | using Microsoft.IdentityModel.Tokens; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.IdentityModel.Tokens.Jwt; 7 | using System.Linq; 8 | using System.Security.Claims; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | 12 | namespace JwtTokenWithIdentity.Library 13 | { 14 | public class AccessTokenGenerator 15 | { 16 | public APIDbContext _context { get; set; } 17 | public IConfiguration _config { get; set; } 18 | public ApplicationUser _applicationUser { get; set; } 19 | 20 | /// 21 | /// Class'ın oluşturulması. 22 | /// 23 | /// 24 | /// 25 | /// 26 | /// 27 | public AccessTokenGenerator(APIDbContext context, 28 | IConfiguration config, 29 | ApplicationUser applicationUser) 30 | { 31 | _config = config; 32 | _context = context; 33 | _applicationUser = applicationUser; 34 | } 35 | 36 | /// 37 | /// Kullanıcı üzerinde tanımlı tokenı döner;Token yoksa oluşturur. Expire olmuşsa update eder. 38 | /// 39 | /// 40 | public ApplicationUserTokens GetToken() 41 | { 42 | ApplicationUserTokens userTokens = null; 43 | TokenInfo tokenInfo = null; 44 | 45 | //Kullanıcıya ait önceden oluşturulmuş bir token var mı kontrol edilir. 46 | if (_context.ApplicationUserTokens.Count(x => x.UserId == _applicationUser.Id) > 0) 47 | { 48 | //İlgili token bilgileri bulunur. 49 | userTokens = _context.ApplicationUserTokens.FirstOrDefault(x => x.UserId == _applicationUser.Id); 50 | 51 | //Expire olmuş ise yeni token oluşturup günceller. 52 | if (userTokens.ExpireDate <= DateTime.Now) 53 | { 54 | //Create new token 55 | tokenInfo = GenerateToken(); 56 | 57 | userTokens.ExpireDate = tokenInfo.ExpireDate; 58 | userTokens.Value = tokenInfo.Token; 59 | 60 | _context.ApplicationUserTokens.Update(userTokens); 61 | } 62 | } 63 | else 64 | { 65 | //Create new token 66 | tokenInfo = GenerateToken(); 67 | 68 | userTokens = new ApplicationUserTokens(); 69 | 70 | userTokens.UserId = _applicationUser.Id; 71 | userTokens.LoginProvider = "SystemAPI"; 72 | userTokens.Name = _applicationUser.FullName; 73 | userTokens.ExpireDate = tokenInfo.ExpireDate; 74 | userTokens.Value = tokenInfo.Token; 75 | 76 | _context.ApplicationUserTokens.Add(userTokens); 77 | } 78 | 79 | _context.SaveChangesAsync(); 80 | 81 | return userTokens; 82 | } 83 | 84 | /// 85 | /// Kullanıcıya ait tokenı siler. 86 | /// 87 | /// 88 | public async Task DeleteToken() 89 | { 90 | bool ret = true; 91 | 92 | try 93 | { 94 | //Kullanıcıya ait önceden oluşturulmuş bir token var mı kontrol edilir. 95 | if (_context.ApplicationUserTokens.Count(x => x.UserId == _applicationUser.Id) > 0) 96 | { 97 | ApplicationUserTokens userTokens = userTokens = _context.ApplicationUserTokens.FirstOrDefault(x => x.UserId == _applicationUser.Id); 98 | 99 | _context.ApplicationUserTokens.Remove(userTokens); 100 | } 101 | 102 | await _context.SaveChangesAsync(); 103 | } 104 | catch (Exception) 105 | { 106 | ret = false; 107 | } 108 | 109 | return ret; 110 | } 111 | 112 | /// 113 | /// Yeni token oluşturur. 114 | /// 115 | /// 116 | private TokenInfo GenerateToken() 117 | { 118 | DateTime expireDate = DateTime.Now.AddSeconds(50); 119 | var tokenHandler = new JwtSecurityTokenHandler(); 120 | var key = Encoding.ASCII.GetBytes(_config["Application:Secret"]); 121 | 122 | var tokenDescriptor = new SecurityTokenDescriptor 123 | { 124 | Audience = _config["Application:Audience"], 125 | Issuer = _config["Application:Issuer"], 126 | Subject = new ClaimsIdentity(new Claim[] 127 | { 128 | //Claim tanımları yapılır. Burada en önemlisi Id ve emaildir. 129 | //Id üzerinden, aktif kullanıcıyı buluyor olacağız. 130 | new Claim(ClaimTypes.NameIdentifier, _applicationUser.Id), 131 | new Claim(ClaimTypes.Name, _applicationUser.FullName), 132 | new Claim(ClaimTypes.Email, _applicationUser.Email) 133 | }), 134 | 135 | //ExpireDate 136 | Expires = expireDate, 137 | 138 | //Şifreleme türünü belirtiyoruz: HmacSha256Signature 139 | SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) 140 | }; 141 | 142 | var token = tokenHandler.CreateToken(tokenDescriptor); 143 | var tokenString = tokenHandler.WriteToken(token); 144 | 145 | TokenInfo tokenInfo = new TokenInfo(); 146 | 147 | tokenInfo.Token = tokenString; 148 | tokenInfo.ExpireDate = expireDate; 149 | 150 | return tokenInfo; 151 | } 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /JwtTokenWithIdentity/Controllers/UserController.cs: -------------------------------------------------------------------------------- 1 | using JwtTokenWithIdentity.Library; 2 | using JwtTokenWithIdentity.Models; 3 | using Microsoft.AspNetCore.Identity; 4 | using Microsoft.AspNetCore.Mvc; 5 | 6 | namespace JwtTokenWithIdentity.Controllers 7 | { 8 | [Route("api/[controller]")] 9 | [ApiController] 10 | public class UserController : ControllerBase 11 | { 12 | private readonly APIDbContext _context; 13 | private readonly IConfiguration _config; 14 | private readonly SignInManager _signInManager; 15 | private readonly UserManager _userManager; 16 | private readonly RoleManager _roleManager; 17 | 18 | 19 | public UserController(APIDbContext context, 20 | IConfiguration configuration, 21 | SignInManager signInManager, 22 | UserManager userManager, 23 | RoleManager roleManager) 24 | { 25 | _context = context; 26 | _config = configuration; 27 | _signInManager = signInManager; 28 | _userManager = userManager; 29 | _roleManager = roleManager; 30 | } 31 | 32 | [HttpPost] 33 | [Route("Register")] 34 | public async Task Register([FromBody] RegisterViewModel model) 35 | { 36 | ResponseViewModel responseViewModel = new ResponseViewModel(); 37 | 38 | try 39 | { 40 | #region Validate 41 | if (!ModelState.IsValid) 42 | { 43 | responseViewModel.IsSuccess = false; 44 | responseViewModel.Message = "Bilgileriniz eksik, bazı alanlar gönderilmemiş. Lütfen tüm alanları doldurunuz."; 45 | 46 | return BadRequest(responseViewModel); 47 | } 48 | 49 | ApplicationUser existsUser = await _userManager.FindByNameAsync(model.Email); 50 | 51 | if (existsUser != null) 52 | { 53 | responseViewModel.IsSuccess = false; 54 | responseViewModel.Message = "Kullanıcı zaten var."; 55 | 56 | return BadRequest(responseViewModel); 57 | } 58 | #endregion 59 | 60 | //Kullanıcı bilgileri set edilir. 61 | ApplicationUser user = new ApplicationUser(); 62 | 63 | user.FullName = model.FullName; 64 | user.Email = model.Email.Trim(); 65 | user.UserName = model.Email.Trim(); 66 | 67 | //Kullanıcı oluşturulur. 68 | IdentityResult result = await _userManager.CreateAsync(user, model.Password.Trim()); 69 | 70 | //Kullanıcı oluşturuldu ise 71 | if (result.Succeeded) 72 | { 73 | bool roleExists = await _roleManager.RoleExistsAsync(_config["Roles:User"]); 74 | 75 | if (!roleExists) 76 | { 77 | IdentityRole role = new IdentityRole(_config["Roles:User"]); 78 | role.NormalizedName = _config["Roles:User"]; 79 | 80 | _roleManager.CreateAsync(role).Wait(); 81 | } 82 | 83 | //Kullanıcıya ilgili rol ataması yapılır. 84 | _userManager.AddToRoleAsync(user, _config["Roles:User"]).Wait(); 85 | 86 | responseViewModel.IsSuccess = true; 87 | responseViewModel.Message = "Kullanıcı başarılı şekilde oluşturuldu."; 88 | } 89 | else 90 | { 91 | responseViewModel.IsSuccess = false; 92 | responseViewModel.Message = string.Format("Kullanıcı oluşturulurken bir hata oluştu: {0}", result.Errors.FirstOrDefault().Description); 93 | } 94 | 95 | return Ok(responseViewModel); 96 | } 97 | catch (Exception ex) 98 | { 99 | responseViewModel.IsSuccess = false; 100 | responseViewModel.Message = ex.Message; 101 | 102 | return BadRequest(responseViewModel); 103 | } 104 | } 105 | 106 | [HttpPost] 107 | [Route("Login")] 108 | public async Task Login([FromBody] LoginViewModel model) 109 | { 110 | ResponseViewModel responseViewModel = new ResponseViewModel(); 111 | 112 | try 113 | { 114 | #region Validate 115 | 116 | if (ModelState.IsValid == false) 117 | { 118 | responseViewModel.IsSuccess = false; 119 | responseViewModel.Message = "Bilgileriniz eksik, bazı alanlar gönderilmemiş. Lütfen tüm alanları doldurunuz."; 120 | return BadRequest(responseViewModel); 121 | } 122 | 123 | //Kulllanıcı bulunur. 124 | ApplicationUser user = await _userManager.FindByNameAsync(model.Email); 125 | 126 | if (user == null) 127 | { 128 | return Unauthorized(); 129 | } 130 | 131 | Microsoft.AspNetCore.Identity.SignInResult signInResult = await _signInManager.PasswordSignInAsync(user, 132 | model.Password, 133 | false, 134 | false); 135 | //Kullanıcı adı ve şifre kontrolü 136 | if (signInResult.Succeeded == false) 137 | { 138 | responseViewModel.IsSuccess = false; 139 | responseViewModel.Message = "Kullanıcı adı veya şifre hatalı."; 140 | 141 | return Unauthorized(responseViewModel); 142 | } 143 | 144 | #endregion 145 | 146 | ApplicationUser applicationUser = _context.Users.FirstOrDefault(x => x.Id == user.Id); 147 | 148 | AccessTokenGenerator accessTokenGenerator = new AccessTokenGenerator(_context, _config, applicationUser); 149 | ApplicationUserTokens userTokens = accessTokenGenerator.GetToken(); 150 | 151 | responseViewModel.IsSuccess = true; 152 | responseViewModel.Message = "Kullanıcı giriş yaptı."; 153 | responseViewModel.TokenInfo = new TokenInfo 154 | { 155 | Token = userTokens.Value, 156 | ExpireDate = userTokens.ExpireDate 157 | }; 158 | 159 | return Ok(responseViewModel); 160 | } 161 | catch (Exception ex) 162 | { 163 | responseViewModel.IsSuccess = false; 164 | responseViewModel.Message = ex.Message; 165 | 166 | return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); 167 | } 168 | } 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /JwtTokenWithIdentity/Migrations/20250208221331_initDB.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | #nullable disable 5 | 6 | namespace JwtTokenWithIdentity.Migrations 7 | { 8 | /// 9 | public partial class initDB : Migration 10 | { 11 | /// 12 | protected override void Up(MigrationBuilder migrationBuilder) 13 | { 14 | migrationBuilder.CreateTable( 15 | name: "AspNetRoles", 16 | columns: table => new 17 | { 18 | Id = table.Column(type: "nvarchar(450)", nullable: false), 19 | Name = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 20 | NormalizedName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 21 | ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true) 22 | }, 23 | constraints: table => 24 | { 25 | table.PrimaryKey("PK_AspNetRoles", x => x.Id); 26 | }); 27 | 28 | migrationBuilder.CreateTable( 29 | name: "AspNetUsers", 30 | columns: table => new 31 | { 32 | Id = table.Column(type: "nvarchar(450)", nullable: false), 33 | FullName = table.Column(type: "nvarchar(60)", maxLength: 60, nullable: false), 34 | UserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 35 | NormalizedUserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 36 | Email = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 37 | NormalizedEmail = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 38 | EmailConfirmed = table.Column(type: "bit", nullable: false), 39 | PasswordHash = table.Column(type: "nvarchar(max)", nullable: true), 40 | SecurityStamp = table.Column(type: "nvarchar(max)", nullable: true), 41 | ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true), 42 | PhoneNumber = table.Column(type: "nvarchar(max)", nullable: true), 43 | PhoneNumberConfirmed = table.Column(type: "bit", nullable: false), 44 | TwoFactorEnabled = table.Column(type: "bit", nullable: false), 45 | LockoutEnd = table.Column(type: "datetimeoffset", nullable: true), 46 | LockoutEnabled = table.Column(type: "bit", nullable: false), 47 | AccessFailedCount = table.Column(type: "int", nullable: false) 48 | }, 49 | constraints: table => 50 | { 51 | table.PrimaryKey("PK_AspNetUsers", x => x.Id); 52 | }); 53 | 54 | migrationBuilder.CreateTable( 55 | name: "Products", 56 | columns: table => new 57 | { 58 | Id = table.Column(type: "int", nullable: false) 59 | .Annotation("SqlServer:Identity", "1, 1"), 60 | Name = table.Column(type: "nvarchar(60)", maxLength: 60, nullable: false), 61 | UnitPrice = table.Column(type: "real", maxLength: 60, nullable: false) 62 | }, 63 | constraints: table => 64 | { 65 | table.PrimaryKey("PK_Products", x => x.Id); 66 | }); 67 | 68 | migrationBuilder.CreateTable( 69 | name: "AspNetRoleClaims", 70 | columns: table => new 71 | { 72 | Id = table.Column(type: "int", nullable: false) 73 | .Annotation("SqlServer:Identity", "1, 1"), 74 | RoleId = table.Column(type: "nvarchar(450)", nullable: false), 75 | ClaimType = table.Column(type: "nvarchar(max)", nullable: true), 76 | ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) 77 | }, 78 | constraints: table => 79 | { 80 | table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); 81 | table.ForeignKey( 82 | name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", 83 | column: x => x.RoleId, 84 | principalTable: "AspNetRoles", 85 | principalColumn: "Id", 86 | onDelete: ReferentialAction.Cascade); 87 | }); 88 | 89 | migrationBuilder.CreateTable( 90 | name: "AspNetUserClaims", 91 | columns: table => new 92 | { 93 | Id = table.Column(type: "int", nullable: false) 94 | .Annotation("SqlServer:Identity", "1, 1"), 95 | UserId = table.Column(type: "nvarchar(450)", nullable: false), 96 | ClaimType = table.Column(type: "nvarchar(max)", nullable: true), 97 | ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) 98 | }, 99 | constraints: table => 100 | { 101 | table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); 102 | table.ForeignKey( 103 | name: "FK_AspNetUserClaims_AspNetUsers_UserId", 104 | column: x => x.UserId, 105 | principalTable: "AspNetUsers", 106 | principalColumn: "Id", 107 | onDelete: ReferentialAction.Cascade); 108 | }); 109 | 110 | migrationBuilder.CreateTable( 111 | name: "AspNetUserLogins", 112 | columns: table => new 113 | { 114 | LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), 115 | ProviderKey = table.Column(type: "nvarchar(450)", nullable: false), 116 | ProviderDisplayName = table.Column(type: "nvarchar(max)", nullable: true), 117 | UserId = table.Column(type: "nvarchar(450)", nullable: false) 118 | }, 119 | constraints: table => 120 | { 121 | table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); 122 | table.ForeignKey( 123 | name: "FK_AspNetUserLogins_AspNetUsers_UserId", 124 | column: x => x.UserId, 125 | principalTable: "AspNetUsers", 126 | principalColumn: "Id", 127 | onDelete: ReferentialAction.Cascade); 128 | }); 129 | 130 | migrationBuilder.CreateTable( 131 | name: "AspNetUserRoles", 132 | columns: table => new 133 | { 134 | UserId = table.Column(type: "nvarchar(450)", nullable: false), 135 | RoleId = table.Column(type: "nvarchar(450)", nullable: false) 136 | }, 137 | constraints: table => 138 | { 139 | table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); 140 | table.ForeignKey( 141 | name: "FK_AspNetUserRoles_AspNetRoles_RoleId", 142 | column: x => x.RoleId, 143 | principalTable: "AspNetRoles", 144 | principalColumn: "Id", 145 | onDelete: ReferentialAction.Cascade); 146 | table.ForeignKey( 147 | name: "FK_AspNetUserRoles_AspNetUsers_UserId", 148 | column: x => x.UserId, 149 | principalTable: "AspNetUsers", 150 | principalColumn: "Id", 151 | onDelete: ReferentialAction.Cascade); 152 | }); 153 | 154 | migrationBuilder.CreateTable( 155 | name: "AspNetUserTokens", 156 | columns: table => new 157 | { 158 | UserId = table.Column(type: "nvarchar(450)", nullable: false), 159 | LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), 160 | Name = table.Column(type: "nvarchar(450)", nullable: false), 161 | Value = table.Column(type: "nvarchar(max)", nullable: true), 162 | Discriminator = table.Column(type: "nvarchar(34)", maxLength: 34, nullable: false), 163 | ExpireDate = table.Column(type: "datetime2", nullable: true) 164 | }, 165 | constraints: table => 166 | { 167 | table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); 168 | table.ForeignKey( 169 | name: "FK_AspNetUserTokens_AspNetUsers_UserId", 170 | column: x => x.UserId, 171 | principalTable: "AspNetUsers", 172 | principalColumn: "Id", 173 | onDelete: ReferentialAction.Cascade); 174 | }); 175 | 176 | migrationBuilder.CreateIndex( 177 | name: "IX_AspNetRoleClaims_RoleId", 178 | table: "AspNetRoleClaims", 179 | column: "RoleId"); 180 | 181 | migrationBuilder.CreateIndex( 182 | name: "RoleNameIndex", 183 | table: "AspNetRoles", 184 | column: "NormalizedName", 185 | unique: true, 186 | filter: "[NormalizedName] IS NOT NULL"); 187 | 188 | migrationBuilder.CreateIndex( 189 | name: "IX_AspNetUserClaims_UserId", 190 | table: "AspNetUserClaims", 191 | column: "UserId"); 192 | 193 | migrationBuilder.CreateIndex( 194 | name: "IX_AspNetUserLogins_UserId", 195 | table: "AspNetUserLogins", 196 | column: "UserId"); 197 | 198 | migrationBuilder.CreateIndex( 199 | name: "IX_AspNetUserRoles_RoleId", 200 | table: "AspNetUserRoles", 201 | column: "RoleId"); 202 | 203 | migrationBuilder.CreateIndex( 204 | name: "EmailIndex", 205 | table: "AspNetUsers", 206 | column: "NormalizedEmail"); 207 | 208 | migrationBuilder.CreateIndex( 209 | name: "UserNameIndex", 210 | table: "AspNetUsers", 211 | column: "NormalizedUserName", 212 | unique: true, 213 | filter: "[NormalizedUserName] IS NOT NULL"); 214 | 215 | migrationBuilder.CreateIndex( 216 | name: "IX_Products_Name", 217 | table: "Products", 218 | column: "Name", 219 | unique: true); 220 | } 221 | 222 | /// 223 | protected override void Down(MigrationBuilder migrationBuilder) 224 | { 225 | migrationBuilder.DropTable( 226 | name: "AspNetRoleClaims"); 227 | 228 | migrationBuilder.DropTable( 229 | name: "AspNetUserClaims"); 230 | 231 | migrationBuilder.DropTable( 232 | name: "AspNetUserLogins"); 233 | 234 | migrationBuilder.DropTable( 235 | name: "AspNetUserRoles"); 236 | 237 | migrationBuilder.DropTable( 238 | name: "AspNetUserTokens"); 239 | 240 | migrationBuilder.DropTable( 241 | name: "Products"); 242 | 243 | migrationBuilder.DropTable( 244 | name: "AspNetRoles"); 245 | 246 | migrationBuilder.DropTable( 247 | name: "AspNetUsers"); 248 | } 249 | } 250 | } 251 | -------------------------------------------------------------------------------- /JwtTokenWithIdentity/Migrations/APIDbContextModelSnapshot.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using JwtTokenWithIdentity.Models; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 8 | 9 | #nullable disable 10 | 11 | namespace JwtTokenWithIdentity.Migrations 12 | { 13 | [DbContext(typeof(APIDbContext))] 14 | partial class APIDbContextModelSnapshot : ModelSnapshot 15 | { 16 | protected override void BuildModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder 20 | .HasAnnotation("ProductVersion", "9.0.1") 21 | .HasAnnotation("Relational:MaxIdentifierLength", 128); 22 | 23 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); 24 | 25 | modelBuilder.Entity("JwtTokenWithIdentity.Models.ApplicationUser", b => 26 | { 27 | b.Property("Id") 28 | .HasColumnType("nvarchar(450)"); 29 | 30 | b.Property("AccessFailedCount") 31 | .HasColumnType("int"); 32 | 33 | b.Property("ConcurrencyStamp") 34 | .IsConcurrencyToken() 35 | .HasColumnType("nvarchar(max)"); 36 | 37 | b.Property("Email") 38 | .HasMaxLength(256) 39 | .HasColumnType("nvarchar(256)"); 40 | 41 | b.Property("EmailConfirmed") 42 | .HasColumnType("bit"); 43 | 44 | b.Property("FullName") 45 | .IsRequired() 46 | .HasMaxLength(60) 47 | .HasColumnType("nvarchar(60)"); 48 | 49 | b.Property("LockoutEnabled") 50 | .HasColumnType("bit"); 51 | 52 | b.Property("LockoutEnd") 53 | .HasColumnType("datetimeoffset"); 54 | 55 | b.Property("NormalizedEmail") 56 | .HasMaxLength(256) 57 | .HasColumnType("nvarchar(256)"); 58 | 59 | b.Property("NormalizedUserName") 60 | .HasMaxLength(256) 61 | .HasColumnType("nvarchar(256)"); 62 | 63 | b.Property("PasswordHash") 64 | .HasColumnType("nvarchar(max)"); 65 | 66 | b.Property("PhoneNumber") 67 | .HasColumnType("nvarchar(max)"); 68 | 69 | b.Property("PhoneNumberConfirmed") 70 | .HasColumnType("bit"); 71 | 72 | b.Property("SecurityStamp") 73 | .HasColumnType("nvarchar(max)"); 74 | 75 | b.Property("TwoFactorEnabled") 76 | .HasColumnType("bit"); 77 | 78 | b.Property("UserName") 79 | .HasMaxLength(256) 80 | .HasColumnType("nvarchar(256)"); 81 | 82 | b.HasKey("Id"); 83 | 84 | b.HasIndex("NormalizedEmail") 85 | .HasDatabaseName("EmailIndex"); 86 | 87 | b.HasIndex("NormalizedUserName") 88 | .IsUnique() 89 | .HasDatabaseName("UserNameIndex") 90 | .HasFilter("[NormalizedUserName] IS NOT NULL"); 91 | 92 | b.ToTable("AspNetUsers", (string)null); 93 | }); 94 | 95 | modelBuilder.Entity("JwtTokenWithIdentity.Models.Products", b => 96 | { 97 | b.Property("Id") 98 | .ValueGeneratedOnAdd() 99 | .HasColumnType("int"); 100 | 101 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 102 | 103 | b.Property("Name") 104 | .IsRequired() 105 | .HasMaxLength(60) 106 | .HasColumnType("nvarchar(60)"); 107 | 108 | b.Property("UnitPrice") 109 | .HasMaxLength(60) 110 | .HasColumnType("real"); 111 | 112 | b.HasKey("Id"); 113 | 114 | b.HasIndex("Name") 115 | .IsUnique(); 116 | 117 | b.ToTable("Products", (string)null); 118 | }); 119 | 120 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => 121 | { 122 | b.Property("Id") 123 | .HasColumnType("nvarchar(450)"); 124 | 125 | b.Property("ConcurrencyStamp") 126 | .IsConcurrencyToken() 127 | .HasColumnType("nvarchar(max)"); 128 | 129 | b.Property("Name") 130 | .HasMaxLength(256) 131 | .HasColumnType("nvarchar(256)"); 132 | 133 | b.Property("NormalizedName") 134 | .HasMaxLength(256) 135 | .HasColumnType("nvarchar(256)"); 136 | 137 | b.HasKey("Id"); 138 | 139 | b.HasIndex("NormalizedName") 140 | .IsUnique() 141 | .HasDatabaseName("RoleNameIndex") 142 | .HasFilter("[NormalizedName] IS NOT NULL"); 143 | 144 | b.ToTable("AspNetRoles", (string)null); 145 | }); 146 | 147 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 148 | { 149 | b.Property("Id") 150 | .ValueGeneratedOnAdd() 151 | .HasColumnType("int"); 152 | 153 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 154 | 155 | b.Property("ClaimType") 156 | .HasColumnType("nvarchar(max)"); 157 | 158 | b.Property("ClaimValue") 159 | .HasColumnType("nvarchar(max)"); 160 | 161 | b.Property("RoleId") 162 | .IsRequired() 163 | .HasColumnType("nvarchar(450)"); 164 | 165 | b.HasKey("Id"); 166 | 167 | b.HasIndex("RoleId"); 168 | 169 | b.ToTable("AspNetRoleClaims", (string)null); 170 | }); 171 | 172 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 173 | { 174 | b.Property("Id") 175 | .ValueGeneratedOnAdd() 176 | .HasColumnType("int"); 177 | 178 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 179 | 180 | b.Property("ClaimType") 181 | .HasColumnType("nvarchar(max)"); 182 | 183 | b.Property("ClaimValue") 184 | .HasColumnType("nvarchar(max)"); 185 | 186 | b.Property("UserId") 187 | .IsRequired() 188 | .HasColumnType("nvarchar(450)"); 189 | 190 | b.HasKey("Id"); 191 | 192 | b.HasIndex("UserId"); 193 | 194 | b.ToTable("AspNetUserClaims", (string)null); 195 | }); 196 | 197 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 198 | { 199 | b.Property("LoginProvider") 200 | .HasColumnType("nvarchar(450)"); 201 | 202 | b.Property("ProviderKey") 203 | .HasColumnType("nvarchar(450)"); 204 | 205 | b.Property("ProviderDisplayName") 206 | .HasColumnType("nvarchar(max)"); 207 | 208 | b.Property("UserId") 209 | .IsRequired() 210 | .HasColumnType("nvarchar(450)"); 211 | 212 | b.HasKey("LoginProvider", "ProviderKey"); 213 | 214 | b.HasIndex("UserId"); 215 | 216 | b.ToTable("AspNetUserLogins", (string)null); 217 | }); 218 | 219 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 220 | { 221 | b.Property("UserId") 222 | .HasColumnType("nvarchar(450)"); 223 | 224 | b.Property("RoleId") 225 | .HasColumnType("nvarchar(450)"); 226 | 227 | b.HasKey("UserId", "RoleId"); 228 | 229 | b.HasIndex("RoleId"); 230 | 231 | b.ToTable("AspNetUserRoles", (string)null); 232 | }); 233 | 234 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 235 | { 236 | b.Property("UserId") 237 | .HasColumnType("nvarchar(450)"); 238 | 239 | b.Property("LoginProvider") 240 | .HasColumnType("nvarchar(450)"); 241 | 242 | b.Property("Name") 243 | .HasColumnType("nvarchar(450)"); 244 | 245 | b.Property("Discriminator") 246 | .IsRequired() 247 | .HasMaxLength(34) 248 | .HasColumnType("nvarchar(34)"); 249 | 250 | b.Property("Value") 251 | .HasColumnType("nvarchar(max)"); 252 | 253 | b.HasKey("UserId", "LoginProvider", "Name"); 254 | 255 | b.ToTable("AspNetUserTokens", (string)null); 256 | 257 | b.HasDiscriminator().HasValue("IdentityUserToken"); 258 | 259 | b.UseTphMappingStrategy(); 260 | }); 261 | 262 | modelBuilder.Entity("JwtTokenWithIdentity.Models.ApplicationUserTokens", b => 263 | { 264 | b.HasBaseType("Microsoft.AspNetCore.Identity.IdentityUserToken"); 265 | 266 | b.Property("ExpireDate") 267 | .HasColumnType("datetime2"); 268 | 269 | b.HasDiscriminator().HasValue("ApplicationUserTokens"); 270 | }); 271 | 272 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 273 | { 274 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 275 | .WithMany() 276 | .HasForeignKey("RoleId") 277 | .OnDelete(DeleteBehavior.Cascade) 278 | .IsRequired(); 279 | }); 280 | 281 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 282 | { 283 | b.HasOne("JwtTokenWithIdentity.Models.ApplicationUser", null) 284 | .WithMany() 285 | .HasForeignKey("UserId") 286 | .OnDelete(DeleteBehavior.Cascade) 287 | .IsRequired(); 288 | }); 289 | 290 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 291 | { 292 | b.HasOne("JwtTokenWithIdentity.Models.ApplicationUser", null) 293 | .WithMany() 294 | .HasForeignKey("UserId") 295 | .OnDelete(DeleteBehavior.Cascade) 296 | .IsRequired(); 297 | }); 298 | 299 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 300 | { 301 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 302 | .WithMany() 303 | .HasForeignKey("RoleId") 304 | .OnDelete(DeleteBehavior.Cascade) 305 | .IsRequired(); 306 | 307 | b.HasOne("JwtTokenWithIdentity.Models.ApplicationUser", null) 308 | .WithMany() 309 | .HasForeignKey("UserId") 310 | .OnDelete(DeleteBehavior.Cascade) 311 | .IsRequired(); 312 | }); 313 | 314 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 315 | { 316 | b.HasOne("JwtTokenWithIdentity.Models.ApplicationUser", null) 317 | .WithMany() 318 | .HasForeignKey("UserId") 319 | .OnDelete(DeleteBehavior.Cascade) 320 | .IsRequired(); 321 | }); 322 | #pragma warning restore 612, 618 323 | } 324 | } 325 | } 326 | -------------------------------------------------------------------------------- /JwtTokenWithIdentity/Migrations/20250208221331_initDB.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using JwtTokenWithIdentity.Models; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | #nullable disable 11 | 12 | namespace JwtTokenWithIdentity.Migrations 13 | { 14 | [DbContext(typeof(APIDbContext))] 15 | [Migration("20250208221331_initDB")] 16 | partial class initDB 17 | { 18 | /// 19 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 20 | { 21 | #pragma warning disable 612, 618 22 | modelBuilder 23 | .HasAnnotation("ProductVersion", "9.0.1") 24 | .HasAnnotation("Relational:MaxIdentifierLength", 128); 25 | 26 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); 27 | 28 | modelBuilder.Entity("JwtTokenWithIdentity.Models.ApplicationUser", b => 29 | { 30 | b.Property("Id") 31 | .HasColumnType("nvarchar(450)"); 32 | 33 | b.Property("AccessFailedCount") 34 | .HasColumnType("int"); 35 | 36 | b.Property("ConcurrencyStamp") 37 | .IsConcurrencyToken() 38 | .HasColumnType("nvarchar(max)"); 39 | 40 | b.Property("Email") 41 | .HasMaxLength(256) 42 | .HasColumnType("nvarchar(256)"); 43 | 44 | b.Property("EmailConfirmed") 45 | .HasColumnType("bit"); 46 | 47 | b.Property("FullName") 48 | .IsRequired() 49 | .HasMaxLength(60) 50 | .HasColumnType("nvarchar(60)"); 51 | 52 | b.Property("LockoutEnabled") 53 | .HasColumnType("bit"); 54 | 55 | b.Property("LockoutEnd") 56 | .HasColumnType("datetimeoffset"); 57 | 58 | b.Property("NormalizedEmail") 59 | .HasMaxLength(256) 60 | .HasColumnType("nvarchar(256)"); 61 | 62 | b.Property("NormalizedUserName") 63 | .HasMaxLength(256) 64 | .HasColumnType("nvarchar(256)"); 65 | 66 | b.Property("PasswordHash") 67 | .HasColumnType("nvarchar(max)"); 68 | 69 | b.Property("PhoneNumber") 70 | .HasColumnType("nvarchar(max)"); 71 | 72 | b.Property("PhoneNumberConfirmed") 73 | .HasColumnType("bit"); 74 | 75 | b.Property("SecurityStamp") 76 | .HasColumnType("nvarchar(max)"); 77 | 78 | b.Property("TwoFactorEnabled") 79 | .HasColumnType("bit"); 80 | 81 | b.Property("UserName") 82 | .HasMaxLength(256) 83 | .HasColumnType("nvarchar(256)"); 84 | 85 | b.HasKey("Id"); 86 | 87 | b.HasIndex("NormalizedEmail") 88 | .HasDatabaseName("EmailIndex"); 89 | 90 | b.HasIndex("NormalizedUserName") 91 | .IsUnique() 92 | .HasDatabaseName("UserNameIndex") 93 | .HasFilter("[NormalizedUserName] IS NOT NULL"); 94 | 95 | b.ToTable("AspNetUsers", (string)null); 96 | }); 97 | 98 | modelBuilder.Entity("JwtTokenWithIdentity.Models.Products", b => 99 | { 100 | b.Property("Id") 101 | .ValueGeneratedOnAdd() 102 | .HasColumnType("int"); 103 | 104 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 105 | 106 | b.Property("Name") 107 | .IsRequired() 108 | .HasMaxLength(60) 109 | .HasColumnType("nvarchar(60)"); 110 | 111 | b.Property("UnitPrice") 112 | .HasMaxLength(60) 113 | .HasColumnType("real"); 114 | 115 | b.HasKey("Id"); 116 | 117 | b.HasIndex("Name") 118 | .IsUnique(); 119 | 120 | b.ToTable("Products", (string)null); 121 | }); 122 | 123 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => 124 | { 125 | b.Property("Id") 126 | .HasColumnType("nvarchar(450)"); 127 | 128 | b.Property("ConcurrencyStamp") 129 | .IsConcurrencyToken() 130 | .HasColumnType("nvarchar(max)"); 131 | 132 | b.Property("Name") 133 | .HasMaxLength(256) 134 | .HasColumnType("nvarchar(256)"); 135 | 136 | b.Property("NormalizedName") 137 | .HasMaxLength(256) 138 | .HasColumnType("nvarchar(256)"); 139 | 140 | b.HasKey("Id"); 141 | 142 | b.HasIndex("NormalizedName") 143 | .IsUnique() 144 | .HasDatabaseName("RoleNameIndex") 145 | .HasFilter("[NormalizedName] IS NOT NULL"); 146 | 147 | b.ToTable("AspNetRoles", (string)null); 148 | }); 149 | 150 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 151 | { 152 | b.Property("Id") 153 | .ValueGeneratedOnAdd() 154 | .HasColumnType("int"); 155 | 156 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 157 | 158 | b.Property("ClaimType") 159 | .HasColumnType("nvarchar(max)"); 160 | 161 | b.Property("ClaimValue") 162 | .HasColumnType("nvarchar(max)"); 163 | 164 | b.Property("RoleId") 165 | .IsRequired() 166 | .HasColumnType("nvarchar(450)"); 167 | 168 | b.HasKey("Id"); 169 | 170 | b.HasIndex("RoleId"); 171 | 172 | b.ToTable("AspNetRoleClaims", (string)null); 173 | }); 174 | 175 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 176 | { 177 | b.Property("Id") 178 | .ValueGeneratedOnAdd() 179 | .HasColumnType("int"); 180 | 181 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 182 | 183 | b.Property("ClaimType") 184 | .HasColumnType("nvarchar(max)"); 185 | 186 | b.Property("ClaimValue") 187 | .HasColumnType("nvarchar(max)"); 188 | 189 | b.Property("UserId") 190 | .IsRequired() 191 | .HasColumnType("nvarchar(450)"); 192 | 193 | b.HasKey("Id"); 194 | 195 | b.HasIndex("UserId"); 196 | 197 | b.ToTable("AspNetUserClaims", (string)null); 198 | }); 199 | 200 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 201 | { 202 | b.Property("LoginProvider") 203 | .HasColumnType("nvarchar(450)"); 204 | 205 | b.Property("ProviderKey") 206 | .HasColumnType("nvarchar(450)"); 207 | 208 | b.Property("ProviderDisplayName") 209 | .HasColumnType("nvarchar(max)"); 210 | 211 | b.Property("UserId") 212 | .IsRequired() 213 | .HasColumnType("nvarchar(450)"); 214 | 215 | b.HasKey("LoginProvider", "ProviderKey"); 216 | 217 | b.HasIndex("UserId"); 218 | 219 | b.ToTable("AspNetUserLogins", (string)null); 220 | }); 221 | 222 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 223 | { 224 | b.Property("UserId") 225 | .HasColumnType("nvarchar(450)"); 226 | 227 | b.Property("RoleId") 228 | .HasColumnType("nvarchar(450)"); 229 | 230 | b.HasKey("UserId", "RoleId"); 231 | 232 | b.HasIndex("RoleId"); 233 | 234 | b.ToTable("AspNetUserRoles", (string)null); 235 | }); 236 | 237 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 238 | { 239 | b.Property("UserId") 240 | .HasColumnType("nvarchar(450)"); 241 | 242 | b.Property("LoginProvider") 243 | .HasColumnType("nvarchar(450)"); 244 | 245 | b.Property("Name") 246 | .HasColumnType("nvarchar(450)"); 247 | 248 | b.Property("Discriminator") 249 | .IsRequired() 250 | .HasMaxLength(34) 251 | .HasColumnType("nvarchar(34)"); 252 | 253 | b.Property("Value") 254 | .HasColumnType("nvarchar(max)"); 255 | 256 | b.HasKey("UserId", "LoginProvider", "Name"); 257 | 258 | b.ToTable("AspNetUserTokens", (string)null); 259 | 260 | b.HasDiscriminator().HasValue("IdentityUserToken"); 261 | 262 | b.UseTphMappingStrategy(); 263 | }); 264 | 265 | modelBuilder.Entity("JwtTokenWithIdentity.Models.ApplicationUserTokens", b => 266 | { 267 | b.HasBaseType("Microsoft.AspNetCore.Identity.IdentityUserToken"); 268 | 269 | b.Property("ExpireDate") 270 | .HasColumnType("datetime2"); 271 | 272 | b.HasDiscriminator().HasValue("ApplicationUserTokens"); 273 | }); 274 | 275 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 276 | { 277 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 278 | .WithMany() 279 | .HasForeignKey("RoleId") 280 | .OnDelete(DeleteBehavior.Cascade) 281 | .IsRequired(); 282 | }); 283 | 284 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 285 | { 286 | b.HasOne("JwtTokenWithIdentity.Models.ApplicationUser", null) 287 | .WithMany() 288 | .HasForeignKey("UserId") 289 | .OnDelete(DeleteBehavior.Cascade) 290 | .IsRequired(); 291 | }); 292 | 293 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 294 | { 295 | b.HasOne("JwtTokenWithIdentity.Models.ApplicationUser", null) 296 | .WithMany() 297 | .HasForeignKey("UserId") 298 | .OnDelete(DeleteBehavior.Cascade) 299 | .IsRequired(); 300 | }); 301 | 302 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 303 | { 304 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 305 | .WithMany() 306 | .HasForeignKey("RoleId") 307 | .OnDelete(DeleteBehavior.Cascade) 308 | .IsRequired(); 309 | 310 | b.HasOne("JwtTokenWithIdentity.Models.ApplicationUser", null) 311 | .WithMany() 312 | .HasForeignKey("UserId") 313 | .OnDelete(DeleteBehavior.Cascade) 314 | .IsRequired(); 315 | }); 316 | 317 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 318 | { 319 | b.HasOne("JwtTokenWithIdentity.Models.ApplicationUser", null) 320 | .WithMany() 321 | .HasForeignKey("UserId") 322 | .OnDelete(DeleteBehavior.Cascade) 323 | .IsRequired(); 324 | }); 325 | #pragma warning restore 612, 618 326 | } 327 | } 328 | } 329 | --------------------------------------------------------------------------------