Skip to content
Merged
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
2 changes: 0 additions & 2 deletions OpenIddict.Samples.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
<Folder Name="/samples/Balosar/">
<Project Path="samples/Balosar/Balosar.Client/Balosar.Client.csproj" />
<Project Path="samples/Balosar/Balosar.Server/Balosar.Server.csproj" />
<Project Path="samples/Balosar/Balosar.Shared/Balosar.Shared.csproj" />
</Folder>

<Folder Name="/samples/Contruum/">
Expand All @@ -43,7 +42,6 @@
<Project Path="samples/Dantooine/Dantooine.Server/Dantooine.Server.csproj" />
<Project Path="samples/Dantooine/Dantooine.WebAssembly.Client/Dantooine.WebAssembly.Client.csproj" />
<Project Path="samples/Dantooine/Dantooine.WebAssembly.Server/Dantooine.WebAssembly.Server.csproj" />
<Project Path="samples/Dantooine/Dantooine.WebAssembly.Shared/Dantooine.WebAssembly.Shared.csproj" />
</Folder>

<Folder Name="/samples/Fornax/">
Expand Down
4 changes: 0 additions & 4 deletions samples/Balosar/Balosar.Client/Balosar.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
</PropertyGroup>

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

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" />
Expand Down
11 changes: 10 additions & 1 deletion samples/Balosar/Balosar.Client/Pages/FetchData.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@page "/fetchdata"
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using Balosar.Shared
@attribute [Authorize]
@inject HttpClient Http

Expand Down Expand Up @@ -53,4 +52,14 @@ else
}
}

