commit 5a0687b9228c985a269c274b6aaa0d259dd6d713
Author: Dominik Chlouba <dchlouba@students.zcu.cz>
Date:   Thu Apr 8 21:13:30 2021 +0200

    Merged ad-auth with frontend

diff --git a/Leuze.sln b/Leuze.sln
index fc944db..48b3590 100644
--- a/Leuze.sln
+++ b/Leuze.sln
@@ -35,9 +35,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{B74BED5E-F
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Leuze.Tests.Core.Domain", "tests\Core\Leuze.Tests.Core.Domain\Leuze.Tests.Core.Domain.csproj", "{8ECAEA01-61F3-402D-B94E-E54FC0C94C8E}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Leuze.Core.Infrastructure.ActiveDirectory", "src\Core\Infrastructure\Leuze.Core.Infrastructure.ActiveDirectory\Leuze.Core.Infrastructure.ActiveDirectory.csproj", "{1407144F-48F6-404E-A890-961B739D030D}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Leuze.Core.Infrastructure.ActiveDirectory", "src\Core\Infrastructure\Leuze.Core.Infrastructure.ActiveDirectory\Leuze.Core.Infrastructure.ActiveDirectory.csproj", "{1407144F-48F6-404E-A890-961B739D030D}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Leuze.Tests.Core.Infrastructure.ActiveDirectory", "tests\Core\Leuze.Tests.Core.Infrastructure.ActiveDirectory\Leuze.Tests.Core.Infrastructure.ActiveDirectory.csproj", "{C1813611-5FF2-4E70-B7E5-A4E8553F0B66}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Leuze.Tests.Core.Infrastructure.ActiveDirectory", "tests\Core\Leuze.Tests.Core.Infrastructure.ActiveDirectory\Leuze.Tests.Core.Infrastructure.ActiveDirectory.csproj", "{C1813611-5FF2-4E70-B7E5-A4E8553F0B66}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
diff --git a/src/Core/Application/Leuze.Core.Application.UI/App.razor b/src/Core/Application/Leuze.Core.Application.UI/App.razor
index 7c71f22..1d53f78 100644
--- a/src/Core/Application/Leuze.Core.Application.UI/App.razor
+++ b/src/Core/Application/Leuze.Core.Application.UI/App.razor
@@ -1,16 +1,17 @@
 ﻿@using System.Reflection
 @using ExtCore.Infrastructure
-
-<Router AppAssembly="@typeof(CoreUIExtension).Assembly" AdditionalAssemblies="LoadAdditionalAssemblies">
-    <Found Context="routeData">
-        <RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
-    </Found>
-    <NotFound>
-        <LayoutView Layout="@typeof(MainLayout)">
-            <p>Sorry, there's nothing at this address.</p>
-        </LayoutView>
-    </NotFound>
-</Router>
+<CascadingAuthenticationState>
+    <Router AppAssembly="@typeof(CoreUIExtension).Assembly" AdditionalAssemblies="LoadAdditionalAssemblies">
+        <Found Context="routeData">
+            <AuthorizeRouteView RouteData="@routeData"/>
+        </Found>
+        <NotFound>
+            <LayoutView Layout="@typeof(MainLayout)">
+                <p>Sorry, there's nothing at this address.</p>
+            </LayoutView>
+        </NotFound>
+    </Router>
+</CascadingAuthenticationState>
 
 @code {
     public IEnumerable<Assembly> LoadAdditionalAssemblies { get; set; } = null!;
diff --git a/src/Core/Application/Leuze.Core.Application.UI/Pages/Index.razor b/src/Core/Application/Leuze.Core.Application.UI/Pages/Index.razor
index e54d914..e52ad93 100644
--- a/src/Core/Application/Leuze.Core.Application.UI/Pages/Index.razor
+++ b/src/Core/Application/Leuze.Core.Application.UI/Pages/Index.razor
@@ -1,4 +1,5 @@
 ﻿@page "/"
+@layout MainLayout
 
 <h1>Hello, world!</h1>
 
diff --git a/src/Core/Application/Leuze.Core.Application.UI/Shared/MainLayout.razor b/src/Core/Application/Leuze.Core.Application.UI/Shared/MainLayout.razor
index 2d81d80..f8dfacb 100644
--- a/src/Core/Application/Leuze.Core.Application.UI/Shared/MainLayout.razor
+++ b/src/Core/Application/Leuze.Core.Application.UI/Shared/MainLayout.razor
@@ -1,13 +1,15 @@
 ﻿@inherits LayoutComponentBase
+@inject NavigationManager _navManager
 <div class="top-row px-4">
-    <img src="Resources/Icons/logo.svg" alt="logo" style="width:111px;height:28px;">
-    <img src="Resources/Icons/sign-out.svg" style="width:18px;height:20px;">
-
+    <img src="Resources/Icons/logo.svg" alt="logo" style="width:111px;height:28px;"/>
+    <img src="Resources/Icons/sign-out.svg" style="width:18px;height:20px;"/>
 </div>
-    <div class="page">  
-        <div class="sidebar">
-            <NavMenu />
-        </div>
+
+
+<div class="page">
+    <div class="sidebar">
+        <NavMenu />
+    </div>
 
         <div class="main">
             <div class="content px-4">
@@ -15,3 +17,12 @@
             </div>
         </div>
     </div>
+
+@code {
+
+    /*protected override void OnAfterRender(bool firstRender)
+    {
+        base.OnAfterRender(firstRender);
+        if (firstRender) _navManager.NavigateTo("account/login");
+    }*/
+}
diff --git a/src/Core/Application/Leuze.Core.Application.UI/_Imports.razor b/src/Core/Application/Leuze.Core.Application.UI/_Imports.razor
index d28322f..c0a84e4 100644
--- a/src/Core/Application/Leuze.Core.Application.UI/_Imports.razor
+++ b/src/Core/Application/Leuze.Core.Application.UI/_Imports.razor
@@ -7,5 +7,8 @@
 @using Microsoft.AspNetCore.Components.Web.Virtualization
 @using Microsoft.JSInterop
 @using Leuze.Core.Application.UI.Shared
-@using Leuze.Core.Application.UI.Components.Login
-@using BlazorStyled 
\ No newline at end of file
+@using BlazorStyled
+@using Microsoft.AspNetCore.Authentication
+@using Microsoft.AspNetCore.Identity
+@using Leuze.Core.Application.Identity 
+@using Leuze.Core.Application.UI.Components.Login
\ No newline at end of file
diff --git a/src/Core/Application/Leuze.Core.Application/Configuration/Actions.cs b/src/Core/Application/Leuze.Core.Application/Configuration/Actions.cs
index d528b01..a534b09 100644
--- a/src/Core/Application/Leuze.Core.Application/Configuration/Actions.cs
+++ b/src/Core/Application/Leuze.Core.Application/Configuration/Actions.cs
@@ -4,6 +4,7 @@ using ExtCore.Infrastructure.Actions;
 using FluentValidation;
 using Leuze.Core.Application.Behaviors;
 using MediatR;
+using Microsoft.Identity.Web;
 using Microsoft.AspNetCore.Builder;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.Extensions.Configuration;
@@ -11,6 +12,10 @@ using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.Hosting;
 using System;
 using System.Linq;
+using Microsoft.AspNetCore.Authentication.OpenIdConnect;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc.Authorization;
+using Microsoft.Identity.Web.UI;
 
 namespace Leuze.Core.Application.Configuration
 {
@@ -74,6 +79,7 @@ namespace Leuze.Core.Application.Configuration
         /// <param name="serviceProvider"></param>
         public void Execute(IServiceCollection services, IServiceProvider serviceProvider)
         {
+            var configuration = serviceProvider.GetRequiredService<IConfiguration>();
             services.AddAutoMapper(ExtensionManager.Assemblies);
             services.AddValidatorsFromAssemblies(ExtensionManager.Assemblies);
             services.AddMediatR(ExtensionManager.Assemblies.ToArray());
@@ -85,9 +91,16 @@ namespace Leuze.Core.Application.Configuration
             appSettingsSection.Bind(appSettings);
             services.Configure<AppSettings>(appSettingsSection);
 
-            services.AddBlazorStyled();
+            services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
+                .AddMicrosoftIdentityWebApp(configuration.GetSection("AzureAd"));
+            services.AddControllersWithViews()
+                .AddMicrosoftIdentityUI();
+
+            services.AddAuthorization();
             services.AddRazorPages();
-            services.AddServerSideBlazor();
+            services.AddServerSideBlazor()
+                .AddMicrosoftIdentityConsentHandler();
+            services.AddBlazorStyled();
         }
     }
 }
diff --git a/src/Core/Application/Leuze.Core.Application/Leuze.Core.Application.csproj b/src/Core/Application/Leuze.Core.Application/Leuze.Core.Application.csproj
index 16718e7..5157b8f 100644
--- a/src/Core/Application/Leuze.Core.Application/Leuze.Core.Application.csproj
+++ b/src/Core/Application/Leuze.Core.Application/Leuze.Core.Application.csproj
@@ -35,6 +35,9 @@
     <PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="9.5.2" />
     <PackageReference Include="MediatR" Version="9.0.0" />
     <PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="9.0.0" />
+    <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="5.0.5" />
+    <PackageReference Include="Microsoft.Identity.Web" Version="1.8.2" />
+    <PackageReference Include="Microsoft.Identity.Web.UI" Version="1.8.2" />
   </ItemGroup>
 
   <ItemGroup>
diff --git a/src/Presentation/Leuze.App/Leuze.App.csproj b/src/Presentation/Leuze.App/Leuze.App.csproj
index 6b36d67..6b98f80 100644
--- a/src/Presentation/Leuze.App/Leuze.App.csproj
+++ b/src/Presentation/Leuze.App/Leuze.App.csproj
@@ -17,6 +17,14 @@
     <DocumentationFile>..\..\..\docs\Leuze.App.xml</DocumentationFile>
   </PropertyGroup>
 
+  <ItemGroup>
+    <Content Remove="wwwroot\Resources\Icons\microsoft-logo.svg" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <None Include="wwwroot\Resources\Icons\microsoft-logo.svg" />
+  </ItemGroup>
+
   <ItemGroup>
     <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.4">
       <PrivateAssets>all</PrivateAssets>
diff --git a/src/Presentation/Leuze.App/appsettings.Development.json b/src/Presentation/Leuze.App/appsettings.Development.json
index 9960dc7..3e28422 100644
--- a/src/Presentation/Leuze.App/appsettings.Development.json
+++ b/src/Presentation/Leuze.App/appsettings.Development.json
@@ -3,6 +3,13 @@
     "Path": "..\\Leuze.Modules\\net5.0",
     "IncludeSubPaths": false
   },
