Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 12 additions & 25 deletions AspNetCore/Blazor/AdHocReporting.BlazorWasm/Client/App.razor
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
@if (context.User.Identity?.IsAuthenticated != true)
{
<RedirectToLogin />
}
else
{
<p role="alert">You are not authorized to access this resource.</p>
}
</NotAuthorized>
</AuthorizeRouteView>
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>EqDemo.Client</RootNamespace>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components" Version="6.0.25" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.8" PrivateAssets="all" />

Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@page "/authentication/{action}"
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
<RemoteAuthenticatorView Action="@Action" />
@page "/authentication/{action}"

<p>Authentication is not configured.</p>

@code{
[Parameter] public string? Action { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
@page "/fetchdata"
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@page "/fetchdata"
@using EqDemo.Shared
@attribute [Authorize]
@inject HttpClient Http

<PageTitle>Weather forecast</PageTitle>
Expand Down Expand Up @@ -45,13 +42,6 @@ else

protected override async Task OnInitializedAsync()
{
try
{
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("WeatherForecast");
}
catch (AccessTokenNotAvailableException exception)
{
exception.Redirect();
}
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("WeatherForecast");
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
@page "/reports"
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication.Internal
@attribute [Authorize]
@page "/reports"
@implements IAsyncDisposable

@inject IJSRuntime JSRuntime
@inject NavigationManager NavigationManager
@inject AuthenticationStateProvider AuthenticationStateProvider
@inject IAccessTokenProviderAccessor AccessTokenProviderAccessor

<style>
.eqv-chart-panel {
Expand All @@ -29,26 +23,12 @@
aria-expanded="false">
<i class="fas fa-cog"></i>
</button>
@if (IsManager)
{
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" id="NewReportButton" href="javascript:void(0)">New report</a>
<a class="dropdown-item" id="SaveReportButton" href="javascript:void(0)">Save as...</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" id="RemoveReportButton" href="javascript:void(0)">Remove report</a>
</div>
}
else
{
<!-- Disable all menu items if the curren user has no rights to manager reports -->
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton" data-toggle="tooltip" data-html="true" data-placement="bottom"
title="@TooltipContent">
<a class="dropdown-item disabled" href="javascript:void(0)">New report</a>
<a class="dropdown-item disabled" href="javascript:void(0)">Save as...</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item disabled" href="javascript:void(0)">Remove report</a>
</div>
}
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" id="NewReportButton" href="javascript:void(0)">New report</a>
<a class="dropdown-item" id="SaveReportButton" href="javascript:void(0)">Save as...</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" id="RemoveReportButton" href="javascript:void(0)">Remove report</a>
</div>
</div>
</div>
<div class="card-body">
Expand Down Expand Up @@ -87,54 +67,23 @@
</div>
<div class="row " id="NoReportPanel" style="visibility:hidden;">
<div class="col-md-12">
@if (IsManager)
{
<h3 class="text-center">
No reports are defined. <a id="FirstReportButton" href="javascript:document.AdhocReportingView.newReport()">Create the first one</a> to start.
</h3>
}
else
{
<h3 class="text-center">
No reports are defined. Please login to a manager account to create reports.
</h3>
}
<h3 class="text-center">
No reports are defined. <a id="FirstReportButton" href="javascript:document.AdhocReportingView.newReport()">Create the first one</a> to start.
</h3>
</div>
</div>
</div>

@code {
public string TooltipContent { get; } = "You are logged with a 'consumer' role that is not allowed to manage reports.<br />"
+ "To test this functionlity - please log out and sign in again with another account.";

public bool IsManager { get; set; }

protected override async Task OnParametersSetAsync()
{
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();

IsManager = authState.User.IsInRole("eq-manager");

await base.OnParametersSetAsync();
}


protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender) {
var result = await AccessTokenProviderAccessor.TokenProvider.RequestAccessToken();
if (result.Status == AccessTokenResultStatus.Success && result.TryGetToken(out var token)) {
await JSRuntime.InvokeVoidAsync("easyquery.blazor.startAdhocReporting", token.Value);
}
else {
await JSRuntime.InvokeVoidAsync("consloe.error", "Unable to get access token");
}
await JSRuntime.InvokeVoidAsync("easyquery.blazor.startAdhocReporting", "");
}

await base.OnAfterRenderAsync(firstRender);
}


private bool _disposed = false;

public async ValueTask DisposeAsync()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;

using EqDemo.Client;
Expand All @@ -8,12 +7,6 @@
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddHttpClient("EqDemo.BlazorWasm.AdhocReporting.ServerAPI", client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress))
.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>();

// Supply HttpClient instances that include access tokens when making requests to the server project
builder.Services.AddScoped(sp => sp.GetRequiredService<IHttpClientFactory>().CreateClient("EqDemo.BlazorWasm.AdhocReporting.ServerAPI"));

builder.Services.AddApiAuthorization();
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

await builder.Build().RunAsync();
Original file line number Diff line number Diff line change
@@ -1,24 +1 @@
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication

@inject NavigationManager Navigation
@inject SignOutSessionStateManager SignOutManager

<AuthorizeView>
<Authorized>
<a href="authentication/profile">Hello, @context.User.Identity?.Name!</a>
<button class="nav-link btn btn-link" @onclick="BeginSignOut">Log out</button>
</Authorized>
<NotAuthorized>
<a href="authentication/register">Register</a>
<a href="authentication/login">Log in</a>
</NotAuthorized>
</AuthorizeView>

@code{
private async Task BeginSignOut(MouseEventArgs args)
{
await SignOutManager.SetSignOutState();
Navigation.NavigateTo("authentication/logout");
}
}
@* Authentication has been removed as part of the .NET 8 migration (IdentityServer was deprecated). *@
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
@inject NavigationManager Navigation

@code {
protected override void OnInitialized()
{
Navigation.NavigateTo($"authentication/login?returnUrl={Uri.EscapeDataString(Navigation.Uri)}");
}
}
@* Authentication has been removed as part of the .NET 8 migration (IdentityServer was deprecated). *@
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>

<script src="_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js"></script>
<script src="_framework/blazor.webassembly.js"></script>

<!-- Google Charts script -->
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
using Microsoft.AspNetCore.ApiAuthorization.IdentityServer;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;

using Duende.IdentityServer.EntityFramework.Options;

using EqDemo.Models;

namespace EqDemo.Data
{
public class AppDbContext : ApiAuthorizationDbContext<ApplicationUser>
public class AppDbContext : IdentityDbContext<ApplicationUser>
{
public AppDbContext(
DbContextOptions options,
IOptions<OperationalStoreOptions> operationalStoreOptions) : base(options, operationalStoreOptions)
DbContextOptions options) : base(options)
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>disable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>EqDemo.BlazorWasm.AdhocReporting.Server</UserSecretsId>
<RootNamespace>EqDemo.Server</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.1" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="2.1.7" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.8" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.0" />
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="6.34.0" />
<PackageReference Include="NuGet.Common" Version="5.11.5" />
<PackageReference Include="NuGet.Protocol" Version="5.11.5" />
Expand All @@ -23,14 +23,14 @@
<ProjectReference Include="..\Shared\EqDemo.BlazorWasm.AdhocReporting.Shared.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.ApiAuthorization.IdentityServer" Version="6.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.8" />

<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.8" />
</ItemGroup>
<ItemGroup>
<!-- DB initialization packages. They are not necessary for EasyQuery working and can be removed in production -->
Expand Down
14 changes: 0 additions & 14 deletions AspNetCore/Blazor/AdHocReporting.BlazorWasm/Server/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.IdentityModel.Tokens.Jwt;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;

Expand Down Expand Up @@ -29,18 +27,7 @@
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<AppDbContext>();

builder.Services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, AppDbContext>(options => {
//the following 2 lines are necessary to support roles on the WebAssembly side
options.IdentityResources["openid"].UserClaims.Add("role");
options.ApiResources.Single().UserClaims.Add("role");
});

// We need to do this as it maps "role" to ClaimTypes.Role and causes issues
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Remove("role");

builder.Services.AddAuthentication()
.AddIdentityServerJwt();

//EasyQuery services
builder.Services.AddEasyQuery()
Expand Down Expand Up @@ -79,7 +66,6 @@

app.UseRouting();

app.UseIdentityServer();
app.UseAuthentication();
app.UseAuthorization();

Expand Down
Loading