├── README.md
├── JwtAuthentication.Client
├── Pages
│ ├── _ViewImports.cshtml
│ ├── Index.cshtml
│ ├── Counter.cshtml
│ └── FetchData.cshtml
├── wwwroot
│ ├── css
│ │ ├── open-iconic
│ │ │ ├── font
│ │ │ │ ├── fonts
│ │ │ │ │ ├── open-iconic.eot
│ │ │ │ │ ├── open-iconic.otf
│ │ │ │ │ ├── open-iconic.ttf
│ │ │ │ │ ├── open-iconic.woff
│ │ │ │ │ └── open-iconic.svg
│ │ │ │ └── css
│ │ │ │ │ └── open-iconic-bootstrap.min.css
│ │ │ ├── ICON-LICENSE
│ │ │ ├── README.md
│ │ │ └── FONT-LICENSE
│ │ └── site.css
│ └── index.html
├── App.cshtml
├── _ViewImports.cshtml
├── Shared
│ ├── MainLayout.cshtml
│ ├── SurveyPrompt.cshtml
│ └── NavMenu.cshtml
├── Startup.cs
├── Program.cs
├── JwtAuthentication.Client.csproj
└── Properties
│ └── launchSettings.json
├── global.json
├── JwtAuthentication.Shared
├── JwtAuthentication.Shared.csproj
└── WeatherForecast.cs
├── JwtAuthentication.Server
├── Model
│ └── TokenViewModel.cs
├── Interface
│ └── IJwtTokenService.cs
├── appsettings.json
├── Program.cs
├── Properties
│ └── launchSettings.json
├── JwtAuthentication.Server.csproj
├── Controllers
│ ├── TokenController.cs
│ └── SampleDataController.cs
├── Service
│ └── JwtTokenService.cs
└── Startup.cs
├── JwtAuthentication.sln
├── .gitattributes
└── .gitignore
/README.md:
--------------------------------------------------------------------------------
1 | ### JWT Authentication with Dotnet Core 2.1 and Blazor app
--------------------------------------------------------------------------------
/JwtAuthentication.Client/Pages/_ViewImports.cshtml:
--------------------------------------------------------------------------------
1 | @layout MainLayout
2 |
--------------------------------------------------------------------------------
/global.json:
--------------------------------------------------------------------------------
1 | {
2 | "sdk": {
3 | "version": "2.1.300"
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/JwtAuthentication.Client/Pages/Index.cshtml:
--------------------------------------------------------------------------------
1 | @page "/"
2 |
3 |
Hello, world!
4 |
5 | Welcome to your new app.
6 |
7 |
8 |
--------------------------------------------------------------------------------
/JwtAuthentication.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirzaf/DotnetCoreJwtAuthentication/HEAD/JwtAuthentication.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.eot
--------------------------------------------------------------------------------
/JwtAuthentication.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.otf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirzaf/DotnetCoreJwtAuthentication/HEAD/JwtAuthentication.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.otf
--------------------------------------------------------------------------------
/JwtAuthentication.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirzaf/DotnetCoreJwtAuthentication/HEAD/JwtAuthentication.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf
--------------------------------------------------------------------------------
/JwtAuthentication.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirzaf/DotnetCoreJwtAuthentication/HEAD/JwtAuthentication.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.woff
--------------------------------------------------------------------------------
/JwtAuthentication.Client/App.cshtml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
--------------------------------------------------------------------------------
/JwtAuthentication.Shared/JwtAuthentication.Shared.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | 7.3
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/JwtAuthentication.Client/_ViewImports.cshtml:
--------------------------------------------------------------------------------
1 | @using System.Net.Http
2 | @using Microsoft.AspNetCore.Blazor.Layouts
3 | @using Microsoft.AspNetCore.Blazor.Routing
4 | @using Microsoft.JSInterop
5 | @using JwtAuthentication.Client
6 | @using JwtAuthentication.Client.Shared
7 |
--------------------------------------------------------------------------------
/JwtAuthentication.Server/Model/TokenViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 |
6 | namespace JwtAuthentication.Server.Model
7 | {
8 | public class TokenViewModel
9 | {
10 | public string Email { get; set; }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/JwtAuthentication.Server/Interface/IJwtTokenService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 |
6 | namespace JwtAuthentication.Server.Interface
7 | {
8 | public interface IJwtTokenService
9 | {
10 | string BuildToken(string email);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/JwtAuthentication.Client/Pages/Counter.cshtml:
--------------------------------------------------------------------------------
1 | @page "/counter"
2 |
3 | Counter
4 |
5 | Current count: @currentCount
6 |
7 |
8 |
9 | @functions {
10 | int currentCount = 0;
11 |
12 | void IncrementCount()
13 | {
14 | currentCount++;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/JwtAuthentication.Client/Shared/MainLayout.cshtml:
--------------------------------------------------------------------------------
1 | @inherits BlazorLayoutComponent
2 |
3 |
6 |
7 |
8 |
11 |
12 |
13 | @Body
14 |
15 |
16 |
--------------------------------------------------------------------------------
/JwtAuthentication.Server/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Jwt": {
3 | "Key": "SuperTopSecretKeyThatYouDoNotGiveOutEver!",
4 | "Issuer": "http://localhost:57778/",
5 | "Audience": "http://localhost:57778/",
6 | "ExpireTime": 30
7 | },
8 | "ConnectionStrings": {
9 | "DefaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database=_CHANGE_ME;Trusted_Connection=True;MultipleActiveResultSets=true"
10 | }
11 | }
--------------------------------------------------------------------------------
/JwtAuthentication.Shared/WeatherForecast.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace JwtAuthentication.Shared
6 | {
7 | public class WeatherForecast
8 | {
9 | public DateTime Date { get; set; }
10 | public int TemperatureC { get; set; }
11 | public string Summary { get; set; }
12 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/JwtAuthentication.Client/Startup.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Blazor.Builder;
2 | using Microsoft.Extensions.DependencyInjection;
3 |
4 | namespace JwtAuthentication.Client
5 | {
6 | public class Startup
7 | {
8 | public void ConfigureServices(IServiceCollection services)
9 | {
10 | }
11 |
12 | public void Configure(IBlazorApplicationBuilder app)
13 | {
14 | app.AddComponent("app");
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/JwtAuthentication.Client/wwwroot/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | JwtAuthentication
7 |
8 |
9 |
10 |
11 |
12 | Loading...
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/JwtAuthentication.Client/Program.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Blazor.Hosting;
2 |
3 | namespace JwtAuthentication.Client
4 | {
5 | public class Program
6 | {
7 | public static void Main(string[] args)
8 | {
9 | CreateHostBuilder(args).Build().Run();
10 | }
11 |
12 | public static IWebAssemblyHostBuilder CreateHostBuilder(string[] args) =>
13 | BlazorWebAssemblyHost.CreateDefaultBuilder()
14 | .UseBlazorStartup();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/JwtAuthentication.Client/Shared/SurveyPrompt.cshtml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
@Title
4 |
5 |
6 | Please take our
7 | brief survey
8 |
9 | and tell us what you think.
10 |
11 |
12 | @functions {
13 | [Parameter]
14 | string Title { get; set; } // Demonstrates how a parent component can supply parameters
15 | }
16 |
--------------------------------------------------------------------------------
/JwtAuthentication.Client/JwtAuthentication.Client.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | Exe
6 | 7.3
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/JwtAuthentication.Server/Program.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore;
2 | using Microsoft.AspNetCore.Hosting;
3 | using Microsoft.Extensions.Configuration;
4 |
5 | namespace JwtAuthentication.Server
6 | {
7 | public class Program
8 | {
9 | public static void Main(string[] args)
10 | {
11 | BuildWebHost(args).Run();
12 | }
13 |
14 | public static IWebHost BuildWebHost(string[] args) =>
15 | WebHost.CreateDefaultBuilder(args)
16 | .UseConfiguration(new ConfigurationBuilder()
17 | .AddCommandLine(args)
18 | .Build())
19 | .UseStartup()
20 | .Build();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/JwtAuthentication.Client/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:57779/",
7 | "sslPort": 0
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "environmentVariables": {
15 | "ASPNETCORE_ENVIRONMENT": "Development"
16 | }
17 | },
18 | "JwtAuthentication.Client": {
19 | "commandName": "Project",
20 | "launchBrowser": true,
21 | "environmentVariables": {
22 | "ASPNETCORE_ENVIRONMENT": "Development"
23 | },
24 | "applicationUrl": "http://localhost:57781/"
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/JwtAuthentication.Server/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:57778/",
7 | "sslPort": 0
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "environmentVariables": {
15 | "ASPNETCORE_ENVIRONMENT": "Development"
16 | }
17 | },
18 | "JwtAuthentication.Server": {
19 | "commandName": "Project",
20 | "launchBrowser": true,
21 | "environmentVariables": {
22 | "ASPNETCORE_ENVIRONMENT": "Development"
23 | },
24 | "applicationUrl": "http://localhost:57780/"
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/JwtAuthentication.Server/JwtAuthentication.Server.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.1
5 | 7.3
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/JwtAuthentication.Server/Controllers/TokenController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using JwtAuthentication.Server.Interface;
6 | using JwtAuthentication.Server.Model;
7 | using JwtAuthentication.Server.Service;
8 | using Microsoft.AspNetCore.Http;
9 | using Microsoft.AspNetCore.Mvc;
10 |
11 | namespace JwtAuthentication.Server.Controllers
12 | {
13 | [Route("api/[controller]")]
14 | [ApiController]
15 | public class TokenController : ControllerBase
16 | {
17 | private readonly IJwtTokenService _tokenService;
18 | public TokenController(IJwtTokenService tokenService)
19 | {
20 | _tokenService = tokenService;
21 | }
22 |
23 | [HttpPost]
24 | public IActionResult GenerateToken([FromBody] TokenViewModel vm)
25 | {
26 | var token = _tokenService.BuildToken(vm.Email);
27 |
28 | return Ok(new {token});
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/JwtAuthentication.Server/Controllers/SampleDataController.cs:
--------------------------------------------------------------------------------
1 | using JwtAuthentication.Shared;
2 | using Microsoft.AspNetCore.Mvc;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using Microsoft.AspNetCore.Authorization;
8 |
9 | namespace JwtAuthentication.Server.Controllers
10 | {
11 | [Authorize]
12 | [Route("api/[controller]")]
13 | public class SampleDataController : Controller
14 | {
15 | private static string[] Summaries = new[]
16 | {
17 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
18 | };
19 |
20 | [HttpGet("[action]")]
21 | public IEnumerable WeatherForecasts()
22 | {
23 | var rng = new Random();
24 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast
25 | {
26 | Date = DateTime.Now.AddDays(index),
27 | TemperatureC = rng.Next(-20, 55),
28 | Summary = Summaries[rng.Next(Summaries.Length)]
29 | });
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/JwtAuthentication.Client/wwwroot/css/open-iconic/ICON-LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Waybury
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
--------------------------------------------------------------------------------
/JwtAuthentication.Client/Pages/FetchData.cshtml:
--------------------------------------------------------------------------------
1 | @using JwtAuthentication.Shared
2 | @page "/fetchdata"
3 | @inject HttpClient Http
4 |
5 | Weather forecast
6 |
7 | This component demonstrates fetching data from the server.
8 |
9 | @if (forecasts == null)
10 | {
11 | Loading...
12 | }
13 | else
14 | {
15 |
16 |
17 |
18 | | Date |
19 | Temp. (C) |
20 | Temp. (F) |
21 | Summary |
22 |
23 |
24 |
25 | @foreach (var forecast in forecasts)
26 | {
27 |
28 | | @forecast.Date.ToShortDateString() |
29 | @forecast.TemperatureC |
30 | @forecast.TemperatureF |
31 | @forecast.Summary |
32 |
33 | }
34 |
35 |
36 | }
37 |
38 | @functions {
39 | WeatherForecast[] forecasts;
40 |
41 | protected override async Task OnInitAsync()
42 | {
43 | forecasts = await Http.GetJsonAsync("api/SampleData/WeatherForecasts");
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/JwtAuthentication.Client/Shared/NavMenu.cshtml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
27 |
28 | @functions {
29 | bool collapseNavMenu = true;
30 |
31 | void ToggleNavMenu()
32 | {
33 | collapseNavMenu = !collapseNavMenu;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/JwtAuthentication.Server/Service/JwtTokenService.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 JwtAuthentication.Server.Interface;
9 | using Microsoft.AspNetCore.Mvc;
10 | using Microsoft.Extensions.Configuration;
11 | using Microsoft.IdentityModel.Tokens;
12 |
13 | namespace JwtAuthentication.Server.Service
14 | {
15 | public class JwtTokenService : IJwtTokenService
16 | {
17 | private readonly IConfiguration _config;
18 |
19 | public JwtTokenService(IConfiguration config)
20 | {
21 | _config = config;
22 | }
23 |
24 | ///
25 | /// Builds the token used for authentication
26 | ///
27 | ///
28 | ///
29 | public string BuildToken([FromBody] string email)
30 | {
31 | // Create a claim based on the users emai. You can add more claims like ID's and any other info
32 | var claims = new[] {
33 | new Claim(JwtRegisteredClaimNames.Email, email),
34 | new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())
35 | };
36 |
37 | // Creates a key from our private key that will be used in the security algorithm next
38 | var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Jwt:Key"]));
39 |
40 | // Credentials that are encrypted which can only be created by our server using the private key
41 | var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
42 |
43 | // this is the actual token that will be issued to the user
44 | var token = new JwtSecurityToken(_config["Jwt:Issuer"],
45 | _config["Jwt:Audience"],
46 | claims,
47 | expires: DateTime.Now.AddMinutes(double.Parse(_config["Jwt:ExpireTime"])),
48 | signingCredentials: creds);
49 |
50 | // return the token in the correct format using JwtSecurityTokenHandler
51 | return new JwtSecurityTokenHandler().WriteToken(token);
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/JwtAuthentication.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27703.2047
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JwtAuthentication.Server", "JwtAuthentication.Server\JwtAuthentication.Server.csproj", "{CC571CC2-EEA6-493B-A0F5-31B3B652E25D}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JwtAuthentication.Client", "JwtAuthentication.Client\JwtAuthentication.Client.csproj", "{346554D7-D8A5-4E96-8727-92F9C272B53F}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JwtAuthentication.Shared", "JwtAuthentication.Shared\JwtAuthentication.Shared.csproj", "{639A2E72-7201-4DE0-828D-30C908E59A77}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|Any CPU = Debug|Any CPU
15 | Release|Any CPU = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {CC571CC2-EEA6-493B-A0F5-31B3B652E25D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {CC571CC2-EEA6-493B-A0F5-31B3B652E25D}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {CC571CC2-EEA6-493B-A0F5-31B3B652E25D}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {CC571CC2-EEA6-493B-A0F5-31B3B652E25D}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {346554D7-D8A5-4E96-8727-92F9C272B53F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {346554D7-D8A5-4E96-8727-92F9C272B53F}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {346554D7-D8A5-4E96-8727-92F9C272B53F}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {346554D7-D8A5-4E96-8727-92F9C272B53F}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {639A2E72-7201-4DE0-828D-30C908E59A77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {639A2E72-7201-4DE0-828D-30C908E59A77}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {639A2E72-7201-4DE0-828D-30C908E59A77}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {639A2E72-7201-4DE0-828D-30C908E59A77}.Release|Any CPU.Build.0 = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(SolutionProperties) = preSolution
32 | HideSolutionNode = FALSE
33 | EndGlobalSection
34 | GlobalSection(ExtensibilityGlobals) = postSolution
35 | SolutionGuid = {492775CA-5F8C-41C6-B45D-1B3E8D6B6CD6}
36 | EndGlobalSection
37 | EndGlobal
38 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/JwtAuthentication.Client/wwwroot/css/site.css:
--------------------------------------------------------------------------------
1 | @import url('open-iconic/font/css/open-iconic-bootstrap.min.css');
2 |
3 | html, body {
4 | font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
5 | }
6 |
7 | app {
8 | position: relative;
9 | display: flex;
10 | flex-direction: column;
11 | }
12 |
13 | .top-row {
14 | height: 3.5rem;
15 | display: flex;
16 | align-items: center;
17 | }
18 |
19 | .main {
20 | flex: 1;
21 | }
22 |
23 | .main .top-row {
24 | background-color: #e6e6e6;
25 | border-bottom: 1px solid #d6d5d5;
26 | }
27 |
28 | .sidebar {
29 | background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
30 | }
31 |
32 | .sidebar .top-row {
33 | background-color: rgba(0,0,0,0.4);
34 | }
35 |
36 | .sidebar .navbar-brand {
37 | font-size: 1.1rem;
38 | }
39 |
40 | .sidebar .oi {
41 | width: 2rem;
42 | font-size: 1.1rem;
43 | vertical-align: text-top;
44 | top: -2px;
45 | }
46 |
47 | .nav-item {
48 | font-size: 0.9rem;
49 | padding-bottom: 0.5rem;
50 | }
51 |
52 | .nav-item:first-of-type {
53 | padding-top: 1rem;
54 | }
55 |
56 | .nav-item:last-of-type {
57 | padding-bottom: 1rem;
58 | }
59 |
60 | .nav-item a {
61 | color: #d7d7d7;
62 | border-radius: 4px;
63 | height: 3rem;
64 | display: flex;
65 | align-items: center;
66 | line-height: 3rem;
67 | }
68 |
69 | .nav-item a.active {
70 | background-color: rgba(255,255,255,0.25);
71 | color: white;
72 | }
73 |
74 | .nav-item a:hover {
75 | background-color: rgba(255,255,255,0.1);
76 | color: white;
77 | }
78 |
79 | .content {
80 | padding-top: 1.1rem;
81 | }
82 |
83 | .navbar-toggler {
84 | background-color: rgba(255, 255, 255, 0.1);
85 | }
86 |
87 | @media (max-width: 767.98px) {
88 | .main .top-row {
89 | display: none;
90 | }
91 | }
92 |
93 | @media (min-width: 768px) {
94 | app {
95 | flex-direction: row;
96 | }
97 |
98 | .sidebar {
99 | width: 250px;
100 | height: 100vh;
101 | position: sticky;
102 | top: 0;
103 | }
104 |
105 | .main .top-row {
106 | position: sticky;
107 | top: 0;
108 | }
109 |
110 | .main > div {
111 | padding-left: 2rem !important;
112 | padding-right: 1.5rem !important;
113 | }
114 |
115 | .navbar-toggler {
116 | display: none;
117 | }
118 |
119 | .sidebar .collapse {
120 | /* Never collapse the sidebar for wide screens */
121 | display: block;
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/JwtAuthentication.Server/Startup.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Blazor.Server;
2 | using Microsoft.AspNetCore.Builder;
3 | using Microsoft.AspNetCore.Hosting;
4 | using Microsoft.AspNetCore.ResponseCompression;
5 | using Microsoft.Extensions.DependencyInjection;
6 | using Newtonsoft.Json.Serialization;
7 | using System.Linq;
8 | using System.Net.Mime;
9 | using System.Text;
10 | using JwtAuthentication.Server.Interface;
11 | using JwtAuthentication.Server.Service;
12 | using Microsoft.AspNetCore.Authentication.JwtBearer;
13 | using Microsoft.AspNetCore.Identity;
14 | using Microsoft.Extensions.Configuration;
15 | using Microsoft.IdentityModel.Tokens;
16 |
17 | namespace JwtAuthentication.Server
18 | {
19 | public class Startup
20 | {
21 | public IConfiguration Configuration { get; }
22 | public Startup(IConfiguration configuration)
23 | {
24 | Configuration = configuration;
25 | }
26 |
27 |
28 | // This method gets called by the runtime. Use this method to add services to the container.
29 | // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
30 | public void ConfigureServices(IServiceCollection services)
31 | {
32 | services.AddMvc();
33 |
34 | services.AddTransient();
35 |
36 | //Setting up Jwt Authentication
37 | services.AddAuthentication(options =>
38 | {
39 | options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
40 | options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
41 | })
42 | .AddJwtBearer(options =>
43 | {
44 | options.TokenValidationParameters = new TokenValidationParameters
45 | {
46 | ValidateIssuer = true,
47 | ValidateAudience = true,
48 | ValidateLifetime = true,
49 | ValidateIssuerSigningKey = true,
50 | ValidIssuer = Configuration["Jwt:Issuer"],
51 | ValidAudience = Configuration["Jwt:Audience"],
52 | IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Key"]))
53 | };
54 | });
55 |
56 | services.AddResponseCompression(options =>
57 | {
58 | options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[]
59 | {
60 | MediaTypeNames.Application.Octet,
61 | WasmMediaTypeNames.Application.Wasm,
62 | });
63 | });
64 | }
65 |
66 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
67 | public void Configure(IApplicationBuilder app, IHostingEnvironment env)
68 | {
69 | app.UseResponseCompression();
70 |
71 | if (env.IsDevelopment())
72 | {
73 | app.UseDeveloperExceptionPage();
74 | }
75 |
76 | // Tell the app to use authentication
77 | app.UseAuthentication();
78 |
79 | app.UseMvc(routes =>
80 | {
81 | routes.MapRoute(name: "default", template: "{controller}/{action}/{id?}");
82 | });
83 |
84 | app.UseBlazor();
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/JwtAuthentication.Client/wwwroot/css/open-iconic/README.md:
--------------------------------------------------------------------------------
1 | [Open Iconic v1.1.1](http://useiconic.com/open)
2 | ===========
3 |
4 | ### Open Iconic is the open source sibling of [Iconic](http://useiconic.com). It is a hyper-legible collection of 223 icons with a tiny footprint—ready to use with Bootstrap and Foundation. [View the collection](http://useiconic.com/open#icons)
5 |
6 |
7 |
8 | ## What's in Open Iconic?
9 |
10 | * 223 icons designed to be legible down to 8 pixels
11 | * Super-light SVG files - 61.8 for the entire set
12 | * SVG sprite—the modern replacement for icon fonts
13 | * Webfont (EOT, OTF, SVG, TTF, WOFF), PNG and WebP formats
14 | * Webfont stylesheets (including versions for Bootstrap and Foundation) in CSS, LESS, SCSS and Stylus formats
15 | * PNG and WebP raster images in 8px, 16px, 24px, 32px, 48px and 64px.
16 |
17 |
18 | ## Getting Started
19 |
20 | #### For code samples and everything else you need to get started with Open Iconic, check out our [Icons](http://useiconic.com/open#icons) and [Reference](http://useiconic.com/open#reference) sections.
21 |
22 | ### General Usage
23 |
24 | #### Using Open Iconic's SVGs
25 |
26 | We like SVGs and we think they're the way to display icons on the web. Since Open Iconic are just basic SVGs, we suggest you display them like you would any other image (don't forget the `alt` attribute).
27 |
28 | ```
29 |
30 | ```
31 |
32 | #### Using Open Iconic's SVG Sprite
33 |
34 | Open Iconic also comes in a SVG sprite which allows you to display all the icons in the set with a single request. It's like an icon font, without being a hack.
35 |
36 | Adding an icon from an SVG sprite is a little different than what you're used to, but it's still a piece of cake. *Tip: To make your icons easily style able, we suggest adding a general class to the* `