-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e8dd7fd
Showing
159 changed files
with
14,350 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<CascadingAuthenticationState> | ||
<Router AppAssembly="typeof(Program).Assembly"> | ||
<NotFoundContent> | ||
<p>Sorry, there's nothing at this address.</p> | ||
</NotFoundContent> | ||
</Router> | ||
</CascadingAuthenticationState> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<LangVersion>7.3</LangVersion> | ||
<RazorLangVersion>3.0</RazorLangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview6.19307.2" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview6.19307.2" PrivateAssets="all" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.0.0-preview6.19307.2" PrivateAssets="all" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@page "/counter" | ||
|
||
<h1>Counter</h1> | ||
|
||
<p>Current count: @currentCount</p> | ||
|
||
<button class="btn btn-primary" @onclick="@IncrementCount">Click me</button> | ||
|
||
@code { | ||
int currentCount = 0; | ||
|
||
void IncrementCount() | ||
{ | ||
currentCount++; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
@page "/fetchdata" | ||
@inject HttpClient Http | ||
|
||
<h1>Weather forecast</h1> | ||
|
||
<p>This component demonstrates fetching data from the server.</p> | ||
|
||
@if (forecasts == null) | ||
{ | ||
<p><em>Loading...</em></p> | ||
} | ||
else | ||
{ | ||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th>Date</th> | ||
<th>Temp. (C)</th> | ||
<th>Temp. (F)</th> | ||
<th>Summary</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach (var forecast in forecasts) | ||
{ | ||
<tr> | ||
<td>@forecast.Date.ToShortDateString()</td> | ||
<td>@forecast.TemperatureC</td> | ||
<td>@forecast.TemperatureF</td> | ||
<td>@forecast.Summary</td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
} | ||
|
||
@code { | ||
WeatherForecast[] forecasts; | ||
|
||
protected override async Task OnInitAsync() | ||
{ | ||
forecasts = await Http.GetJsonAsync<WeatherForecast[]>("sample-data/weather.json"); | ||
} | ||
|
||
class WeatherForecast | ||
{ | ||
public DateTime Date { get; set; } | ||
|
||
public int TemperatureC { get; set; } | ||
|
||
public int TemperatureF { get; set; } | ||
|
||
public string Summary { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
@page "/" | ||
@using Services.Auth | ||
@inject CustomAuthStateProvider CustomAuthStateProvider | ||
<h1>Hello, world!</h1> | ||
|
||
Welcome to your new app. | ||
|
||
<SurveyPrompt Title="How is Blazor working for you?" /> | ||
|
||
<Microsoft.AspNetCore.Components.AuthorizeView> | ||
<NotAuthorized> | ||
Not Authorized | ||
</NotAuthorized> | ||
<Authorizing> | ||
Authorizing | ||
</Authorizing> | ||
<Authorized> | ||
Authorized | ||
@context.User.Identity.Name | ||
</Authorized> | ||
</Microsoft.AspNetCore.Components.AuthorizeView> | ||
<button onclick="@(() => UpdateAuthentication(true))"> | ||
Set Auth True | ||
</button> | ||
<button onclick="@(() => UpdateAuthentication(false))"> | ||
Set Auth False | ||
</button> | ||
|
||
@code | ||
{ | ||
[CascadingParameter] | ||
private Task<AuthenticationState> AuthenticationStateTask { get; set; } | ||
|
||
private async Task UpdateAuthentication(bool isAuthenticated) | ||
{ | ||
CustomAuthStateProvider.Authenticated = isAuthenticated; | ||
CustomAuthStateProvider.NotifyStateChange(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@layout MainLayout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.AspNetCore.Blazor.Hosting; | ||
|
||
namespace BlazorAuth | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
CreateHostBuilder(args).Build().Run(); | ||
} | ||
|
||
public static IWebAssemblyHostBuilder CreateHostBuilder(string[] args) => | ||
BlazorWebAssemblyHost.CreateDefaultBuilder() | ||
.UseBlazorStartup<Startup>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Security.Claims; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Components; | ||
|
||
namespace BlazorAuth.Services.Auth | ||
{ | ||
public class CustomAuthStateProvider : AuthenticationStateProvider | ||
{ | ||
public static bool Authenticated { get; set ;} = true; | ||
public override async Task<AuthenticationState> GetAuthenticationStateAsync() | ||
{ | ||
var claimsIdentity = Authenticated ? new ClaimsIdentity(new List<Claim> | ||
{ | ||
new Claim(ClaimTypes.Name, "test_user") | ||
}, "server_auth") | ||
: | ||
new ClaimsIdentity(); | ||
return new AuthenticationState(new ClaimsPrincipal(claimsIdentity)); | ||
} | ||
|
||
public async Task NotifyStateChange() | ||
{ | ||
Console.WriteLine($"Calling NotifyStateChange... with Auth={Authenticated}"); | ||
NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.