class WeatherForecast
{
public DateTime Date { get; set; }

public int TemperatureC { get; set; }

public required string Summary { get; set; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
}
10 changes: 2 additions & 8 deletions samples/Balosar/Balosar.Client/Program.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
using Balosar.Client;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Options;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");

builder.Services.AddHttpClient("Balosar.ServerAPI")
builder.Services.AddHttpClient(Options.DefaultName)
.ConfigureHttpClient(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(provider =>
{
var factory = provider.GetRequiredService<IHttpClientFactory>();
return factory.CreateClient("Balosar.ServerAPI");
});

builder.Services.AddOidcAuthentication(options =>
{
options.ProviderOptions.ClientId = "balosar-blazor-client";
Expand Down
1 change: 0 additions & 1 deletion samples/Balosar/Balosar.Server/Balosar.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

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

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public async Task<IActionResult> Authorize()
.SetClaim(Claims.Email, await _userManager.GetEmailAsync(user))
.SetClaim(Claims.Name, await _userManager.GetUserNameAsync(user))
.SetClaim(Claims.PreferredUsername, await _userManager.GetUserNameAsync(user))
.SetClaims(Claims.Role, [.. (await _userManager.GetRolesAsync(user))]);
.SetClaims(Claims.Role, [.. await _userManager.GetRolesAsync(user)]);

// Note: in this sample, the granted scopes match the requested scope
// but you may want to allow the user to uncheck specific scopes.
Expand Down Expand Up @@ -232,7 +232,7 @@ public async Task<IActionResult> Accept()
.SetClaim(Claims.Email, await _userManager.GetEmailAsync(user))
.SetClaim(Claims.Name, await _userManager.GetUserNameAsync(user))
.SetClaim(Claims.PreferredUsername, await _userManager.GetUserNameAsync(user))
.SetClaims(Claims.Role, [.. (await _userManager.GetRolesAsync(user))]);
.SetClaims(Claims.Role, [.. await _userManager.GetRolesAsync(user)]);

// Note: in this sample, the granted scopes match the requested scope
// but you may want to allow the user to uncheck specific scopes.
Expand Down Expand Up @@ -332,7 +332,7 @@ public async Task<IActionResult> Exchange()
.SetClaim(Claims.Email, await _userManager.GetEmailAsync(user))
.SetClaim(Claims.Name, await _userManager.GetUserNameAsync(user))
.SetClaim(Claims.PreferredUsername, await _userManager.GetUserNameAsync(user))
.SetClaims(Claims.Role, [.. (await _userManager.GetRolesAsync(user))]);
.SetClaims(Claims.Role, [.. await _userManager.GetRolesAsync(user)]);

identity.SetDestinations(GetDestinations);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Balosar.Shared;
using Balosar.Server.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OpenIddict.Validation.AspNetCore;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Balosar.Shared;
namespace Balosar.Server.Models;

public class WeatherForecast
{
Expand Down
11 changes: 0 additions & 11 deletions samples/Balosar/Balosar.Shared/Balosar.Shared.csproj

This file was deleted.

2 changes: 1 addition & 1 deletion samples/Dantooine/Dantooine.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
app.UseAuthentication();
app.UseAuthorization();

app.MapGet("api/DantooineApi", [Authorize] () => new string[] { "data1", "data2" });
app.MapGet("api/downstream-api", () => new[] { "data1", "data2" }).RequireAuthorization();

app.Run();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public async Task<IActionResult> Authorize()
.SetClaim(Claims.Email, await _userManager.GetEmailAsync(user))
.SetClaim(Claims.Name, await _userManager.GetUserNameAsync(user))
.SetClaim(Claims.PreferredUsername, await _userManager.GetUserNameAsync(user))
.SetClaims(Claims.Role, [.. (await _userManager.GetRolesAsync(user))]);
.SetClaims(Claims.Role, [.. await _userManager.GetRolesAsync(user)]);

// Note: in this sample, the granted scopes match the requested scope
// but you may want to allow the user to uncheck specific scopes.
Expand Down Expand Up @@ -232,7 +232,7 @@ public async Task<IActionResult> Accept()
.SetClaim(Claims.Email, await _userManager.GetEmailAsync(user))
.SetClaim(Claims.Name, await _userManager.GetUserNameAsync(user))
.SetClaim(Claims.PreferredUsername, await _userManager.GetUserNameAsync(user))
.SetClaims(Claims.Role, [.. (await _userManager.GetRolesAsync(user))]);
.SetClaims(Claims.Role, [.. await _userManager.GetRolesAsync(user)]);

// Note: in this sample, the granted scopes match the requested scope
// but you may want to allow the user to uncheck specific scopes.
Expand Down Expand Up @@ -332,7 +332,7 @@ public async Task<IActionResult> Exchange()
.SetClaim(Claims.Email, await _userManager.GetEmailAsync(user))
.SetClaim(Claims.Name, await _userManager.GetUserNameAsync(user))
.SetClaim(Claims.PreferredUsername, await _userManager.GetUserNameAsync(user))
.SetClaims(Claims.Role, [.. (await _userManager.GetRolesAsync(user))]);
.SetClaims(Claims.Role, [.. await _userManager.GetRolesAsync(user)]);

identity.SetDestinations(GetDestinations);

Expand Down
11 changes: 7 additions & 4 deletions samples/Dantooine/Dantooine.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ static async Task RegisterApplicationsAsync(IServiceProvider provider)
// Blazor Hosted
if (await manager.FindByClientIdAsync("blazorcodeflowpkceclient") is null)
{
await manager.CreateAsync(new OpenIddictApplicationDescriptor
var descriptor = new OpenIddictApplicationDescriptor
{
ClientId = "blazorcodeflowpkceclient",
ConsentType = ConsentTypes.Explicit,
Expand Down Expand Up @@ -217,14 +217,17 @@ await manager.CreateAsync(new OpenIddictApplicationDescriptor
Permissions.ResponseTypes.Code,
Permissions.Scopes.Email,
Permissions.Scopes.Profile,
Permissions.Scopes.Roles,
Permissions.Prefixes.Scope + "api1"
Permissions.Scopes.Roles
},
Requirements =
{
Requirements.Features.ProofKeyForCodeExchange
}
});
};

descriptor.AddScopePermissions("api1");

await manager.CreateAsync(descriptor);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,4 @@
<PackageReference Include="Microsoft.Extensions.Http" />
</ItemGroup>

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

</Project>

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
@page "/downstream-api"
@using System.Net
@inject HttpClient client
@inject NavigationManager manager
@inject AuthenticationStateProvider provider
@inject IJSRuntime runtime

<h1>Data retrieved from downstream API via YARP</h1>

@if (data is null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
@for (var index = 0; index < data.Length; index++)
{
<tr>
<td>@data[index]</td>
</tr>
}
</tbody>
</table>
}

@code {
private string[] data = default!;

protected override async Task OnInitializedAsync()
{
var state = await provider.GetAuthenticationStateAsync();
if (state is not { User.Identity.IsAuthenticated: true })
{
manager.NavigateTo($"login?returnUrl=/{Uri.EscapeDataString(manager.ToBaseRelativePath(manager.Uri))}", true);
return;
}

client.DefaultRequestHeaders.Add("X-XSRF-TOKEN", await runtime.InvokeAsync<string>("getAntiForgeryToken"));

try
{
data = (await client.GetFromJsonAsync<string[]>("api/downstream-api"))!;
}

catch (HttpRequestException exception) when (exception.StatusCode is HttpStatusCode.Unauthorized)
{
manager.NavigateTo($"login?returnUrl=/{Uri.EscapeDataString(manager.ToBaseRelativePath(manager.Uri))}", true);
return;
}
}
}
Loading
Loading