Skip to content

Commit

Permalink
docs: update api sample
Browse files Browse the repository at this point in the history
* docs: update api sample

* docs: remove useless service implementation

* doc: update multitier sample

---------

Co-authored-by: github-actions <[email protected]>
  • Loading branch information
aguacongas and github-actions authored Dec 5, 2023
1 parent 00f2a8e commit ccfb5d1
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 18 deletions.
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ init:
- cmd: git config --global core.autocrlf true
install:
- ps: Install-Product node 18 x64
- ps: .\dotnet-install.ps1 -Version 7.0.11 -Runtime dotnet -Architecture x64 -InstallDir "C:\Program Files\dotnet"
- ps: .\dotnet-install.ps1 -Version 7.0.11 -Runtime aspnetcore -Architecture x64 -InstallDir "C:\Program Files\dotnet"
- ps: .\dotnet-install.ps1 -Version 7.0.14 -Runtime dotnet -Architecture x64 -InstallDir "C:\Program Files\dotnet"
- ps: .\dotnet-install.ps1 -Version 7.0.14 -Runtime aspnetcore -Architecture x64 -InstallDir "C:\Program Files\dotnet"
- ps: .\dotnet-install.ps1 -Version $env:donetsdk -InstallDir "C:\Program Files\dotnet"
- ps: dotnet tool install --global GitVersion.Tool
- ps: dotnet gitversion /l console /output buildserver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
<NoWarn>1701;1702;NU1603</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Aguacongas.IdentityServer.Admin.Duende" Version="7.4.6" />
<PackageReference Include="Aguacongas.IdentityServer.EntityFramework.Store.Duende" Version="7.4.6" />
<PackageReference Include="Aguacongas.TheIdServer.Migrations.SqlServer" Version="7.4.6" />
<PackageReference Include="Aguacongas.IdentityServer.Admin.Duende" Version="8.0.0-preview1-0001" />
<PackageReference Include="Aguacongas.IdentityServer.EntityFramework.Store.Duende" Version="8.0.0-preview1-0001" />
<PackageReference Include="Aguacongas.TheIdServer.Migrations.SqlServer" Version="8.0.0-preview1-0001" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Duende.IdentityServer.Validation;
using System.Threading.Tasks;

namespace Aguacongas.TheIdServer.Api;

