This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | using System.ComponentModel.DataAnnotations; | |
| namespace JWTSample.Models | |
| { | |
| //Authenticate işleminde neler geleceğini ve validasyonları için oluşturdum. | |
| public class AuthenticateModel | |
| { | |
| [Required] | |
| public string Username { get; set; } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | using JWTSample.Models; | |
| using JWTSample.Services.User; | |
| using Microsoft.AspNetCore.Authorization; | |
| using Microsoft.AspNetCore.Mvc; | |
| namespace JWTSample.Controllers | |
| { | |
| //Authorize attribute ile bu sınıfı sadece yetkisi yani tokenı olan kişilerin girmesini söylüyorum. | |
| [Authorize] | |
| [ApiController] | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | using JWTSample.Helpers; | |
| using JWTSample.Entities; | |
| using Microsoft.Extensions.Options; | |
| using Microsoft.IdentityModel.Tokens; | |
| using System; | |
| using System.IdentityModel.Tokens.Jwt; | |
| using System.Linq; | |
| using System.Security.Claims; | |
| using System.Text; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | namespace JWTSample.Services.User | |
| { | |
| public interface IUserService | |
| { | |
| (string username, string token)? Authenticate(string username, string password); | |
| } | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | namespace JWTSample.Helpers | |
| { | |
| public class AppSettings | |
| { | |
| public string SecretKey { get; set; } | |
| } | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | { | |
| "AppSettings": { | |
| "SecretKey": "Buraya imza için gerekli gizli anahtarımızı giriyoruz." | |
| }, | |
| "Logging": { | |
| "LogLevel": { | |
| "Default": "Information", | |
| "Microsoft": "Warning", | |
| "Microsoft.Hosting.Lifetime": "Information" | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | using Microsoft.EntityFrameworkCore; | |
| namespace JWTSample.Entities | |
| { | |
| //DbContext sınıfından kalıtım alarak bunun bir context olacağını belirtiyorum. | |
| public class ApplicationDbContext : DbContext | |
| { | |
| //Veritabanına hazırladığım modeli tablo olarak eklemesini söylüyorum. | |
| public DbSet<ApplicationUser> ApplicationUsers { get; set; } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | namespace JWTSample.Entities | |
| { | |
| //Veritabanımız için ApplicationUser modelini oluşturduk. | |
| public class ApplicationUser | |
| { | |
| public int Id { get; set; } | |
| public string FirstName { get; set; } = "unnamed"; | |
| public string Username { get; set; } | |
| public string Password { get; set; } | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | using JWTSample.Entities; | |
| using JWTSample.Helpers; | |
| using JWTSample.Services.User; | |
| using Microsoft.AspNetCore.Authentication.JwtBearer; | |
| using Microsoft.AspNetCore.Builder; | |
| using Microsoft.AspNetCore.Hosting; | |
| using Microsoft.Extensions.Configuration; | |
| using Microsoft.Extensions.DependencyInjection; | |
| using Microsoft.Extensions.Hosting; | |
| using Microsoft.IdentityModel.Tokens; |