├── ClaimBased ├── AuthJWT.sln ├── AuthJWT.sln.DotSettings.user └── AuthJWT │ ├── AuthJWT.csproj │ ├── Config │ ├── AppSettings.cs │ └── Extentions │ │ ├── AuthenticationExtention.cs │ │ └── SwaggerExtention.cs │ ├── Controllers │ └── UserController.cs │ ├── DtoModels │ └── UserDto.cs │ ├── Entities │ └── User.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Services │ └── UserService │ │ ├── IUserService.cs │ │ └── UserService.cs │ ├── Startup.cs │ ├── appsettings.Development.json │ ├── appsettings.json │ ├── bin │ └── Debug │ │ └── netcoreapp2.2 │ │ ├── AuthJWT.deps.json │ │ ├── AuthJWT.dll │ │ ├── AuthJWT.pdb │ │ ├── AuthJWT.runtimeconfig.dev.json │ │ ├── AuthJWT.runtimeconfig.json │ │ ├── Properties │ │ └── launchSettings.json │ │ ├── appsettings.Development.json │ │ └── appsettings.json │ └── obj │ ├── AuthJWT.csproj.nuget.cache │ ├── AuthJWT.csproj.nuget.dgspec.json │ ├── AuthJWT.csproj.nuget.g.props │ ├── AuthJWT.csproj.nuget.g.targets │ ├── Debug │ └── netcoreapp2.2 │ │ ├── AuthJWT.AssemblyInfo.cs │ │ ├── AuthJWT.AssemblyInfoInputs.cache │ │ ├── AuthJWT.RazorAssemblyInfo.cache │ │ ├── AuthJWT.RazorAssemblyInfo.cs │ │ ├── AuthJWT.RazorTargetAssemblyInfo.cache │ │ ├── AuthJWT.assets.cache │ │ ├── AuthJWT.csproj.CoreCompileInputs.cache │ │ ├── AuthJWT.csproj.FileListAbsolute.txt │ │ ├── AuthJWT.csprojAssemblyReference.cache │ │ ├── AuthJWT.dll │ │ ├── AuthJWT.pdb │ │ └── project.razor.json │ └── project.assets.json ├── PermissionBased ├── AuthJWT.sln ├── AuthJWT.sln.DotSettings.user └── AuthJWT │ ├── AuthJWT.csproj │ ├── Config │ ├── AppSettings.cs │ ├── Extentions │ │ ├── AuthenticationExtention.cs │ │ └── SwaggerExtention.cs │ └── Permissions │ │ ├── AuthorizationPolicyProvider.cs │ │ ├── PermissionAuthorizeAttribute.cs │ │ └── Permissions.cs │ ├── Controllers │ └── UserController.cs │ ├── DtoModels │ └── UserDto.cs │ ├── Entities │ └── User.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Services │ └── UserService │ │ ├── IUserService.cs │ │ └── UserService.cs │ ├── Startup.cs │ ├── appsettings.Development.json │ ├── appsettings.json │ ├── bin │ └── Debug │ │ └── netcoreapp2.2 │ │ ├── AuthJWT.deps.json │ │ ├── AuthJWT.dll │ │ ├── AuthJWT.pdb │ │ ├── AuthJWT.runtimeconfig.dev.json │ │ ├── AuthJWT.runtimeconfig.json │ │ ├── Properties │ │ └── launchSettings.json │ │ ├── appsettings.Development.json │ │ └── appsettings.json │ └── obj │ ├── AuthJWT.csproj.nuget.cache │ ├── AuthJWT.csproj.nuget.dgspec.json │ ├── AuthJWT.csproj.nuget.g.props │ ├── AuthJWT.csproj.nuget.g.targets │ ├── Debug │ └── netcoreapp2.2 │ │ ├── AuthJWT.AssemblyInfo.cs │ │ ├── AuthJWT.AssemblyInfoInputs.cache │ │ ├── AuthJWT.RazorAssemblyInfo.cache │ │ ├── AuthJWT.RazorAssemblyInfo.cs │ │ ├── AuthJWT.RazorTargetAssemblyInfo.cache │ │ ├── AuthJWT.assets.cache │ │ ├── AuthJWT.csproj.CoreCompileInputs.cache │ │ ├── AuthJWT.csproj.FileListAbsolute.txt │ │ ├── AuthJWT.csprojAssemblyReference.cache │ │ ├── AuthJWT.dll │ │ └── AuthJWT.pdb │ └── project.assets.json ├── README.md ├── RoleBased ├── AuthJWT.sln ├── AuthJWT.sln.DotSettings.user └── AuthJWT │ ├── AuthJWT.csproj │ ├── Config │ ├── AppSettings.cs │ └── Extentions │ │ ├── AuthenticationExtention.cs │ │ └── SwaggerExtention.cs │ ├── Controllers │ └── UserController.cs │ ├── DtoModels │ └── UserDto.cs │ ├── Entities │ └── User.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Services │ └── UserService │ │ ├── IUserService.cs │ │ └── UserService.cs │ ├── Startup.cs │ ├── appsettings.Development.json │ ├── appsettings.json │ ├── bin │ └── Debug │ │ └── netcoreapp2.2 │ │ ├── AuthJWT.deps.json │ │ ├── AuthJWT.dll │ │ ├── AuthJWT.pdb │ │ ├── AuthJWT.runtimeconfig.dev.json │ │ ├── AuthJWT.runtimeconfig.json │ │ ├── Properties │ │ └── launchSettings.json │ │ ├── appsettings.Development.json │ │ └── appsettings.json │ └── obj │ ├── AuthJWT.csproj.nuget.cache │ ├── AuthJWT.csproj.nuget.dgspec.json │ ├── AuthJWT.csproj.nuget.g.props │ ├── AuthJWT.csproj.nuget.g.targets │ ├── Debug │ └── netcoreapp2.2 │ │ ├── AuthJWT.AssemblyInfo.cs │ │ ├── AuthJWT.AssemblyInfoInputs.cache │ │ ├── AuthJWT.RazorAssemblyInfo.cache │ │ ├── AuthJWT.RazorAssemblyInfo.cs │ │ ├── AuthJWT.RazorTargetAssemblyInfo.cache │ │ ├── AuthJWT.assets.cache │ │ ├── AuthJWT.csproj.CoreCompileInputs.cache │ │ ├── AuthJWT.csproj.FileListAbsolute.txt │ │ ├── AuthJWT.csprojAssemblyReference.cache │ │ ├── AuthJWT.dll │ │ └── AuthJWT.pdb │ └── project.assets.json └── RoleToPermissionBased ├── AuthJWT.sln ├── AuthJWT.sln.DotSettings.user └── AuthJWT ├── AuthJWT.csproj ├── Config ├── AppSettings.cs ├── Extentions │ ├── AuthenticationExtention.cs │ └── SwaggerExtention.cs └── Permissions │ ├── AuthorizationPolicyProvider.cs │ ├── PermissionAuthorizeAttribute.cs │ └── Permissions.cs ├── Controllers └── UserController.cs ├── DtoModels └── UserDto.cs ├── Entities ├── Role.cs └── User.cs ├── Program.cs ├── Properties └── launchSettings.json ├── Services └── UserService │ ├── IUserService.cs │ └── UserService.cs ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json ├── bin └── Debug │ └── netcoreapp2.2 │ ├── AuthJWT.deps.json │ ├── AuthJWT.dll │ ├── AuthJWT.pdb │ ├── AuthJWT.runtimeconfig.dev.json │ ├── AuthJWT.runtimeconfig.json │ ├── Properties │ └── launchSettings.json │ ├── appsettings.Development.json │ └── appsettings.json └── obj ├── AuthJWT.csproj.nuget.cache ├── AuthJWT.csproj.nuget.dgspec.json ├── AuthJWT.csproj.nuget.g.props ├── AuthJWT.csproj.nuget.g.targets ├── Debug └── netcoreapp2.2 │ ├── AuthJWT.AssemblyInfo.cs │ ├── AuthJWT.AssemblyInfoInputs.cache │ ├── AuthJWT.RazorAssemblyInfo.cache │ ├── AuthJWT.RazorAssemblyInfo.cs │ ├── AuthJWT.RazorTargetAssemblyInfo.cache │ ├── AuthJWT.assets.cache │ ├── AuthJWT.csproj.CoreCompileInputs.cache │ ├── AuthJWT.csproj.FileListAbsolute.txt │ ├── AuthJWT.csprojAssemblyReference.cache │ ├── AuthJWT.dll │ └── AuthJWT.pdb └── project.assets.json /ClaimBased/AuthJWT.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28803.352 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AuthJWT", "AuthJWT\AuthJWT.csproj", "{768D6249-9A5F-4137-9159-0D332DB8674E}" 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 | {768D6249-9A5F-4137-9159-0D332DB8674E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {768D6249-9A5F-4137-9159-0D332DB8674E}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {768D6249-9A5F-4137-9159-0D332DB8674E}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {768D6249-9A5F-4137-9159-0D332DB8674E}.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 = {7F036B04-C1C5-4372-B639-881D3526DF67} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /ClaimBased/AuthJWT.sln.DotSettings.user: -------------------------------------------------------------------------------- 1 |  2 | 2 -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/AuthJWT.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.2 5 | InProcess 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/Config/AppSettings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AuthJWT.Config 7 | { 8 | public class AppSettings 9 | { 10 | public string Secret { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/Config/Extentions/AuthenticationExtention.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Authentication.JwtBearer; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.IdentityModel.Tokens; 10 | 11 | namespace AuthJWT.Config.Extentions 12 | { 13 | public static class AuthenticationExtention 14 | { 15 | public static IServiceCollection AddOurAuthentication(this IServiceCollection services, 16 | AppSettings appSettings) 17 | { 18 | // Authorization service 19 | services.AddAuthorization(options => 20 | { 21 | options.AddPolicy("GetAllUser", 22 | policy => policy.RequireClaim("AccessAllUser", "True")); 23 | }); 24 | 25 | // JWT Authentication 26 | var key = Encoding.ASCII.GetBytes(appSettings.Secret); 27 | services.AddAuthentication(options => 28 | { 29 | options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; 30 | options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; 31 | }) 32 | .AddJwtBearer(options => 33 | { 34 | options.RequireHttpsMetadata = false; 35 | options.SaveToken = true; 36 | options.TokenValidationParameters = new TokenValidationParameters 37 | { 38 | ValidateIssuerSigningKey = true, 39 | IssuerSigningKey = new SymmetricSecurityKey(key), 40 | ValidateIssuer = false, 41 | ValidateAudience = false 42 | }; 43 | }); 44 | return services; 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/Config/Extentions/SwaggerExtention.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.Extensions.DependencyInjection; 6 | using Swashbuckle.AspNetCore.Swagger; 7 | 8 | namespace AuthJWT.Config.Extentions 9 | { 10 | public static class SwaggerExtention 11 | { 12 | public static IServiceCollection AddOurSwaager(this IServiceCollection services) 13 | { 14 | // Swagger service properties 15 | services.AddSwaggerGen(c => 16 | { 17 | c.SwaggerDoc("v1", new Info 18 | { 19 | Version = "v1", 20 | Title = "Auth JWT", 21 | Description = "Auth JWT Demo - angular-netcore.ir", 22 | TermsOfService = "None", 23 | Contact = new Contact() 24 | { 25 | Name = "Mohammad Moein Fazeli", 26 | Email = "mmfazeli372@gmail.com", 27 | Url = "http://www.angular-netcore.ir" 28 | } 29 | }); 30 | c.AddSecurityDefinition("Bearer", new ApiKeyScheme() 31 | { 32 | Description = "JWT Authorization header {token}", 33 | Name = "Authorization", 34 | In = "header", 35 | Type = "apiKey" 36 | }); 37 | c.AddSecurityRequirement(new Dictionary> 38 | { 39 | { "Bearer", new string[] { } } 40 | }); 41 | }); 42 | return services; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/Controllers/UserController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using AuthJWT.DtoModels; 6 | using AuthJWT.Entities; 7 | using AuthJWT.Services.UserService; 8 | using Microsoft.AspNetCore.Authorization; 9 | using Microsoft.AspNetCore.Mvc; 10 | 11 | // For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 12 | 13 | namespace AuthJWT.Controllers 14 | { 15 | [Authorize] 16 | [ApiController] 17 | [Route("api/[Controller]")] 18 | public class UserController : Controller 19 | { 20 | private readonly IUserService _userService; 21 | 22 | public UserController(IUserService userService) 23 | { 24 | _userService = userService; 25 | } 26 | 27 | [AllowAnonymous] 28 | [HttpPost("login")] 29 | public User Login([FromBody] UserDto user) 30 | { 31 | var User = _userService.Authenticate(user.Username, user.Password); 32 | 33 | return User; 34 | } 35 | 36 | [Authorize(Policy = "GetAllUser")] 37 | [HttpGet("all")] 38 | public IEnumerable GetAllUser () 39 | { 40 | return _userService.GetAll(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/DtoModels/UserDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AuthJWT.DtoModels 7 | { 8 | public class UserDto 9 | { 10 | public string Username { get; set; } 11 | public string Password { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/Entities/User.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AuthJWT.Entities 7 | { 8 | public class User 9 | { 10 | public int Id { get; set; } 11 | public string FirstName { get; set; } 12 | public string LastName { get; set; } 13 | public string Username { get; set; } 14 | public string Password { get; set; } 15 | public string Token { get; set; } 16 | public bool AccessAllUser { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace AuthJWT 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateWebHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:63136", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "launchUrl": "swagger", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "AuthJWT": { 20 | "commandName": "Project", 21 | "launchBrowser": true, 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | }, 25 | "applicationUrl": "http://localhost:5000" 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/Services/UserService/IUserService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using AuthJWT.Entities; 3 | 4 | namespace AuthJWT.Services.UserService 5 | { 6 | public interface IUserService 7 | { 8 | User Authenticate(string username, string password); 9 | IEnumerable GetAll(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/Services/UserService/UserService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IdentityModel.Tokens.Jwt; 4 | using System.Linq; 5 | using System.Security.Claims; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using AuthJWT.Config; 9 | using AuthJWT.Entities; 10 | using Microsoft.Extensions.Options; 11 | using Microsoft.IdentityModel.Tokens; 12 | 13 | namespace AuthJWT.Services.UserService 14 | { 15 | public class UserService : IUserService 16 | { 17 | private readonly List _users = new List 18 | { 19 | new User 20 | { 21 | Id = 1, FirstName = "moein", LastName = "fazeli", Username = "user1", Password = "1234", 22 | AccessAllUser = true 23 | }, 24 | new User 25 | { 26 | Id = 2, FirstName = "hassan", LastName = "saeedi", Username = "user2", Password = "1234", 27 | AccessAllUser = true 28 | } 29 | }; 30 | 31 | private readonly AppSettings _appSettings; 32 | 33 | public UserService(IOptions appSettings) 34 | { 35 | _appSettings = appSettings.Value; 36 | } 37 | 38 | public User Authenticate(string username, string password) 39 | { 40 | var user = _users.SingleOrDefault(x => x.Username == username && x.Password == password); 41 | 42 | // return null if user not found 43 | if (user == null) 44 | return null; 45 | 46 | // authentication successful so generate jwt token 47 | var tokenHandler = new JwtSecurityTokenHandler(); 48 | var key = Encoding.ASCII.GetBytes(_appSettings.Secret); 49 | var claims = new ClaimsIdentity(); 50 | claims.AddClaims(new[] 51 | { 52 | new Claim("AccessAllUser", user.AccessAllUser.ToString()) 53 | }); 54 | var tokenDescriptor = new SecurityTokenDescriptor 55 | { 56 | Subject = claims, 57 | Expires = DateTime.UtcNow.AddDays(7), 58 | SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), 59 | SecurityAlgorithms.HmacSha256Signature) 60 | }; 61 | var token = tokenHandler.CreateToken(tokenDescriptor); 62 | user.Token = tokenHandler.WriteToken(token); 63 | 64 | // remove password before returning 65 | user.Password = null; 66 | 67 | return user; 68 | } 69 | 70 | public IEnumerable GetAll() 71 | { 72 | return _users.ToList(); 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/Startup.cs: -------------------------------------------------------------------------------- 1 | using AuthJWT.Config; 2 | using AuthJWT.Config.Extentions; 3 | using AuthJWT.Services.UserService; 4 | using Microsoft.AspNetCore.Builder; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.DependencyInjection; 8 | 9 | namespace AuthJWT 10 | { 11 | public class Startup 12 | { 13 | private readonly IConfiguration _configuration; 14 | 15 | public Startup(IConfiguration configuration) 16 | { 17 | _configuration = configuration; 18 | } 19 | 20 | public void ConfigureServices(IServiceCollection services) 21 | { 22 | // configure strongly typed settings objects 23 | var appSettingsSection = _configuration.GetSection("AppSettings"); 24 | services.Configure(appSettingsSection); 25 | 26 | // configure jwt authentication 27 | var appSettings = appSettingsSection.Get(); 28 | services.AddOurAuthentication(appSettings); 29 | services.AddOurSwaager(); 30 | 31 | // DI services 32 | services.AddScoped(); 33 | 34 | services.AddMvc(); 35 | } 36 | 37 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 38 | { 39 | if (env.IsDevelopment()) 40 | { 41 | app.UseDeveloperExceptionPage(); 42 | } 43 | 44 | app.UseAuthentication(); 45 | 46 | app.UseMvc(); 47 | app.UseSwagger(); 48 | app.UseSwaggerUI(c => 49 | { 50 | c.SwaggerEndpoint("/swagger/v1/swagger.json", "v1"); 51 | }); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "AppSettings": { 3 | "Secret": "This is the secret key and its very important" 4 | }, 5 | "Logging": { 6 | "LogLevel": { 7 | "Default": "Warning" 8 | } 9 | }, 10 | "AllowedHosts": "*" 11 | } 12 | -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/bin/Debug/netcoreapp2.2/AuthJWT.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohammadMoeinFazeli/ASP.NetCore-AllAuthorizationMethods/7e051867f456d68b750c8d0a2dc95c5a70c047ba/ClaimBased/AuthJWT/bin/Debug/netcoreapp2.2/AuthJWT.dll -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/bin/Debug/netcoreapp2.2/AuthJWT.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohammadMoeinFazeli/ASP.NetCore-AllAuthorizationMethods/7e051867f456d68b750c8d0a2dc95c5a70c047ba/ClaimBased/AuthJWT/bin/Debug/netcoreapp2.2/AuthJWT.pdb -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/bin/Debug/netcoreapp2.2/AuthJWT.runtimeconfig.dev.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtimeOptions": { 3 | "additionalProbingPaths": [ 4 | "C:\\Users\\MoeinFazeli\\.dotnet\\store\\|arch|\\|tfm|", 5 | "C:\\Users\\MoeinFazeli\\.nuget\\packages", 6 | "C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder" 7 | ] 8 | } 9 | } -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/bin/Debug/netcoreapp2.2/AuthJWT.runtimeconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtimeOptions": { 3 | "tfm": "netcoreapp2.2", 4 | "framework": { 5 | "name": "Microsoft.AspNetCore.App", 6 | "version": "2.2.0" 7 | }, 8 | "configProperties": { 9 | "System.GC.Server": true 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/bin/Debug/netcoreapp2.2/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:63136", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "launchUrl": "swagger", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "AuthJWT": { 20 | "commandName": "Project", 21 | "launchBrowser": true, 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | }, 25 | "applicationUrl": "http://localhost:5000" 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/bin/Debug/netcoreapp2.2/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/bin/Debug/netcoreapp2.2/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "AppSettings": { 3 | "Secret": "This is the secret key and its very important" 4 | }, 5 | "Logging": { 6 | "LogLevel": { 7 | "Default": "Warning" 8 | } 9 | }, 10 | "AllowedHosts": "*" 11 | } 12 | -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/obj/AuthJWT.csproj.nuget.cache: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "dgSpecHash": "IQ9yL6QkILGDRlBHckiNsfxAZISSuUAoCC9zgw/WNixxMQKC26WUw4/9Lz/eWw2ZMfNzvGXdBy21oF9f/jvPxw==", 4 | "success": true 5 | } -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/obj/AuthJWT.csproj.nuget.dgspec.json: -------------------------------------------------------------------------------- 1 | { 2 | "format": 1, 3 | "restore": { 4 | "D:\\_LearnToday\\ASP.net Core\\AuthJWT\\AuthJWT\\AuthJWT.csproj": {} 5 | }, 6 | "projects": { 7 | "D:\\_LearnToday\\ASP.net Core\\AuthJWT\\AuthJWT\\AuthJWT.csproj": { 8 | "version": "1.0.0", 9 | "restore": { 10 | "projectUniqueName": "D:\\_LearnToday\\ASP.net Core\\AuthJWT\\AuthJWT\\AuthJWT.csproj", 11 | "projectName": "AuthJWT", 12 | "projectPath": "D:\\_LearnToday\\ASP.net Core\\AuthJWT\\AuthJWT\\AuthJWT.csproj", 13 | "packagesPath": "C:\\Users\\MoeinFazeli\\.nuget\\packages\\", 14 | "outputPath": "D:\\_LearnToday\\ASP.net Core\\AuthJWT\\AuthJWT\\obj\\", 15 | "projectStyle": "PackageReference", 16 | "fallbackFolders": [ 17 | "C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder" 18 | ], 19 | "configFilePaths": [ 20 | "C:\\Users\\MoeinFazeli\\AppData\\Roaming\\NuGet\\NuGet.Config", 21 | "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config" 22 | ], 23 | "originalTargetFrameworks": [ 24 | "netcoreapp2.2" 25 | ], 26 | "sources": { 27 | "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {}, 28 | "https://api.nuget.org/v3/index.json": {} 29 | }, 30 | "frameworks": { 31 | "netcoreapp2.2": { 32 | "projectReferences": {} 33 | } 34 | }, 35 | "warningProperties": { 36 | "warnAsError": [ 37 | "NU1605" 38 | ] 39 | } 40 | }, 41 | "frameworks": { 42 | "netcoreapp2.2": { 43 | "dependencies": { 44 | "Microsoft.AspNetCore.App": { 45 | "suppressParent": "All", 46 | "target": "Package", 47 | "version": "[2.2.0, )", 48 | "autoReferenced": true 49 | }, 50 | "Microsoft.AspNetCore.Razor.Design": { 51 | "suppressParent": "All", 52 | "target": "Package", 53 | "version": "[2.2.0, )" 54 | }, 55 | "Microsoft.NETCore.App": { 56 | "suppressParent": "All", 57 | "target": "Package", 58 | "version": "[2.2.0, )", 59 | "autoReferenced": true 60 | }, 61 | "Swashbuckle.AspNetCore": { 62 | "target": "Package", 63 | "version": "[4.0.1, )" 64 | } 65 | }, 66 | "imports": [ 67 | "net461", 68 | "net462", 69 | "net47", 70 | "net471", 71 | "net472", 72 | "net48" 73 | ], 74 | "assetTargetFallback": true, 75 | "warn": true 76 | } 77 | } 78 | } 79 | } 80 | } -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/obj/AuthJWT.csproj.nuget.g.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | True 5 | NuGet 6 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\project.assets.json 7 | $(UserProfile)\.nuget\packages\ 8 | C:\Users\MoeinFazeli\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder 9 | PackageReference 10 | 5.0.0 11 | 12 | 13 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.entityframeworkcore.tools\2.2.0 26 | C:\Users\MoeinFazeli\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0 27 | C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.razor.design\2.2.0 28 | 29 | -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/obj/AuthJWT.csproj.nuget.g.targets: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | using System; 12 | using System.Reflection; 13 | 14 | [assembly: System.Reflection.AssemblyCompanyAttribute("AuthJWT")] 15 | [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] 16 | [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] 17 | [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] 18 | [assembly: System.Reflection.AssemblyProductAttribute("AuthJWT")] 19 | [assembly: System.Reflection.AssemblyTitleAttribute("AuthJWT")] 20 | [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] 21 | 22 | // Generated by the MSBuild WriteCodeFragment class. 23 | 24 | -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.AssemblyInfoInputs.cache: -------------------------------------------------------------------------------- 1 | e98e1728c7d46036ecf157fac43ce5850b035eaa 2 | -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.RazorAssemblyInfo.cache: -------------------------------------------------------------------------------- 1 | 54b1e93c7698f925dcab5c3998494f88511fd105 2 | -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.RazorAssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | using System; 12 | using System.Reflection; 13 | 14 | [assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.RelatedAssemblyAttribute("AuthJWT.Views")] 15 | [assembly: Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute("2.1")] 16 | [assembly: Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute("MVC-2.1")] 17 | [assembly: Microsoft.AspNetCore.Razor.Hosting.RazorExtensionAssemblyNameAttribute("MVC-2.1", "Microsoft.AspNetCore.Mvc.Razor.Extensions")] 18 | 19 | // Generated by the MSBuild WriteCodeFragment class. 20 | 21 | -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.RazorTargetAssemblyInfo.cache: -------------------------------------------------------------------------------- 1 | a13c668074c643d342d6dd4176c238c701b45c02 2 | -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.assets.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohammadMoeinFazeli/ASP.NetCore-AllAuthorizationMethods/7e051867f456d68b750c8d0a2dc95c5a70c047ba/ClaimBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.assets.cache -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.csproj.CoreCompileInputs.cache: -------------------------------------------------------------------------------- 1 | 530ad0946519dbe76237bb6861c1afd193c3aa3f 2 | -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\appsettings.Development.json 2 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\appsettings.json 3 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\Properties\launchSettings.json 4 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\AuthJWT.deps.json 5 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\AuthJWT.runtimeconfig.json 6 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\AuthJWT.runtimeconfig.dev.json 7 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\AuthJWT.dll 8 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.csprojAssemblyReference.cache 9 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.csproj.CoreCompileInputs.cache 10 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.RazorAssemblyInfo.cache 11 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.RazorAssemblyInfo.cs 12 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.AssemblyInfoInputs.cache 13 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.AssemblyInfo.cs 14 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.RazorTargetAssemblyInfo.cache 15 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\AuthJWT.pdb 16 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.dll 17 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.pdb 18 | -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.csprojAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohammadMoeinFazeli/ASP.NetCore-AllAuthorizationMethods/7e051867f456d68b750c8d0a2dc95c5a70c047ba/ClaimBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.csprojAssemblyReference.cache -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohammadMoeinFazeli/ASP.NetCore-AllAuthorizationMethods/7e051867f456d68b750c8d0a2dc95c5a70c047ba/ClaimBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.dll -------------------------------------------------------------------------------- /ClaimBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohammadMoeinFazeli/ASP.NetCore-AllAuthorizationMethods/7e051867f456d68b750c8d0a2dc95c5a70c047ba/ClaimBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.pdb -------------------------------------------------------------------------------- /PermissionBased/AuthJWT.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28803.352 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AuthJWT", "AuthJWT\AuthJWT.csproj", "{768D6249-9A5F-4137-9159-0D332DB8674E}" 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 | {768D6249-9A5F-4137-9159-0D332DB8674E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {768D6249-9A5F-4137-9159-0D332DB8674E}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {768D6249-9A5F-4137-9159-0D332DB8674E}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {768D6249-9A5F-4137-9159-0D332DB8674E}.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 = {7F036B04-C1C5-4372-B639-881D3526DF67} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT.sln.DotSettings.user: -------------------------------------------------------------------------------- 1 |  2 | 2 -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/AuthJWT.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.2 5 | InProcess 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/Config/AppSettings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AuthJWT.Config 7 | { 8 | public class AppSettings 9 | { 10 | public string Secret { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/Config/Extentions/AuthenticationExtention.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Authentication.JwtBearer; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.IdentityModel.Tokens; 10 | 11 | namespace AuthJWT.Config.Extentions 12 | { 13 | public static class AuthenticationExtention 14 | { 15 | public static IServiceCollection AddOurAuthentication(this IServiceCollection services, 16 | AppSettings appSettings) 17 | { 18 | // Authorization service 19 | //services.AddAuthorization(options => 20 | //{ 21 | // options.AddPolicy("GetAllUser", 22 | // policy => policy.RequireClaim("AccessAllUser", "True")); 23 | //}); 24 | 25 | // JWT Authentication 26 | var key = Encoding.ASCII.GetBytes(appSettings.Secret); 27 | services.AddAuthentication(options => 28 | { 29 | options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; 30 | options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; 31 | }) 32 | .AddJwtBearer(options => 33 | { 34 | options.RequireHttpsMetadata = false; 35 | options.SaveToken = true; 36 | options.TokenValidationParameters = new TokenValidationParameters 37 | { 38 | ValidateIssuerSigningKey = true, 39 | IssuerSigningKey = new SymmetricSecurityKey(key), 40 | ValidateIssuer = false, 41 | ValidateAudience = false 42 | }; 43 | }); 44 | return services; 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/Config/Extentions/SwaggerExtention.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.Extensions.DependencyInjection; 6 | using Swashbuckle.AspNetCore.Swagger; 7 | 8 | namespace AuthJWT.Config.Extentions 9 | { 10 | public static class SwaggerExtention 11 | { 12 | public static IServiceCollection AddOurSwaager(this IServiceCollection services) 13 | { 14 | // Swagger service properties 15 | services.AddSwaggerGen(c => 16 | { 17 | c.SwaggerDoc("v1", new Info 18 | { 19 | Version = "v1", 20 | Title = "Auth JWT", 21 | Description = "Auth JWT Demo - angular-netcore.ir", 22 | TermsOfService = "None", 23 | Contact = new Contact() 24 | { 25 | Name = "Mohammad Moein Fazeli", 26 | Email = "mmfazeli372@gmail.com", 27 | Url = "http://www.angular-netcore.ir" 28 | } 29 | }); 30 | c.AddSecurityDefinition("Bearer", new ApiKeyScheme() 31 | { 32 | Description = "JWT Authorization header {token}", 33 | Name = "Authorization", 34 | In = "header", 35 | Type = "apiKey" 36 | }); 37 | c.AddSecurityRequirement(new Dictionary> 38 | { 39 | { "Bearer", new string[] { } } 40 | }); 41 | }); 42 | return services; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/Config/Permissions/AuthorizationPolicyProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Authorization; 6 | using Microsoft.Extensions.Options; 7 | 8 | namespace AuthJWT.Config.Permissions 9 | { 10 | public class AuthorizationPolicyProvider : DefaultAuthorizationPolicyProvider 11 | { 12 | public AuthorizationPolicyProvider(IOptions options) 13 | : base(options) 14 | { 15 | } 16 | 17 | public override Task GetPolicyAsync(string policyName) 18 | { 19 | if (!policyName.StartsWith(PermissionAuthorizeAttribute.PolicyPrefix, StringComparison.OrdinalIgnoreCase)) 20 | { 21 | return base.GetPolicyAsync(policyName); 22 | } 23 | 24 | var permissionNames = policyName.Substring(PermissionAuthorizeAttribute.PolicyPrefix.Length).Split(','); 25 | 26 | var policy = new AuthorizationPolicyBuilder() 27 | .RequireClaim(Permissions.Permission, permissionNames) 28 | .Build(); 29 | 30 | return Task.FromResult(policy); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/Config/Permissions/PermissionAuthorizeAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Authorization; 6 | 7 | namespace AuthJWT.Config.Permissions 8 | { 9 | public class PermissionAuthorizeAttribute : AuthorizeAttribute 10 | { 11 | internal const string PolicyPrefix = "PERMISSION:"; 12 | public PermissionAuthorizeAttribute(params string[] permissions) 13 | { 14 | Policy = $"{PolicyPrefix}{string.Join(",", permissions)}"; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/Config/Permissions/Permissions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AuthJWT.Config.Permissions 7 | { 8 | public static class Permissions 9 | { 10 | public static string Permission = "Permissions"; 11 | 12 | public static class User 13 | { 14 | public const string GetAll = "Permissions.User.GetAll"; 15 | public const string CheckUser = "Permissions.User.CheckUser"; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/Controllers/UserController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using AuthJWT.Config.Permissions; 6 | using AuthJWT.DtoModels; 7 | using AuthJWT.Entities; 8 | using AuthJWT.Services.UserService; 9 | using Microsoft.AspNetCore.Authorization; 10 | using Microsoft.AspNetCore.Mvc; 11 | 12 | // For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 13 | 14 | namespace AuthJWT.Controllers 15 | { 16 | [Authorize] 17 | [ApiController] 18 | [Route("api/[Controller]")] 19 | public class UserController : Controller 20 | { 21 | private readonly IUserService _userService; 22 | 23 | public UserController(IUserService userService) 24 | { 25 | _userService = userService; 26 | } 27 | 28 | [AllowAnonymous] 29 | [HttpPost("login")] 30 | public User Login([FromBody] UserDto user) 31 | { 32 | var User = _userService.Authenticate(user.Username, user.Password); 33 | 34 | return User; 35 | } 36 | 37 | [PermissionAuthorize(Permissions.User.GetAll)] 38 | [HttpGet("all")] 39 | public IEnumerable GetAllUser () 40 | { 41 | return _userService.GetAll(); 42 | } 43 | 44 | [PermissionAuthorize(Permissions.User.CheckUser)] 45 | [HttpGet("checkUser")] 46 | public string CheckUser() 47 | { 48 | return "Hello You have the right access"; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/DtoModels/UserDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AuthJWT.DtoModels 7 | { 8 | public class UserDto 9 | { 10 | public string Username { get; set; } 11 | public string Password { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/Entities/User.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AuthJWT.Entities 7 | { 8 | public class User 9 | { 10 | public int Id { get; set; } 11 | public string FirstName { get; set; } 12 | public string LastName { get; set; } 13 | public string Username { get; set; } 14 | public string Password { get; set; } 15 | public string Token { get; set; } 16 | public string[] Permissions { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace AuthJWT 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateWebHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:63136", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "launchUrl": "swagger", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "AuthJWT": { 20 | "commandName": "Project", 21 | "launchBrowser": true, 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | }, 25 | "applicationUrl": "http://localhost:5000" 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/Services/UserService/IUserService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using AuthJWT.Entities; 3 | 4 | namespace AuthJWT.Services.UserService 5 | { 6 | public interface IUserService 7 | { 8 | User Authenticate(string username, string password); 9 | IEnumerable GetAll(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/Services/UserService/UserService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IdentityModel.Tokens.Jwt; 4 | using System.Linq; 5 | using System.Security.Claims; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using AuthJWT.Config; 9 | using AuthJWT.Config.Permissions; 10 | using AuthJWT.Entities; 11 | using Microsoft.Extensions.Options; 12 | using Microsoft.IdentityModel.Tokens; 13 | 14 | namespace AuthJWT.Services.UserService 15 | { 16 | public class UserService : IUserService 17 | { 18 | private readonly List _users = new List 19 | { 20 | new User 21 | { 22 | Id = 1, FirstName = "moein", LastName = "fazeli", Username = "user1", Password = "1234", 23 | Permissions = new string[] { "Permissions.User.GetAll" } 24 | }, 25 | new User 26 | { 27 | Id = 2, FirstName = "hassan", LastName = "saeedi", Username = "user2", Password = "1234", 28 | Permissions = new string[] { "Permissions.User.CheckUser" } 29 | } 30 | }; 31 | 32 | private readonly AppSettings _appSettings; 33 | 34 | public UserService(IOptions appSettings) 35 | { 36 | _appSettings = appSettings.Value; 37 | } 38 | 39 | public User Authenticate(string username, string password) 40 | { 41 | var user = _users.SingleOrDefault(x => x.Username == username && x.Password == password); 42 | 43 | // return null if user not found 44 | if (user == null) 45 | return null; 46 | 47 | // authentication successful so generate jwt token 48 | var tokenHandler = new JwtSecurityTokenHandler(); 49 | var key = Encoding.ASCII.GetBytes(_appSettings.Secret); 50 | var claims = new ClaimsIdentity(); 51 | foreach (var permission in user.Permissions) 52 | { 53 | claims.AddClaims(new[] 54 | { 55 | new Claim(Permissions.Permission, permission) 56 | }); 57 | } 58 | var tokenDescriptor = new SecurityTokenDescriptor 59 | { 60 | Subject = claims, 61 | Expires = DateTime.UtcNow.AddDays(7), 62 | SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), 63 | SecurityAlgorithms.HmacSha256Signature) 64 | }; 65 | var token = tokenHandler.CreateToken(tokenDescriptor); 66 | user.Token = tokenHandler.WriteToken(token); 67 | 68 | // remove password before returning 69 | user.Password = null; 70 | 71 | return user; 72 | } 73 | 74 | public IEnumerable GetAll() 75 | { 76 | return _users.ToList(); 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/Startup.cs: -------------------------------------------------------------------------------- 1 | using AuthJWT.Config; 2 | using AuthJWT.Config.Extentions; 3 | using AuthJWT.Config.Permissions; 4 | using AuthJWT.Services.UserService; 5 | using Microsoft.AspNetCore.Authorization; 6 | using Microsoft.AspNetCore.Builder; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.DependencyInjection; 10 | 11 | namespace AuthJWT 12 | { 13 | public class Startup 14 | { 15 | private readonly IConfiguration _configuration; 16 | 17 | public Startup(IConfiguration configuration) 18 | { 19 | _configuration = configuration; 20 | } 21 | 22 | public void ConfigureServices(IServiceCollection services) 23 | { 24 | // configure strongly typed settings objects 25 | var appSettingsSection = _configuration.GetSection("AppSettings"); 26 | services.Configure(appSettingsSection); 27 | 28 | // configure jwt authentication 29 | var appSettings = appSettingsSection.Get(); 30 | services.AddOurAuthentication(appSettings); 31 | services.AddOurSwaager(); 32 | 33 | // DI services 34 | services.AddScoped(); 35 | services.AddSingleton(); 36 | 37 | services.AddMvc(); 38 | } 39 | 40 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 41 | { 42 | if (env.IsDevelopment()) 43 | { 44 | app.UseDeveloperExceptionPage(); 45 | } 46 | 47 | app.UseAuthentication(); 48 | 49 | app.UseMvc(); 50 | app.UseSwagger(); 51 | app.UseSwaggerUI(c => 52 | { 53 | c.SwaggerEndpoint("/swagger/v1/swagger.json", "v1"); 54 | }); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "AppSettings": { 3 | "Secret": "This is the secret key and its very important" 4 | }, 5 | "Logging": { 6 | "LogLevel": { 7 | "Default": "Warning" 8 | } 9 | }, 10 | "AllowedHosts": "*" 11 | } 12 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/bin/Debug/netcoreapp2.2/AuthJWT.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohammadMoeinFazeli/ASP.NetCore-AllAuthorizationMethods/7e051867f456d68b750c8d0a2dc95c5a70c047ba/PermissionBased/AuthJWT/bin/Debug/netcoreapp2.2/AuthJWT.dll -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/bin/Debug/netcoreapp2.2/AuthJWT.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohammadMoeinFazeli/ASP.NetCore-AllAuthorizationMethods/7e051867f456d68b750c8d0a2dc95c5a70c047ba/PermissionBased/AuthJWT/bin/Debug/netcoreapp2.2/AuthJWT.pdb -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/bin/Debug/netcoreapp2.2/AuthJWT.runtimeconfig.dev.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtimeOptions": { 3 | "additionalProbingPaths": [ 4 | "C:\\Users\\MoeinFazeli\\.dotnet\\store\\|arch|\\|tfm|", 5 | "C:\\Users\\MoeinFazeli\\.nuget\\packages", 6 | "C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder" 7 | ] 8 | } 9 | } -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/bin/Debug/netcoreapp2.2/AuthJWT.runtimeconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtimeOptions": { 3 | "tfm": "netcoreapp2.2", 4 | "framework": { 5 | "name": "Microsoft.AspNetCore.App", 6 | "version": "2.2.0" 7 | }, 8 | "configProperties": { 9 | "System.GC.Server": true 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/bin/Debug/netcoreapp2.2/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:63136", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "launchUrl": "swagger", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "AuthJWT": { 20 | "commandName": "Project", 21 | "launchBrowser": true, 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | }, 25 | "applicationUrl": "http://localhost:5000" 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/bin/Debug/netcoreapp2.2/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/bin/Debug/netcoreapp2.2/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "AppSettings": { 3 | "Secret": "This is the secret key and its very important" 4 | }, 5 | "Logging": { 6 | "LogLevel": { 7 | "Default": "Warning" 8 | } 9 | }, 10 | "AllowedHosts": "*" 11 | } 12 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/obj/AuthJWT.csproj.nuget.cache: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "dgSpecHash": "IQ9yL6QkILGDRlBHckiNsfxAZISSuUAoCC9zgw/WNixxMQKC26WUw4/9Lz/eWw2ZMfNzvGXdBy21oF9f/jvPxw==", 4 | "success": true 5 | } -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/obj/AuthJWT.csproj.nuget.dgspec.json: -------------------------------------------------------------------------------- 1 | { 2 | "format": 1, 3 | "restore": { 4 | "D:\\_LearnToday\\ASP.net Core\\AuthJWT\\AuthJWT\\AuthJWT.csproj": {} 5 | }, 6 | "projects": { 7 | "D:\\_LearnToday\\ASP.net Core\\AuthJWT\\AuthJWT\\AuthJWT.csproj": { 8 | "version": "1.0.0", 9 | "restore": { 10 | "projectUniqueName": "D:\\_LearnToday\\ASP.net Core\\AuthJWT\\AuthJWT\\AuthJWT.csproj", 11 | "projectName": "AuthJWT", 12 | "projectPath": "D:\\_LearnToday\\ASP.net Core\\AuthJWT\\AuthJWT\\AuthJWT.csproj", 13 | "packagesPath": "C:\\Users\\MoeinFazeli\\.nuget\\packages\\", 14 | "outputPath": "D:\\_LearnToday\\ASP.net Core\\AuthJWT\\AuthJWT\\obj\\", 15 | "projectStyle": "PackageReference", 16 | "fallbackFolders": [ 17 | "C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder" 18 | ], 19 | "configFilePaths": [ 20 | "C:\\Users\\MoeinFazeli\\AppData\\Roaming\\NuGet\\NuGet.Config", 21 | "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config" 22 | ], 23 | "originalTargetFrameworks": [ 24 | "netcoreapp2.2" 25 | ], 26 | "sources": { 27 | "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {}, 28 | "https://api.nuget.org/v3/index.json": {} 29 | }, 30 | "frameworks": { 31 | "netcoreapp2.2": { 32 | "projectReferences": {} 33 | } 34 | }, 35 | "warningProperties": { 36 | "warnAsError": [ 37 | "NU1605" 38 | ] 39 | } 40 | }, 41 | "frameworks": { 42 | "netcoreapp2.2": { 43 | "dependencies": { 44 | "Microsoft.AspNetCore.App": { 45 | "suppressParent": "All", 46 | "target": "Package", 47 | "version": "[2.2.0, )", 48 | "autoReferenced": true 49 | }, 50 | "Microsoft.AspNetCore.Razor.Design": { 51 | "suppressParent": "All", 52 | "target": "Package", 53 | "version": "[2.2.0, )" 54 | }, 55 | "Microsoft.NETCore.App": { 56 | "suppressParent": "All", 57 | "target": "Package", 58 | "version": "[2.2.0, )", 59 | "autoReferenced": true 60 | }, 61 | "Swashbuckle.AspNetCore": { 62 | "target": "Package", 63 | "version": "[4.0.1, )" 64 | } 65 | }, 66 | "imports": [ 67 | "net461", 68 | "net462", 69 | "net47", 70 | "net471", 71 | "net472", 72 | "net48" 73 | ], 74 | "assetTargetFallback": true, 75 | "warn": true 76 | } 77 | } 78 | } 79 | } 80 | } -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/obj/AuthJWT.csproj.nuget.g.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | True 5 | NuGet 6 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\project.assets.json 7 | $(UserProfile)\.nuget\packages\ 8 | C:\Users\MoeinFazeli\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder 9 | PackageReference 10 | 5.0.0 11 | 12 | 13 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.entityframeworkcore.tools\2.2.0 26 | C:\Users\MoeinFazeli\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0 27 | C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.razor.design\2.2.0 28 | 29 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/obj/AuthJWT.csproj.nuget.g.targets: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | using System; 12 | using System.Reflection; 13 | 14 | [assembly: System.Reflection.AssemblyCompanyAttribute("AuthJWT")] 15 | [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] 16 | [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] 17 | [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] 18 | [assembly: System.Reflection.AssemblyProductAttribute("AuthJWT")] 19 | [assembly: System.Reflection.AssemblyTitleAttribute("AuthJWT")] 20 | [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] 21 | 22 | // Generated by the MSBuild WriteCodeFragment class. 23 | 24 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.AssemblyInfoInputs.cache: -------------------------------------------------------------------------------- 1 | e98e1728c7d46036ecf157fac43ce5850b035eaa 2 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.RazorAssemblyInfo.cache: -------------------------------------------------------------------------------- 1 | 54b1e93c7698f925dcab5c3998494f88511fd105 2 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.RazorAssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | using System; 12 | using System.Reflection; 13 | 14 | [assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.RelatedAssemblyAttribute("AuthJWT.Views")] 15 | [assembly: Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute("2.1")] 16 | [assembly: Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute("MVC-2.1")] 17 | [assembly: Microsoft.AspNetCore.Razor.Hosting.RazorExtensionAssemblyNameAttribute("MVC-2.1", "Microsoft.AspNetCore.Mvc.Razor.Extensions")] 18 | 19 | // Generated by the MSBuild WriteCodeFragment class. 20 | 21 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.RazorTargetAssemblyInfo.cache: -------------------------------------------------------------------------------- 1 | a13c668074c643d342d6dd4176c238c701b45c02 2 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.assets.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohammadMoeinFazeli/ASP.NetCore-AllAuthorizationMethods/7e051867f456d68b750c8d0a2dc95c5a70c047ba/PermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.assets.cache -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.csproj.CoreCompileInputs.cache: -------------------------------------------------------------------------------- 1 | 8a421ef3c32768433a337260ea121676a7f4d0e8 2 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\appsettings.Development.json 2 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\appsettings.json 3 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\Properties\launchSettings.json 4 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\AuthJWT.deps.json 5 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\AuthJWT.runtimeconfig.json 6 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\AuthJWT.runtimeconfig.dev.json 7 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\AuthJWT.dll 8 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.csprojAssemblyReference.cache 9 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.csproj.CoreCompileInputs.cache 10 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.RazorAssemblyInfo.cache 11 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.RazorAssemblyInfo.cs 12 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.AssemblyInfoInputs.cache 13 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.AssemblyInfo.cs 14 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.RazorTargetAssemblyInfo.cache 15 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\AuthJWT.pdb 16 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.dll 17 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.pdb 18 | -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.csprojAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohammadMoeinFazeli/ASP.NetCore-AllAuthorizationMethods/7e051867f456d68b750c8d0a2dc95c5a70c047ba/PermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.csprojAssemblyReference.cache -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohammadMoeinFazeli/ASP.NetCore-AllAuthorizationMethods/7e051867f456d68b750c8d0a2dc95c5a70c047ba/PermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.dll -------------------------------------------------------------------------------- /PermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohammadMoeinFazeli/ASP.NetCore-AllAuthorizationMethods/7e051867f456d68b750c8d0a2dc95c5a70c047ba/PermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.pdb -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ASP.NetCore-AllAuthorizationMethods 2 | ## Visit http://angular-netcore.ir/آموزش-ویدئویی-کامل-authorization-و-authentication-در-asp-net-core-همراه-ب/ to view the description 3 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28803.352 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AuthJWT", "AuthJWT\AuthJWT.csproj", "{768D6249-9A5F-4137-9159-0D332DB8674E}" 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 | {768D6249-9A5F-4137-9159-0D332DB8674E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {768D6249-9A5F-4137-9159-0D332DB8674E}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {768D6249-9A5F-4137-9159-0D332DB8674E}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {768D6249-9A5F-4137-9159-0D332DB8674E}.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 = {7F036B04-C1C5-4372-B639-881D3526DF67} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT.sln.DotSettings.user: -------------------------------------------------------------------------------- 1 |  2 | 2 -------------------------------------------------------------------------------- /RoleBased/AuthJWT/AuthJWT.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.2 5 | InProcess 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT/Config/AppSettings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AuthJWT.Config 7 | { 8 | public class AppSettings 9 | { 10 | public string Secret { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT/Config/Extentions/AuthenticationExtention.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Authentication.JwtBearer; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.IdentityModel.Tokens; 10 | 11 | namespace AuthJWT.Config.Extentions 12 | { 13 | public static class AuthenticationExtention 14 | { 15 | public static IServiceCollection AddOurAuthentication(this IServiceCollection services, 16 | AppSettings appSettings) 17 | { 18 | // JWT Authentication 19 | var key = Encoding.ASCII.GetBytes(appSettings.Secret); 20 | services.AddAuthentication(options => 21 | { 22 | options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; 23 | options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; 24 | }) 25 | .AddJwtBearer(options => 26 | { 27 | options.RequireHttpsMetadata = false; 28 | options.SaveToken = true; 29 | options.TokenValidationParameters = new TokenValidationParameters 30 | { 31 | ValidateIssuerSigningKey = true, 32 | IssuerSigningKey = new SymmetricSecurityKey(key), 33 | ValidateIssuer = false, 34 | ValidateAudience = false 35 | }; 36 | }); 37 | return services; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT/Config/Extentions/SwaggerExtention.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.Extensions.DependencyInjection; 6 | using Swashbuckle.AspNetCore.Swagger; 7 | 8 | namespace AuthJWT.Config.Extentions 9 | { 10 | public static class SwaggerExtention 11 | { 12 | public static IServiceCollection AddOurSwaager(this IServiceCollection services) 13 | { 14 | // Swagger service properties 15 | services.AddSwaggerGen(c => 16 | { 17 | c.SwaggerDoc("v1", new Info 18 | { 19 | Version = "v1", 20 | Title = "Auth JWT", 21 | Description = "Auth JWT Demo - angular-netcore.ir", 22 | TermsOfService = "None", 23 | Contact = new Contact() 24 | { 25 | Name = "Mohammad Moein Fazeli", 26 | Email = "mmfazeli372@gmail.com", 27 | Url = "http://www.angular-netcore.ir" 28 | } 29 | }); 30 | c.AddSecurityDefinition("Bearer", new ApiKeyScheme() 31 | { 32 | Description = "JWT Authorization header {token}", 33 | Name = "Authorization", 34 | In = "header", 35 | Type = "apiKey" 36 | }); 37 | c.AddSecurityRequirement(new Dictionary> 38 | { 39 | { "Bearer", new string[] { } } 40 | }); 41 | }); 42 | return services; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT/Controllers/UserController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using AuthJWT.DtoModels; 6 | using AuthJWT.Entities; 7 | using AuthJWT.Services.UserService; 8 | using Microsoft.AspNetCore.Authorization; 9 | using Microsoft.AspNetCore.Mvc; 10 | 11 | // For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 12 | 13 | namespace AuthJWT.Controllers 14 | { 15 | [Authorize] 16 | [ApiController] 17 | [Route("api/[Controller]")] 18 | public class UserController : Controller 19 | { 20 | private readonly IUserService _userService; 21 | 22 | public UserController(IUserService userService) 23 | { 24 | _userService = userService; 25 | } 26 | 27 | [AllowAnonymous] 28 | [HttpPost("login")] 29 | public User Login([FromBody] UserDto user) 30 | { 31 | var User = _userService.Authenticate(user.Username, user.Password); 32 | 33 | return User; 34 | } 35 | 36 | [Authorize(Roles = "Admin")] 37 | [HttpGet("all")] 38 | public IEnumerable GetAllUser () 39 | { 40 | return _userService.GetAll(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT/DtoModels/UserDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AuthJWT.DtoModels 7 | { 8 | public class UserDto 9 | { 10 | public string Username { get; set; } 11 | public string Password { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT/Entities/User.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AuthJWT.Entities 7 | { 8 | public class User 9 | { 10 | public int Id { get; set; } 11 | public string FirstName { get; set; } 12 | public string LastName { get; set; } 13 | public string Username { get; set; } 14 | public string Password { get; set; } 15 | public string Token { get; set; } 16 | public string Role { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace AuthJWT 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateWebHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:63136", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "launchUrl": "swagger", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "AuthJWT": { 20 | "commandName": "Project", 21 | "launchBrowser": true, 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | }, 25 | "applicationUrl": "http://localhost:5000" 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /RoleBased/AuthJWT/Services/UserService/IUserService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using AuthJWT.Entities; 3 | 4 | namespace AuthJWT.Services.UserService 5 | { 6 | public interface IUserService 7 | { 8 | User Authenticate(string username, string password); 9 | IEnumerable GetAll(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT/Services/UserService/UserService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IdentityModel.Tokens.Jwt; 4 | using System.Linq; 5 | using System.Security.Claims; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using AuthJWT.Config; 9 | using AuthJWT.Entities; 10 | using Microsoft.Extensions.Options; 11 | using Microsoft.IdentityModel.Tokens; 12 | 13 | namespace AuthJWT.Services.UserService 14 | { 15 | public class UserService : IUserService 16 | { 17 | private readonly List _users = new List 18 | { 19 | new User 20 | { 21 | Id = 1, FirstName = "moein", LastName = "fazeli", Username = "admin", Password = "1234", 22 | Role = "Admin" 23 | }, 24 | new User 25 | { 26 | Id = 2, FirstName = "hassan", LastName = "saeedi", Username = "regularUser", Password = "1234", 27 | Role = "User" 28 | } 29 | }; 30 | 31 | private readonly AppSettings _appSettings; 32 | 33 | public UserService(IOptions appSettings) 34 | { 35 | _appSettings = appSettings.Value; 36 | } 37 | 38 | public User Authenticate(string username, string password) 39 | { 40 | var user = _users.SingleOrDefault(x => x.Username == username && x.Password == password); 41 | 42 | // return null if user not found 43 | if (user == null) 44 | return null; 45 | 46 | // authentication successful so generate jwt token 47 | var tokenHandler = new JwtSecurityTokenHandler(); 48 | var key = Encoding.ASCII.GetBytes(_appSettings.Secret); 49 | var claims = new ClaimsIdentity(); 50 | claims.AddClaims(new[] 51 | { 52 | new Claim(ClaimTypes.Role, user.Role.ToString()) 53 | }); 54 | var tokenDescriptor = new SecurityTokenDescriptor 55 | { 56 | Subject = claims, 57 | Expires = DateTime.UtcNow.AddDays(7), 58 | SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), 59 | SecurityAlgorithms.HmacSha256Signature) 60 | }; 61 | var token = tokenHandler.CreateToken(tokenDescriptor); 62 | user.Token = tokenHandler.WriteToken(token); 63 | 64 | // remove password before returning 65 | user.Password = null; 66 | 67 | return user; 68 | } 69 | 70 | public IEnumerable GetAll() 71 | { 72 | return _users.ToList(); 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /RoleBased/AuthJWT/Startup.cs: -------------------------------------------------------------------------------- 1 | using AuthJWT.Config; 2 | using AuthJWT.Config.Extentions; 3 | using AuthJWT.Services.UserService; 4 | using Microsoft.AspNetCore.Builder; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.DependencyInjection; 8 | 9 | namespace AuthJWT 10 | { 11 | public class Startup 12 | { 13 | private readonly IConfiguration _configuration; 14 | 15 | public Startup(IConfiguration configuration) 16 | { 17 | _configuration = configuration; 18 | } 19 | 20 | public void ConfigureServices(IServiceCollection services) 21 | { 22 | // configure strongly typed settings objects 23 | var appSettingsSection = _configuration.GetSection("AppSettings"); 24 | services.Configure(appSettingsSection); 25 | 26 | // configure jwt authentication 27 | var appSettings = appSettingsSection.Get(); 28 | services.AddOurAuthentication(appSettings); 29 | services.AddOurSwaager(); 30 | 31 | // DI services 32 | services.AddScoped(); 33 | 34 | services.AddMvc(); 35 | } 36 | 37 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 38 | { 39 | if (env.IsDevelopment()) 40 | { 41 | app.UseDeveloperExceptionPage(); 42 | } 43 | 44 | app.UseAuthentication(); 45 | 46 | app.UseMvc(); 47 | app.UseSwagger(); 48 | app.UseSwaggerUI(c => 49 | { 50 | c.SwaggerEndpoint("/swagger/v1/swagger.json", "v1"); 51 | }); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "AppSettings": { 3 | "Secret": "This is the secret key and its very important" 4 | }, 5 | "Logging": { 6 | "LogLevel": { 7 | "Default": "Warning" 8 | } 9 | }, 10 | "AllowedHosts": "*" 11 | } 12 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT/bin/Debug/netcoreapp2.2/AuthJWT.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohammadMoeinFazeli/ASP.NetCore-AllAuthorizationMethods/7e051867f456d68b750c8d0a2dc95c5a70c047ba/RoleBased/AuthJWT/bin/Debug/netcoreapp2.2/AuthJWT.dll -------------------------------------------------------------------------------- /RoleBased/AuthJWT/bin/Debug/netcoreapp2.2/AuthJWT.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohammadMoeinFazeli/ASP.NetCore-AllAuthorizationMethods/7e051867f456d68b750c8d0a2dc95c5a70c047ba/RoleBased/AuthJWT/bin/Debug/netcoreapp2.2/AuthJWT.pdb -------------------------------------------------------------------------------- /RoleBased/AuthJWT/bin/Debug/netcoreapp2.2/AuthJWT.runtimeconfig.dev.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtimeOptions": { 3 | "additionalProbingPaths": [ 4 | "C:\\Users\\MoeinFazeli\\.dotnet\\store\\|arch|\\|tfm|", 5 | "C:\\Users\\MoeinFazeli\\.nuget\\packages", 6 | "C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder" 7 | ] 8 | } 9 | } -------------------------------------------------------------------------------- /RoleBased/AuthJWT/bin/Debug/netcoreapp2.2/AuthJWT.runtimeconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtimeOptions": { 3 | "tfm": "netcoreapp2.2", 4 | "framework": { 5 | "name": "Microsoft.AspNetCore.App", 6 | "version": "2.2.0" 7 | }, 8 | "configProperties": { 9 | "System.GC.Server": true 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /RoleBased/AuthJWT/bin/Debug/netcoreapp2.2/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:63136", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "launchUrl": "swagger", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "AuthJWT": { 20 | "commandName": "Project", 21 | "launchBrowser": true, 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | }, 25 | "applicationUrl": "http://localhost:5000" 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /RoleBased/AuthJWT/bin/Debug/netcoreapp2.2/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT/bin/Debug/netcoreapp2.2/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "AppSettings": { 3 | "Secret": "This is the secret key and its very important" 4 | }, 5 | "Logging": { 6 | "LogLevel": { 7 | "Default": "Warning" 8 | } 9 | }, 10 | "AllowedHosts": "*" 11 | } 12 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT/obj/AuthJWT.csproj.nuget.cache: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "dgSpecHash": "IQ9yL6QkILGDRlBHckiNsfxAZISSuUAoCC9zgw/WNixxMQKC26WUw4/9Lz/eWw2ZMfNzvGXdBy21oF9f/jvPxw==", 4 | "success": true 5 | } -------------------------------------------------------------------------------- /RoleBased/AuthJWT/obj/AuthJWT.csproj.nuget.dgspec.json: -------------------------------------------------------------------------------- 1 | { 2 | "format": 1, 3 | "restore": { 4 | "D:\\_LearnToday\\ASP.net Core\\AuthJWT\\AuthJWT\\AuthJWT.csproj": {} 5 | }, 6 | "projects": { 7 | "D:\\_LearnToday\\ASP.net Core\\AuthJWT\\AuthJWT\\AuthJWT.csproj": { 8 | "version": "1.0.0", 9 | "restore": { 10 | "projectUniqueName": "D:\\_LearnToday\\ASP.net Core\\AuthJWT\\AuthJWT\\AuthJWT.csproj", 11 | "projectName": "AuthJWT", 12 | "projectPath": "D:\\_LearnToday\\ASP.net Core\\AuthJWT\\AuthJWT\\AuthJWT.csproj", 13 | "packagesPath": "C:\\Users\\MoeinFazeli\\.nuget\\packages\\", 14 | "outputPath": "D:\\_LearnToday\\ASP.net Core\\AuthJWT\\AuthJWT\\obj\\", 15 | "projectStyle": "PackageReference", 16 | "fallbackFolders": [ 17 | "C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder" 18 | ], 19 | "configFilePaths": [ 20 | "C:\\Users\\MoeinFazeli\\AppData\\Roaming\\NuGet\\NuGet.Config", 21 | "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config" 22 | ], 23 | "originalTargetFrameworks": [ 24 | "netcoreapp2.2" 25 | ], 26 | "sources": { 27 | "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {}, 28 | "https://api.nuget.org/v3/index.json": {} 29 | }, 30 | "frameworks": { 31 | "netcoreapp2.2": { 32 | "projectReferences": {} 33 | } 34 | }, 35 | "warningProperties": { 36 | "warnAsError": [ 37 | "NU1605" 38 | ] 39 | } 40 | }, 41 | "frameworks": { 42 | "netcoreapp2.2": { 43 | "dependencies": { 44 | "Microsoft.AspNetCore.App": { 45 | "suppressParent": "All", 46 | "target": "Package", 47 | "version": "[2.2.0, )", 48 | "autoReferenced": true 49 | }, 50 | "Microsoft.AspNetCore.Razor.Design": { 51 | "suppressParent": "All", 52 | "target": "Package", 53 | "version": "[2.2.0, )" 54 | }, 55 | "Microsoft.NETCore.App": { 56 | "suppressParent": "All", 57 | "target": "Package", 58 | "version": "[2.2.0, )", 59 | "autoReferenced": true 60 | }, 61 | "Swashbuckle.AspNetCore": { 62 | "target": "Package", 63 | "version": "[4.0.1, )" 64 | } 65 | }, 66 | "imports": [ 67 | "net461", 68 | "net462", 69 | "net47", 70 | "net471", 71 | "net472", 72 | "net48" 73 | ], 74 | "assetTargetFallback": true, 75 | "warn": true 76 | } 77 | } 78 | } 79 | } 80 | } -------------------------------------------------------------------------------- /RoleBased/AuthJWT/obj/AuthJWT.csproj.nuget.g.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | True 5 | NuGet 6 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\project.assets.json 7 | $(UserProfile)\.nuget\packages\ 8 | C:\Users\MoeinFazeli\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder 9 | PackageReference 10 | 5.0.0 11 | 12 | 13 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.entityframeworkcore.tools\2.2.0 26 | C:\Users\MoeinFazeli\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0 27 | C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.razor.design\2.2.0 28 | 29 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT/obj/AuthJWT.csproj.nuget.g.targets: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | using System; 12 | using System.Reflection; 13 | 14 | [assembly: System.Reflection.AssemblyCompanyAttribute("AuthJWT")] 15 | [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] 16 | [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] 17 | [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] 18 | [assembly: System.Reflection.AssemblyProductAttribute("AuthJWT")] 19 | [assembly: System.Reflection.AssemblyTitleAttribute("AuthJWT")] 20 | [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] 21 | 22 | // Generated by the MSBuild WriteCodeFragment class. 23 | 24 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.AssemblyInfoInputs.cache: -------------------------------------------------------------------------------- 1 | e98e1728c7d46036ecf157fac43ce5850b035eaa 2 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.RazorAssemblyInfo.cache: -------------------------------------------------------------------------------- 1 | 54b1e93c7698f925dcab5c3998494f88511fd105 2 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.RazorAssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | using System; 12 | using System.Reflection; 13 | 14 | [assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.RelatedAssemblyAttribute("AuthJWT.Views")] 15 | [assembly: Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute("2.1")] 16 | [assembly: Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute("MVC-2.1")] 17 | [assembly: Microsoft.AspNetCore.Razor.Hosting.RazorExtensionAssemblyNameAttribute("MVC-2.1", "Microsoft.AspNetCore.Mvc.Razor.Extensions")] 18 | 19 | // Generated by the MSBuild WriteCodeFragment class. 20 | 21 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.RazorTargetAssemblyInfo.cache: -------------------------------------------------------------------------------- 1 | a13c668074c643d342d6dd4176c238c701b45c02 2 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.assets.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohammadMoeinFazeli/ASP.NetCore-AllAuthorizationMethods/7e051867f456d68b750c8d0a2dc95c5a70c047ba/RoleBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.assets.cache -------------------------------------------------------------------------------- /RoleBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.csproj.CoreCompileInputs.cache: -------------------------------------------------------------------------------- 1 | 530ad0946519dbe76237bb6861c1afd193c3aa3f 2 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\appsettings.Development.json 2 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\appsettings.json 3 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\Properties\launchSettings.json 4 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\AuthJWT.deps.json 5 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\AuthJWT.runtimeconfig.json 6 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\AuthJWT.runtimeconfig.dev.json 7 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\AuthJWT.dll 8 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.csprojAssemblyReference.cache 9 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.csproj.CoreCompileInputs.cache 10 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.RazorAssemblyInfo.cache 11 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.RazorAssemblyInfo.cs 12 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.AssemblyInfoInputs.cache 13 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.AssemblyInfo.cs 14 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.RazorTargetAssemblyInfo.cache 15 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\AuthJWT.pdb 16 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.dll 17 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.pdb 18 | -------------------------------------------------------------------------------- /RoleBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.csprojAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohammadMoeinFazeli/ASP.NetCore-AllAuthorizationMethods/7e051867f456d68b750c8d0a2dc95c5a70c047ba/RoleBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.csprojAssemblyReference.cache -------------------------------------------------------------------------------- /RoleBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohammadMoeinFazeli/ASP.NetCore-AllAuthorizationMethods/7e051867f456d68b750c8d0a2dc95c5a70c047ba/RoleBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.dll -------------------------------------------------------------------------------- /RoleBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohammadMoeinFazeli/ASP.NetCore-AllAuthorizationMethods/7e051867f456d68b750c8d0a2dc95c5a70c047ba/RoleBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.pdb -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28803.352 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AuthJWT", "AuthJWT\AuthJWT.csproj", "{768D6249-9A5F-4137-9159-0D332DB8674E}" 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 | {768D6249-9A5F-4137-9159-0D332DB8674E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {768D6249-9A5F-4137-9159-0D332DB8674E}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {768D6249-9A5F-4137-9159-0D332DB8674E}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {768D6249-9A5F-4137-9159-0D332DB8674E}.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 = {7F036B04-C1C5-4372-B639-881D3526DF67} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT.sln.DotSettings.user: -------------------------------------------------------------------------------- 1 |  2 | 2 -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/AuthJWT.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.2 5 | InProcess 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/Config/AppSettings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AuthJWT.Config 7 | { 8 | public class AppSettings 9 | { 10 | public string Secret { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/Config/Extentions/AuthenticationExtention.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Authentication.JwtBearer; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.IdentityModel.Tokens; 10 | 11 | namespace AuthJWT.Config.Extentions 12 | { 13 | public static class AuthenticationExtention 14 | { 15 | public static IServiceCollection AddOurAuthentication(this IServiceCollection services, 16 | AppSettings appSettings) 17 | { 18 | // Authorization service 19 | //services.AddAuthorization(options => 20 | //{ 21 | // options.AddPolicy("GetAllUser", 22 | // policy => policy.RequireClaim("AccessAllUser", "True")); 23 | //}); 24 | 25 | // JWT Authentication 26 | var key = Encoding.ASCII.GetBytes(appSettings.Secret); 27 | services.AddAuthentication(options => 28 | { 29 | options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; 30 | options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; 31 | }) 32 | .AddJwtBearer(options => 33 | { 34 | options.RequireHttpsMetadata = false; 35 | options.SaveToken = true; 36 | options.TokenValidationParameters = new TokenValidationParameters 37 | { 38 | ValidateIssuerSigningKey = true, 39 | IssuerSigningKey = new SymmetricSecurityKey(key), 40 | ValidateIssuer = false, 41 | ValidateAudience = false 42 | }; 43 | }); 44 | return services; 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/Config/Extentions/SwaggerExtention.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.Extensions.DependencyInjection; 6 | using Swashbuckle.AspNetCore.Swagger; 7 | 8 | namespace AuthJWT.Config.Extentions 9 | { 10 | public static class SwaggerExtention 11 | { 12 | public static IServiceCollection AddOurSwaager(this IServiceCollection services) 13 | { 14 | // Swagger service properties 15 | services.AddSwaggerGen(c => 16 | { 17 | c.SwaggerDoc("v1", new Info 18 | { 19 | Version = "v1", 20 | Title = "Auth JWT", 21 | Description = "Auth JWT Demo - angular-netcore.ir", 22 | TermsOfService = "None", 23 | Contact = new Contact() 24 | { 25 | Name = "Mohammad Moein Fazeli", 26 | Email = "mmfazeli372@gmail.com", 27 | Url = "http://www.angular-netcore.ir" 28 | } 29 | }); 30 | c.AddSecurityDefinition("Bearer", new ApiKeyScheme() 31 | { 32 | Description = "JWT Authorization header {token}", 33 | Name = "Authorization", 34 | In = "header", 35 | Type = "apiKey" 36 | }); 37 | c.AddSecurityRequirement(new Dictionary> 38 | { 39 | { "Bearer", new string[] { } } 40 | }); 41 | }); 42 | return services; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/Config/Permissions/AuthorizationPolicyProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Authorization; 6 | using Microsoft.Extensions.Options; 7 | 8 | namespace AuthJWT.Config.Permissions 9 | { 10 | public class AuthorizationPolicyProvider : DefaultAuthorizationPolicyProvider 11 | { 12 | public AuthorizationPolicyProvider(IOptions options) 13 | : base(options) 14 | { 15 | } 16 | 17 | public override Task GetPolicyAsync(string policyName) 18 | { 19 | if (!policyName.StartsWith(PermissionAuthorizeAttribute.PolicyPrefix, StringComparison.OrdinalIgnoreCase)) 20 | { 21 | return base.GetPolicyAsync(policyName); 22 | } 23 | 24 | var permissionNames = policyName.Substring(PermissionAuthorizeAttribute.PolicyPrefix.Length).Split(','); 25 | 26 | var policy = new AuthorizationPolicyBuilder() 27 | .RequireClaim(Permissions.Permission, permissionNames) 28 | .Build(); 29 | 30 | return Task.FromResult(policy); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/Config/Permissions/PermissionAuthorizeAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Authorization; 6 | 7 | namespace AuthJWT.Config.Permissions 8 | { 9 | public class PermissionAuthorizeAttribute : AuthorizeAttribute 10 | { 11 | internal const string PolicyPrefix = "PERMISSION:"; 12 | public PermissionAuthorizeAttribute(params string[] permissions) 13 | { 14 | Policy = $"{PolicyPrefix}{string.Join(",", permissions)}"; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/Config/Permissions/Permissions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AuthJWT.Config.Permissions 7 | { 8 | public static class Permissions 9 | { 10 | public static string Permission = "Permissions"; 11 | 12 | public static class User 13 | { 14 | public const string GetAll = "Permissions.User.GetAll"; 15 | public const string CheckUser = "Permissions.User.CheckUser"; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/Controllers/UserController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using AuthJWT.Config.Permissions; 6 | using AuthJWT.DtoModels; 7 | using AuthJWT.Entities; 8 | using AuthJWT.Services.UserService; 9 | using Microsoft.AspNetCore.Authorization; 10 | using Microsoft.AspNetCore.Mvc; 11 | 12 | // For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 13 | 14 | namespace AuthJWT.Controllers 15 | { 16 | [Authorize] 17 | [ApiController] 18 | [Route("api/[Controller]")] 19 | public class UserController : Controller 20 | { 21 | private readonly IUserService _userService; 22 | 23 | public UserController(IUserService userService) 24 | { 25 | _userService = userService; 26 | } 27 | 28 | [AllowAnonymous] 29 | [HttpPost("login")] 30 | public User Login([FromBody] UserDto user) 31 | { 32 | var User = _userService.Authenticate(user.Username, user.Password); 33 | 34 | return User; 35 | } 36 | 37 | [PermissionAuthorize(Permissions.User.GetAll)] 38 | [HttpGet("all")] 39 | public IEnumerable GetAllUser () 40 | { 41 | return _userService.GetAll(); 42 | } 43 | 44 | [PermissionAuthorize(Permissions.User.CheckUser)] 45 | [HttpGet("checkUser")] 46 | public string CheckUser() 47 | { 48 | return "Hello You have the right access"; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/DtoModels/UserDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AuthJWT.DtoModels 7 | { 8 | public class UserDto 9 | { 10 | public string Username { get; set; } 11 | public string Password { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/Entities/Role.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AuthJWT.Entities 7 | { 8 | public class Role 9 | { 10 | public string Name { get; set; } 11 | public string[] Permissions { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/Entities/User.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AuthJWT.Entities 7 | { 8 | public class User 9 | { 10 | public int Id { get; set; } 11 | public string FirstName { get; set; } 12 | public string LastName { get; set; } 13 | public string Username { get; set; } 14 | public string Password { get; set; } 15 | public string Token { get; set; } 16 | public string[] Permissions { get; set; } 17 | public string Role { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace AuthJWT 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateWebHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:63136", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "launchUrl": "swagger", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "AuthJWT": { 20 | "commandName": "Project", 21 | "launchBrowser": true, 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | }, 25 | "applicationUrl": "http://localhost:5000" 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/Services/UserService/IUserService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using AuthJWT.Entities; 3 | 4 | namespace AuthJWT.Services.UserService 5 | { 6 | public interface IUserService 7 | { 8 | User Authenticate(string username, string password); 9 | IEnumerable GetAll(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/Services/UserService/UserService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IdentityModel.Tokens.Jwt; 4 | using System.Linq; 5 | using System.Security.Claims; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using AuthJWT.Config; 9 | using AuthJWT.Config.Permissions; 10 | using AuthJWT.Entities; 11 | using Microsoft.Extensions.Options; 12 | using Microsoft.IdentityModel.Tokens; 13 | 14 | namespace AuthJWT.Services.UserService 15 | { 16 | public class UserService : IUserService 17 | { 18 | private readonly List _users = new List 19 | { 20 | new User 21 | { 22 | Id = 1, FirstName = "moein", LastName = "fazeli", Username = "user1", Password = "1234", 23 | Permissions = new string[] {"Permissions.User.GetAll"}, Role = "Admin" 24 | }, 25 | new User 26 | { 27 | Id = 2, FirstName = "hassan", LastName = "saeedi", Username = "user2", Password = "1234", 28 | Permissions = new string[] {"Permissions.User.CheckUser"}, Role = "User" 29 | } 30 | }; 31 | 32 | private readonly List _roles = new List 33 | { 34 | new Role 35 | { 36 | Name = "Admin", Permissions = new string[] {"Permissions.User.CheckUser", "Permissions.User.GetAll"} 37 | }, 38 | new Role 39 | { 40 | Name = "User", Permissions = new string[] {"Permissions.User.CheckUser"} 41 | } 42 | }; 43 | 44 | private readonly AppSettings _appSettings; 45 | 46 | public UserService(IOptions appSettings) 47 | { 48 | _appSettings = appSettings.Value; 49 | } 50 | 51 | public User Authenticate(string username, string password) 52 | { 53 | var user = _users.SingleOrDefault(x => x.Username == username && x.Password == password); 54 | 55 | // return null if user not found 56 | if (user == null) 57 | return null; 58 | 59 | // authentication successful so generate jwt token 60 | var tokenHandler = new JwtSecurityTokenHandler(); 61 | var key = Encoding.ASCII.GetBytes(_appSettings.Secret); 62 | var claims = new ClaimsIdentity(); 63 | foreach (var permission in user.Permissions) 64 | { 65 | claims.AddClaims(new[] 66 | { 67 | new Claim(Permissions.Permission, permission) 68 | }); 69 | } 70 | 71 | foreach (var rolePermission in _roles.Find(role=> role.Name == user.Role).Permissions) 72 | { 73 | if (!user.Permissions.Any(x => x == rolePermission)) 74 | { 75 | claims.AddClaims(new[] 76 | { 77 | new Claim(Permissions.Permission, rolePermission) 78 | }); 79 | } 80 | } 81 | 82 | var tokenDescriptor = new SecurityTokenDescriptor 83 | { 84 | Subject = claims, 85 | Expires = DateTime.UtcNow.AddDays(7), 86 | SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), 87 | SecurityAlgorithms.HmacSha256Signature) 88 | }; 89 | var token = tokenHandler.CreateToken(tokenDescriptor); 90 | user.Token = tokenHandler.WriteToken(token); 91 | 92 | // remove password before returning 93 | //user.Password = null; 94 | 95 | return user; 96 | } 97 | 98 | public IEnumerable GetAll() 99 | { 100 | return _users.ToList(); 101 | } 102 | } 103 | } -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/Startup.cs: -------------------------------------------------------------------------------- 1 | using AuthJWT.Config; 2 | using AuthJWT.Config.Extentions; 3 | using AuthJWT.Config.Permissions; 4 | using AuthJWT.Services.UserService; 5 | using Microsoft.AspNetCore.Authorization; 6 | using Microsoft.AspNetCore.Builder; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.DependencyInjection; 10 | 11 | namespace AuthJWT 12 | { 13 | public class Startup 14 | { 15 | private readonly IConfiguration _configuration; 16 | 17 | public Startup(IConfiguration configuration) 18 | { 19 | _configuration = configuration; 20 | } 21 | 22 | public void ConfigureServices(IServiceCollection services) 23 | { 24 | // configure strongly typed settings objects 25 | var appSettingsSection = _configuration.GetSection("AppSettings"); 26 | services.Configure(appSettingsSection); 27 | 28 | // configure jwt authentication 29 | var appSettings = appSettingsSection.Get(); 30 | services.AddOurAuthentication(appSettings); 31 | services.AddOurSwaager(); 32 | 33 | // DI services 34 | services.AddScoped(); 35 | services.AddSingleton(); 36 | 37 | services.AddMvc(); 38 | } 39 | 40 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 41 | { 42 | if (env.IsDevelopment()) 43 | { 44 | app.UseDeveloperExceptionPage(); 45 | } 46 | 47 | app.UseAuthentication(); 48 | 49 | app.UseMvc(); 50 | app.UseSwagger(); 51 | app.UseSwaggerUI(c => 52 | { 53 | c.SwaggerEndpoint("/swagger/v1/swagger.json", "v1"); 54 | }); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "AppSettings": { 3 | "Secret": "This is the secret key and its very important" 4 | }, 5 | "Logging": { 6 | "LogLevel": { 7 | "Default": "Warning" 8 | } 9 | }, 10 | "AllowedHosts": "*" 11 | } 12 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/bin/Debug/netcoreapp2.2/AuthJWT.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohammadMoeinFazeli/ASP.NetCore-AllAuthorizationMethods/7e051867f456d68b750c8d0a2dc95c5a70c047ba/RoleToPermissionBased/AuthJWT/bin/Debug/netcoreapp2.2/AuthJWT.dll -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/bin/Debug/netcoreapp2.2/AuthJWT.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohammadMoeinFazeli/ASP.NetCore-AllAuthorizationMethods/7e051867f456d68b750c8d0a2dc95c5a70c047ba/RoleToPermissionBased/AuthJWT/bin/Debug/netcoreapp2.2/AuthJWT.pdb -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/bin/Debug/netcoreapp2.2/AuthJWT.runtimeconfig.dev.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtimeOptions": { 3 | "additionalProbingPaths": [ 4 | "C:\\Users\\MoeinFazeli\\.dotnet\\store\\|arch|\\|tfm|", 5 | "C:\\Users\\MoeinFazeli\\.nuget\\packages", 6 | "C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder" 7 | ] 8 | } 9 | } -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/bin/Debug/netcoreapp2.2/AuthJWT.runtimeconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtimeOptions": { 3 | "tfm": "netcoreapp2.2", 4 | "framework": { 5 | "name": "Microsoft.AspNetCore.App", 6 | "version": "2.2.0" 7 | }, 8 | "configProperties": { 9 | "System.GC.Server": true 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/bin/Debug/netcoreapp2.2/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:63136", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "launchUrl": "swagger", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "AuthJWT": { 20 | "commandName": "Project", 21 | "launchBrowser": true, 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | }, 25 | "applicationUrl": "http://localhost:5000" 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/bin/Debug/netcoreapp2.2/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/bin/Debug/netcoreapp2.2/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "AppSettings": { 3 | "Secret": "This is the secret key and its very important" 4 | }, 5 | "Logging": { 6 | "LogLevel": { 7 | "Default": "Warning" 8 | } 9 | }, 10 | "AllowedHosts": "*" 11 | } 12 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/obj/AuthJWT.csproj.nuget.cache: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "dgSpecHash": "IQ9yL6QkILGDRlBHckiNsfxAZISSuUAoCC9zgw/WNixxMQKC26WUw4/9Lz/eWw2ZMfNzvGXdBy21oF9f/jvPxw==", 4 | "success": true 5 | } -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/obj/AuthJWT.csproj.nuget.dgspec.json: -------------------------------------------------------------------------------- 1 | { 2 | "format": 1, 3 | "restore": { 4 | "D:\\_LearnToday\\ASP.net Core\\AuthJWT\\AuthJWT\\AuthJWT.csproj": {} 5 | }, 6 | "projects": { 7 | "D:\\_LearnToday\\ASP.net Core\\AuthJWT\\AuthJWT\\AuthJWT.csproj": { 8 | "version": "1.0.0", 9 | "restore": { 10 | "projectUniqueName": "D:\\_LearnToday\\ASP.net Core\\AuthJWT\\AuthJWT\\AuthJWT.csproj", 11 | "projectName": "AuthJWT", 12 | "projectPath": "D:\\_LearnToday\\ASP.net Core\\AuthJWT\\AuthJWT\\AuthJWT.csproj", 13 | "packagesPath": "C:\\Users\\MoeinFazeli\\.nuget\\packages\\", 14 | "outputPath": "D:\\_LearnToday\\ASP.net Core\\AuthJWT\\AuthJWT\\obj\\", 15 | "projectStyle": "PackageReference", 16 | "fallbackFolders": [ 17 | "C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder" 18 | ], 19 | "configFilePaths": [ 20 | "C:\\Users\\MoeinFazeli\\AppData\\Roaming\\NuGet\\NuGet.Config", 21 | "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config" 22 | ], 23 | "originalTargetFrameworks": [ 24 | "netcoreapp2.2" 25 | ], 26 | "sources": { 27 | "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {}, 28 | "https://api.nuget.org/v3/index.json": {} 29 | }, 30 | "frameworks": { 31 | "netcoreapp2.2": { 32 | "projectReferences": {} 33 | } 34 | }, 35 | "warningProperties": { 36 | "warnAsError": [ 37 | "NU1605" 38 | ] 39 | } 40 | }, 41 | "frameworks": { 42 | "netcoreapp2.2": { 43 | "dependencies": { 44 | "Microsoft.AspNetCore.App": { 45 | "suppressParent": "All", 46 | "target": "Package", 47 | "version": "[2.2.0, )", 48 | "autoReferenced": true 49 | }, 50 | "Microsoft.AspNetCore.Razor.Design": { 51 | "suppressParent": "All", 52 | "target": "Package", 53 | "version": "[2.2.0, )" 54 | }, 55 | "Microsoft.NETCore.App": { 56 | "suppressParent": "All", 57 | "target": "Package", 58 | "version": "[2.2.0, )", 59 | "autoReferenced": true 60 | }, 61 | "Swashbuckle.AspNetCore": { 62 | "target": "Package", 63 | "version": "[4.0.1, )" 64 | } 65 | }, 66 | "imports": [ 67 | "net461", 68 | "net462", 69 | "net47", 70 | "net471", 71 | "net472", 72 | "net48" 73 | ], 74 | "assetTargetFallback": true, 75 | "warn": true 76 | } 77 | } 78 | } 79 | } 80 | } -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/obj/AuthJWT.csproj.nuget.g.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | True 5 | NuGet 6 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\project.assets.json 7 | $(UserProfile)\.nuget\packages\ 8 | C:\Users\MoeinFazeli\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder 9 | PackageReference 10 | 5.0.0 11 | 12 | 13 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.entityframeworkcore.tools\2.2.0 26 | C:\Users\MoeinFazeli\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0 27 | C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.razor.design\2.2.0 28 | 29 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/obj/AuthJWT.csproj.nuget.g.targets: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | using System; 12 | using System.Reflection; 13 | 14 | [assembly: System.Reflection.AssemblyCompanyAttribute("AuthJWT")] 15 | [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] 16 | [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] 17 | [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] 18 | [assembly: System.Reflection.AssemblyProductAttribute("AuthJWT")] 19 | [assembly: System.Reflection.AssemblyTitleAttribute("AuthJWT")] 20 | [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] 21 | 22 | // Generated by the MSBuild WriteCodeFragment class. 23 | 24 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.AssemblyInfoInputs.cache: -------------------------------------------------------------------------------- 1 | e98e1728c7d46036ecf157fac43ce5850b035eaa 2 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.RazorAssemblyInfo.cache: -------------------------------------------------------------------------------- 1 | 54b1e93c7698f925dcab5c3998494f88511fd105 2 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.RazorAssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | using System; 12 | using System.Reflection; 13 | 14 | [assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.RelatedAssemblyAttribute("AuthJWT.Views")] 15 | [assembly: Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute("2.1")] 16 | [assembly: Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute("MVC-2.1")] 17 | [assembly: Microsoft.AspNetCore.Razor.Hosting.RazorExtensionAssemblyNameAttribute("MVC-2.1", "Microsoft.AspNetCore.Mvc.Razor.Extensions")] 18 | 19 | // Generated by the MSBuild WriteCodeFragment class. 20 | 21 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.RazorTargetAssemblyInfo.cache: -------------------------------------------------------------------------------- 1 | a13c668074c643d342d6dd4176c238c701b45c02 2 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.assets.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohammadMoeinFazeli/ASP.NetCore-AllAuthorizationMethods/7e051867f456d68b750c8d0a2dc95c5a70c047ba/RoleToPermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.assets.cache -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.csproj.CoreCompileInputs.cache: -------------------------------------------------------------------------------- 1 | d11250eaa75fc774c66289e7c41a7cd6df29a4c4 2 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\appsettings.Development.json 2 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\appsettings.json 3 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\Properties\launchSettings.json 4 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\AuthJWT.deps.json 5 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\AuthJWT.runtimeconfig.json 6 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\AuthJWT.runtimeconfig.dev.json 7 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\AuthJWT.dll 8 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.csprojAssemblyReference.cache 9 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.csproj.CoreCompileInputs.cache 10 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.RazorAssemblyInfo.cache 11 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.RazorAssemblyInfo.cs 12 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.AssemblyInfoInputs.cache 13 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.AssemblyInfo.cs 14 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.RazorTargetAssemblyInfo.cache 15 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\bin\Debug\netcoreapp2.2\AuthJWT.pdb 16 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.dll 17 | D:\_LearnToday\ASP.net Core\AuthJWT\AuthJWT\obj\Debug\netcoreapp2.2\AuthJWT.pdb 18 | -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.csprojAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohammadMoeinFazeli/ASP.NetCore-AllAuthorizationMethods/7e051867f456d68b750c8d0a2dc95c5a70c047ba/RoleToPermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.csprojAssemblyReference.cache -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohammadMoeinFazeli/ASP.NetCore-AllAuthorizationMethods/7e051867f456d68b750c8d0a2dc95c5a70c047ba/RoleToPermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.dll -------------------------------------------------------------------------------- /RoleToPermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohammadMoeinFazeli/ASP.NetCore-AllAuthorizationMethods/7e051867f456d68b750c8d0a2dc95c5a70c047ba/RoleToPermissionBased/AuthJWT/obj/Debug/netcoreapp2.2/AuthJWT.pdb --------------------------------------------------------------------------------