public class EmptyClientConfigurationValidator : IClientConfigurationValidator
{
public Task ValidateAsync(ClientConfigurationValidationContext context)
=> Task.CompletedTask;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Aguacongas.IdentityServer.Abstractions;
using Microsoft.AspNetCore.Http;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Aguacongas.TheIdServer.Api;

public class CreatePersonalAccessTokenServvice : ICreatePersonalAccessToken
{
public Task<string> CreatePersonalAccessTokenAsync(HttpContext context, bool isRefenceToken, int lifetimeDays, IEnumerable<string> apis, IEnumerable<string> scopes, IEnumerable<string> claimTypes)
{
throw new System.NotImplementedException();
}
}
14 changes: 14 additions & 0 deletions sample/MultiTiers/Aguacongas.TheIdServer.Api/EventService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Duende.IdentityServer.Events;
using Duende.IdentityServer.Services;
using System.Threading.Tasks;

namespace Aguacongas.TheIdServer.Api;

public class EmptyEventService : IEventService
{
public bool CanRaiseEventType(EventTypes evtType)
=> true;

public Task RaiseAsync(Event evt)
=> Task.CompletedTask;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Project: Aguafrommars/TheIdServer
// Copyright (c) 2023 @Olivier Lefebvre
using Aguacongas.IdentityServer.Admin.Configuration;
using Aguacongas.TheIdServer.Admin.Hubs;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
Expand All @@ -22,6 +23,7 @@ public static IApplicationBuilder UseTheIdServerApi(this IApplicationBuilder app
.UseHsts();
}

ApiBasePath.Value = "/api";
app.UseSerilogRequestLogging()
.UseHttpsRedirection()
.UseResponseCompression()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
// Project: Aguafrommars/TheIdServer
// Copyright (c) 2023 @Olivier Lefebvre
using Aguacongas.AspNetCore.Authentication;
using Aguacongas.IdentityServer.Abstractions;
using Aguacongas.IdentityServer.Admin.Models;
using Aguacongas.IdentityServer.Admin.Services;
using Aguacongas.IdentityServer.Store;
using Aguacongas.TheIdServer.Api;
using Aguacongas.TheIdServer.Authentication;
using Aguacongas.TheIdServer.Data;
using Aguacongas.TheIdServer.Models;
using Duende.IdentityServer;
using Duende.IdentityServer.Configuration;
using Duende.IdentityServer.Events;
using Duende.IdentityServer.Services;
using Duende.IdentityServer.Services.KeyManagement;
using Duende.IdentityServer.Stores;
using Duende.IdentityServer.Validation;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.ResponseCompression;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using System;
using System.Linq;
using System.Reflection;
using System.Net.Http;

namespace Microsoft.AspNetCore.Builder
{
Expand All @@ -35,14 +48,26 @@ public static WebApplicationBuilder AddTheIdServerApi(this WebApplicationBuilder
.AddOperationalEntityFrameworkStores(options =>
options.UseSqlServer(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly)));

services.AddIdentityProviderStore()
.AddConfigurationStores()
.AddOperationalStores();

services.AddIdentity<ApplicationUser, IdentityRole>(
options =>
{
configuration.Bind(nameof(IdentityOptions), options);
})
.AddTheIdServerStores()
.AddDefaultTokenProviders();

var signalRBuilder = services.AddSignalR(options => configuration.GetSection("SignalR:HubOptions").Bind(options));
if (configuration.GetValue<bool>("SignalR:UseMessagePack"))
{
signalRBuilder.AddMessagePackProtocol();
}


services.Configure<SendGridOptions>(configuration)
.AddLocalization()
.AddControllersWithViews(options =>
{
options.AddIdentityServerAdminFilters();
Expand All @@ -53,7 +78,8 @@ public static WebApplicationBuilder AddTheIdServerApi(this WebApplicationBuilder
settings.NullValueHandling = NullValueHandling.Ignore;
settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
})
.AddIdentityServerAdmin<ApplicationUser, SchemeDefinition>();
.AddIdentityServerAdmin<ApplicationUser, SchemeDefinition>()
.AddTheIdServerEntityFrameworkStore();

services.AddAuthorization(options =>
{
Expand Down Expand Up @@ -83,6 +109,30 @@ public static WebApplicationBuilder AddTheIdServerApi(this WebApplicationBuilder
new[] { "application/octet-stream" });
});

services.AddTransient<ISchemeChangeSubscriber, SchemeChangeSubscriber>();

services.Configure<IdentityServerOptions>(options => options.IssuerUri = "https://localhost:5443")
.AddTransient(p => p.GetRequiredService<IOptions<IdentityServerOptions>>().Value)
.AddTransient<IClientConfigurationValidator, EmptyClientConfigurationValidator>()
.AddTransient<IEventService, EmptyEventService>();

services.RemoveAll<ICreatePersonalAccessToken>();
services.AddTransient<ICreatePersonalAccessToken, CreatePersonalAccessTokenServvice>();

services.AddScoped<IAuthenticationSchemeOptionsSerializer, AuthenticationSchemeOptionsSerializer>();

services.AddTransient(p =>
{
var handler = new HttpClientHandler();
if (configuration.GetValue<bool>("DisableStrictSsl"))
{
#pragma warning disable S4830 // Server certificates should be verified during SSL/TLS connections
handler.ServerCertificateCustomValidationCallback = (message, cert, chain, policy) => true;
#pragma warning restore S4830 // Server certificates should be verified during SSL/TLS connections
}
return handler;
});

return webApplicationBuilder;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Aguacongas.IdentityServer.Abstractions;
using System.Threading;
using System.Threading.Tasks;

namespace Aguacongas.TheIdServer.Api;

public class SchemeChangeSubscriber : ISchemeChangeSubscriber
{
public Task SubscribeAsync(CancellationToken cancellationToken)
=> Task.CompletedTask;

public Task UnSubscribeAsync(CancellationToken cancellationToken)
=> Task.CompletedTask;
}
8 changes: 8 additions & 0 deletions sample/MultiTiers/Aguacongas.TheIdServer.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
"SignInOptions": {
"RequireConfirmedAccount": false
},
"ApiAuthentication": {
"Authority": "https://localhost:5443",
"RequireHttpsMetadata": false,
"ApiName": "theidserveradminapi",
"ApiSecret": "5b556f7c-b3bc-4b5b-85ab-45eed0cb962d",
"EnableCaching": true,
"CacheDuration": "0:10:0"
},
"SignalR": {
"HubUrl": "https://localhost:8443/providerhub",
"HubOptions": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ public static class ApiBasePath
/// <summary>
/// The api base path value
/// </summary>
public static string Value { get; set; } = "api/";
public static string Value { get; set; } = "/api";
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using Microsoft.AspNetCore.Mvc.Routing;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Aguacongas.IdentityServer.Admin.Configuration;

Expand All @@ -21,8 +17,9 @@ public class ApiRouteAttribute : Attribute, IRouteTemplateProvider
/// <param name="template">The route template. May not be null.</param>
public ApiRouteAttribute([StringSyntax("Route")] string template)
{
ArgumentException.ThrowIfNullOrWhiteSpace(template);
var routeBasePath = $"{ApiBasePath.Value[1..]}/";
Template = $"{routeBasePath}{template ?? throw new ArgumentNullException(nameof(template))}";
Template = $"{routeBasePath}{template}";
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ public static class EndpointRoutingApplicationBuilderExtensions
/// <param name="builder">The builder.</param>
/// <param name="basePath">The base path.</param>
/// <param name="configure">The configure.</param>
/// <param name="notAllowedApiRewritePath">(Optional) the rewritten path when an api route match outside the base path</param>
/// <returns></returns>
public static IApplicationBuilder UseIdentityServerAdminApi(this IApplicationBuilder builder,
string basePath,
Action<IApplicationBuilder> configure,
string notAllowedApiRewritePath = "not-allowed")
Action<IApplicationBuilder> configure)
{
ApiBasePath.Value = basePath;

Expand Down

0 comments on commit ccfb5d1

Please sign in to comment.