Skip to content

Commit

Permalink
Microsoft Entra ID
Browse files Browse the repository at this point in the history
  • Loading branch information
damienbod committed Nov 29, 2023
1 parent bfd0f9c commit b71649b
Show file tree
Hide file tree
Showing 52 changed files with 1,867 additions and 1,867 deletions.
6 changes: 3 additions & 3 deletions BlazorWithApis/BlazorApis.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README_CONFIG.md = README_CONFIG.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorAzureADWithApis.Server", "BlazorAzureADWithApis\Server\BlazorAzureADWithApis.Server.csproj", "{90A119E7-B368-4445-92CA-9474101C2026}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorMicrosoftEntraIDWithApis.Server", "BlazorMicrosoftEntraIDWithApis\Server\BlazorMicrosoftEntraIDWithApis.Server.csproj", "{90A119E7-B368-4445-92CA-9474101C2026}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorAzureADWithApis.Client", "BlazorAzureADWithApis\Client\BlazorAzureADWithApis.Client.csproj", "{ECB9E736-157D-4694-90A0-FDC2474A8544}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorMicrosoftEntraIDWithApis.Client", "BlazorMicrosoftEntraIDWithApis\Client\BlazorMicrosoftEntraIDWithApis.Client.csproj", "{ECB9E736-157D-4694-90A0-FDC2474A8544}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorAzureADWithApis.Shared", "BlazorAzureADWithApis\Shared\BlazorAzureADWithApis.Shared.csproj", "{E875E49E-FB31-446F-8B65-60BDC999AEAD}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorMicrosoftEntraIDWithApis.Shared", "BlazorMicrosoftEntraIDWithApis\Shared\BlazorMicrosoftEntraIDWithApis.Shared.csproj", "{E875E49E-FB31-446F-8B65-60BDC999AEAD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
@if (!context.User.Identity.IsAuthenticated)
{
<RedirectToLogin />
}
else
{
<p>You are not authorized to access this resource.</p>
}
</NotAuthorized>
</AuthorizeRouteView>
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
@if (!context.User.Identity.IsAuthenticated)
{
<RedirectToLogin />
}
else
{
<p>You are not authorized to access this resource.</p>
}
</NotAuthorized>
</AuthorizeRouteView>
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.Authentication.WebAssembly.Msal" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="System.Net.Http.Json" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Shared\BlazorAzureADWithApis.Shared.csproj" />
</ItemGroup>

<ItemGroup>
<ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" />
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.Authentication.WebAssembly.Msal" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="System.Net.Http.Json" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Shared\BlazorMicrosoftEntraIDWithApis.Shared.csproj" />
</ItemGroup>

<ItemGroup>
<ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" />
</ItemGroup>

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

@code{
[Parameter] public string Action { get; set; }
}
@page "/authentication/{action}"
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
<RemoteAuthenticatorView Action="@Action" />

@code{
[Parameter] public string Action { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
@page "/delegateduserapicall"
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@attribute [Authorize]
@inject HttpClient Http

<h1>Data from Delegated User API</h1>

@if (apiData == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Data</th>
</tr>
</thead>
<tbody>
@foreach (var data in apiData)
{
<tr>
<td>@data</td>
</tr>
}
</tbody>
</table>
}

@code {
private string[]? apiData;

protected override async Task OnInitializedAsync()
{
try
{
apiData = await Http.GetFromJsonAsync<string[]>("DelegatedUserApiCalls");
}
catch (AccessTokenNotAvailableException exception)
{
exception.Redirect();
}
}

}
@page "/delegateduserapicall"
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@attribute [Authorize]
@inject HttpClient Http

<h1>Data from Delegated User API</h1>

@if (apiData == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Data</th>
</tr>
</thead>
<tbody>
@foreach (var data in apiData)
{
<tr>
<td>@data</td>
</tr>
}
</tbody>
</table>
}

@code {
private string[]? apiData;

protected override async Task OnInitializedAsync()
{
try
{
apiData = await Http.GetFromJsonAsync<string[]>("DelegatedUserApiCalls");
}
catch (AccessTokenNotAvailableException exception)
{
exception.Redirect();
}
}

}
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
@page "/directapi"
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@attribute [Authorize]
@inject HttpClient Http

<h1>Data from Direct API</h1>

@if (apiData == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Data</th>
</tr>
</thead>
<tbody>
@foreach (var data in apiData)
{
<tr>
<td>@data</td>
</tr>
}
</tbody>
</table>
}

@code {
private string[]? apiData;

protected override async Task OnInitializedAsync()
{
try
{
apiData = await Http.GetFromJsonAsync<string[]>("DirectApi");
}
catch (AccessTokenNotAvailableException exception)
{
exception.Redirect();
}
}

}
@page "/directapi"
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@attribute [Authorize]
@inject HttpClient Http

<h1>Data from Direct API</h1>

@if (apiData == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Data</th>
</tr>
</thead>
<tbody>
@foreach (var data in apiData)
{
<tr>
<td>@data</td>
</tr>
}
</tbody>
</table>
}

@code {
private string[]? apiData;

protected override async Task OnInitializedAsync()
{
try
{
apiData = await Http.GetFromJsonAsync<string[]>("DirectApi");
}
catch (AccessTokenNotAvailableException exception)
{
exception.Redirect();
}
}

}
Loading

0 comments on commit b71649b

Please sign in to comment.