Skip to content

Commit

Permalink
Update BlazorAuthClient to dotnet 5 (address #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
rockfordlhotka committed Nov 30, 2020
1 parent 91abad8 commit 06e2f36
Show file tree
Hide file tree
Showing 26 changed files with 368 additions and 289 deletions.
34 changes: 17 additions & 17 deletions BlazorAuthClient/BlazorAuthClient.sln
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30001.183
VisualStudioVersion = 16.0.30717.126
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorAuthClient.Server", "BlazorAuthClient\Server\BlazorAuthClient.Server.csproj", "{404025C9-1B25-42C5-B1F6-5D84DCE3D257}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorAuthClient.Server", "BlazorAuthClient\Server\BlazorAuthClient.Server.csproj", "{BBB537A6-3925-4061-BFBC-4AE9C6488236}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorAuthClient.Client", "BlazorAuthClient\Client\BlazorAuthClient.Client.csproj", "{00AC37BA-8465-4CCE-AD84-A4ACE61F32C7}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorAuthClient.Client", "BlazorAuthClient\Client\BlazorAuthClient.Client.csproj", "{56B4573A-BB1E-44CB-9046-09A47CBD2E7C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorAuthClient.Shared", "BlazorAuthClient\Shared\BlazorAuthClient.Shared.csproj", "{582C263D-D9FE-487C-834E-0D9F50C9C003}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorAuthClient.Shared", "BlazorAuthClient\Shared\BlazorAuthClient.Shared.csproj", "{DA269CEC-CF51-4530-BBF8-C9F5018C0E8F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{404025C9-1B25-42C5-B1F6-5D84DCE3D257}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{404025C9-1B25-42C5-B1F6-5D84DCE3D257}.Debug|Any CPU.Build.0 = Debug|Any CPU
{404025C9-1B25-42C5-B1F6-5D84DCE3D257}.Release|Any CPU.ActiveCfg = Release|Any CPU
{404025C9-1B25-42C5-B1F6-5D84DCE3D257}.Release|Any CPU.Build.0 = Release|Any CPU
{00AC37BA-8465-4CCE-AD84-A4ACE61F32C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{00AC37BA-8465-4CCE-AD84-A4ACE61F32C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00AC37BA-8465-4CCE-AD84-A4ACE61F32C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00AC37BA-8465-4CCE-AD84-A4ACE61F32C7}.Release|Any CPU.Build.0 = Release|Any CPU
{582C263D-D9FE-487C-834E-0D9F50C9C003}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{582C263D-D9FE-487C-834E-0D9F50C9C003}.Debug|Any CPU.Build.0 = Debug|Any CPU
{582C263D-D9FE-487C-834E-0D9F50C9C003}.Release|Any CPU.ActiveCfg = Release|Any CPU
{582C263D-D9FE-487C-834E-0D9F50C9C003}.Release|Any CPU.Build.0 = Release|Any CPU
{BBB537A6-3925-4061-BFBC-4AE9C6488236}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BBB537A6-3925-4061-BFBC-4AE9C6488236}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BBB537A6-3925-4061-BFBC-4AE9C6488236}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BBB537A6-3925-4061-BFBC-4AE9C6488236}.Release|Any CPU.Build.0 = Release|Any CPU
{56B4573A-BB1E-44CB-9046-09A47CBD2E7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{56B4573A-BB1E-44CB-9046-09A47CBD2E7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{56B4573A-BB1E-44CB-9046-09A47CBD2E7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{56B4573A-BB1E-44CB-9046-09A47CBD2E7C}.Release|Any CPU.Build.0 = Release|Any CPU
{DA269CEC-CF51-4530-BBF8-C9F5018C0E8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DA269CEC-CF51-4530-BBF8-C9F5018C0E8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DA269CEC-CF51-4530-BBF8-C9F5018C0E8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DA269CEC-CF51-4530-BBF8-C9F5018C0E8F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {013603B4-8527-4DC3-B130-94057747C3EA}
SolutionGuid = {93E4131A-53FA-4C11-8922-6E45CAD5A8D4}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion BlazorAuthClient/BlazorAuthClient/Client/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
</CascadingAuthenticationState>
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<RazorLangVersion>3.0</RazorLangVersion>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0-rc1.20223.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.0-rc1.20223.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.0-rc1.20223.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.2.0-preview3.20168.3" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="3.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.0" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Shared\BlazorAuthClient.Shared.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components.Authorization;
using static BlazorAuthClient.Client.CurrentUserService;

namespace BlazorAuthClient.Client
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ else

protected override async Task OnInitializedAsync()
{
forecasts = await Http.GetJsonAsync<WeatherForecast[]>("WeatherForecast");
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("WeatherForecast");
}

}
3 changes: 2 additions & 1 deletion BlazorAuthClient/BlazorAuthClient/Client/Pages/Login.razor
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
ErrorText = string.Empty;
try
{
var userinfo = await Http.PostJsonAsync<UserIdentity>("Authentication", Credentials);
var response = await Http.PostAsJsonAsync("Authentication", Credentials);
var userinfo = await response.Content.ReadFromJsonAsync<UserIdentity>();
if (userinfo.IsAuthenticated)
{
var identity = new ClaimsIdentity(userinfo.AuthenticationType);
Expand Down
10 changes: 5 additions & 5 deletions BlazorAuthClient/BlazorAuthClient/Client/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Components.Authorization;
using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace BlazorAuthClient.Client
{
Expand All @@ -12,9 +12,9 @@ public class Program
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.RootComponents.Add<App>("#app");

builder.Services.AddSingleton(new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddOptions();
builder.Services.AddAuthorizationCore();
builder.Services.AddSingleton<AuthenticationStateProvider, CustomAuthenticationStateProvider>();
Expand Down
45 changes: 23 additions & 22 deletions BlazorAuthClient/BlazorAuthClient/Client/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
@inherits LayoutComponentBase
@inject CurrentUserService CurrentUserService

<div class="sidebar">
<NavMenu />
</div>

<div class="main">
<div class="top-row px-4">
<AuthorizeView>
<Authorized>
Hello, @context.User.Identity.Name
<a href="Logout">Log out</a>
</Authorized>
<NotAuthorized>
<a href="Login">Log in</a>
</NotAuthorized>
<Authorizing>
Authorizing...
</Authorizing>
</AuthorizeView>
<a href="http://blazor.net" target="_blank" class="ml-md-auto">About</a>
<div class="page">
<div class="sidebar">
<NavMenu />
</div>

<div class="content px-4">
@Body
<div class="main">
<div class="top-row px-4 auth">
<AuthorizeView>
<Authorized>
Hello, @context.User.Identity.Name
<a href="Logout">Log out</a>
</Authorized>
<NotAuthorized>
<a href="Login">Log in</a>
</NotAuthorized>
<Authorizing>
Authorizing...
</Authorizing>
</AuthorizeView>
<a href="http://blazor.net" target="_blank" class="ml-md-auto">About</a>
</div>

<div class="content px-4">
@Body
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
.page {
position: relative;
display: flex;
flex-direction: column;
}

.main {
flex: 1;
}

.sidebar {
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
}

.top-row {
background-color: #f7f7f7;
border-bottom: 1px solid #d6d5d5;
justify-content: flex-end;
height: 3.5rem;
display: flex;
align-items: center;
}

.top-row ::deep a, .top-row .btn-link {
white-space: nowrap;
margin-left: 1.5rem;
}

.top-row a:first-child {
overflow: hidden;
text-overflow: ellipsis;
}

@media (max-width: 640.98px) {
.top-row:not(.auth) {
display: none;
}

.top-row.auth {
justify-content: space-between;
}

.top-row a, .top-row .btn-link {
margin-left: 0;
}
}

@media (min-width: 641px) {
.page {
flex-direction: row;
}

.sidebar {
width: 250px;
height: 100vh;
position: sticky;
top: 0;
}

.top-row {
position: sticky;
top: 0;
z-index: 1;
}

.main > div {
padding-left: 2rem !important;
padding-right: 1.5rem !important;
}
}
62 changes: 62 additions & 0 deletions BlazorAuthClient/BlazorAuthClient/Client/Shared/NavMenu.razor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.navbar-toggler {
background-color: rgba(255, 255, 255, 0.1);
}

.top-row {
height: 3.5rem;
background-color: rgba(0,0,0,0.4);
}

.navbar-brand {
font-size: 1.1rem;
}

.oi {
width: 2rem;
font-size: 1.1rem;
vertical-align: text-top;
top: -2px;
}

.nav-item {
font-size: 0.9rem;
padding-bottom: 0.5rem;
}

.nav-item:first-of-type {
padding-top: 1rem;
}

.nav-item:last-of-type {
padding-bottom: 1rem;
}

.nav-item ::deep a {
color: #d7d7d7;
border-radius: 4px;
height: 3rem;
display: flex;
align-items: center;
line-height: 3rem;
}

.nav-item ::deep a.active {
background-color: rgba(255,255,255,0.25);
color: white;
}

.nav-item ::deep a:hover {
background-color: rgba(255,255,255,0.1);
color: white;
}

@media (min-width: 641px) {
.navbar-toggler {
display: none;
}

.collapse {
/* Never collapse the sidebar for wide screens */
display: block;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<span class="text-nowrap">
Please take our
<a target="_blank" class="font-weight-bold" href="https://go.microsoft.com/fwlink/?linkid=2121313">brief survey</a>
<a target="_blank" class="font-weight-bold" href="https://go.microsoft.com/fwlink/?linkid=2137916">brief survey</a>
</span>
and tell us what you think.
</div>
Expand Down
3 changes: 3 additions & 0 deletions BlazorAuthClient/BlazorAuthClient/Client/_Imports.razor
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
@using System.Net.Http
@using System.Net.Http.Json
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.AspNetCore.Components.WebAssembly.Http
@using Microsoft.JSInterop
@using BlazorAuthClient.Client
@using BlazorAuthClient.Client.Shared
50 changes: 50 additions & 0 deletions BlazorAuthClient/BlazorAuthClient/Client/wwwroot/css/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@import url('open-iconic/font/css/open-iconic-bootstrap.min.css');

html, body {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

a, .btn-link {
color: #0366d6;
}

.btn-primary {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}

.content {
padding-top: 1.1rem;
}

.valid.modified:not([type=checkbox]) {
outline: 1px solid #26b050;
}

.invalid {
outline: 1px solid red;
}

.validation-message {
color: red;
}

#blazor-error-ui {
background: lightyellow;
bottom: 0;
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
display: none;
left: 0;
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
position: fixed;
width: 100%;
z-index: 1000;
}

#blazor-error-ui .dismiss {
cursor: pointer;
position: absolute;
right: 0.75rem;
top: 0.5rem;
}
Loading

0 comments on commit 06e2f36

Please sign in to comment.