+  "AzureAd": {
+    "Instance": "https://login.microsoftonline.com/",
+    "Domain": "silentindustries.onmicrosoft.com",
+    "TenantId": "8320026e-f0c8-4609-ac9e-52b0e2bb6029",
+    "ClientId": "7be51083-d17e-4916-984e-8567b8137365",
+    "CallbackPath": "/signin-oidc"
+  },
   "AppSettings": {
     "DatabaseConnection": {
       "ConnectionString": "Server=localhost;Database=Leuze_Local;User Id=sa;Password=LeuzeDB01;",
diff --git a/src/Presentation/Leuze.App/appsettings.json b/src/Presentation/Leuze.App/appsettings.json
index 0302bdb..c30908e 100644
--- a/src/Presentation/Leuze.App/appsettings.json
+++ b/src/Presentation/Leuze.App/appsettings.json
@@ -3,6 +3,13 @@
     "Path": "..\\Leuze.Modules\\net5.0",
     "IncludeSubPaths": false
   },
+  "AzureAd": {
+    "Instance": "https://login.microsoftonline.com/",
+    "Domain": "silentindustries.onmicrosoft.com",
+    "TenantId": "8320026e-f0c8-4609-ac9e-52b0e2bb6029",
+    "ClientId": "7be51083-d17e-4916-984e-8567b8137365",
+    "CallbackPath": "/signin-oidc"
+  },
   "AppSettings": {
     "DatabaseConnection": {
       "ConnectionString": "Server=localhost;Database=Leuze_Local;User Id=sa;Password=LeuzeDB01;",
