Skip to content

Commit

Permalink
Release/1.0.0 preview5 (#10)
Browse files Browse the repository at this point in the history
* Fix #5

* Fix #8

* Fix authorization for API

* Fix default schema

* Fix identity services

* Add higher version 1.0.0-preview5

* Remove SignInManager which is not necessary for API services

* Fix missing HttpContextAccessor for Audit Logging

* Remove unused HashTypeEnum;

* Update template to 1.0.0-preview5

* Update README.md
  • Loading branch information
skoruba authored May 1, 2021
1 parent a07a55f commit 0d20724
Show file tree
Hide file tree
Showing 50 changed files with 201 additions and 115 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The application is written in the **Asp.Net Core MVC - using .NET 5.0**
- 🔒 **NOTE:** The project uses the default database migrations which affect your database therefore double check the migrations according to your database provider and create a database backup

```sh
dotnet new -i Skoruba.Duende.IdentityServer.Admin.Templates::1.0.0-preview4
dotnet new -i Skoruba.Duende.IdentityServer.Admin.Templates::1.0.0-preview5
```

### Create new project:
Expand Down
3 changes: 3 additions & 0 deletions build/publish-nuget-project-template.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
param([string] $version, [string] $key)

dotnet nuget push ../templates/Skoruba.Duende.IdentityServer.Admin.Templates.$version.nupkg -k $key -s https://api.nuget.org/v3/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ namespace Skoruba.Duende.IdentityServer.Admin.Api.Configuration.Constants
public class AuthorizationConsts
{
public const string AdministrationPolicy = "RequireAdministratorRole";
public const string ApiScopePolicy = "ApiScope";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class ApiSecretApiDto
[Required]
public string Value { get; set; }

public string HashType { get; set; }

public DateTime? Expiration { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.ComponentModel.DataAnnotations;
using Skoruba.Duende.IdentityServer.Admin.EntityFramework.Helpers;

namespace Skoruba.Duende.IdentityServer.Admin.Api.Dtos.Clients
{
Expand All @@ -21,8 +20,6 @@ public class ClientSecretApiDto

public string HashType { get; set; }

public HashType HashTypeEnum => Enum.TryParse(HashType, true, out HashType result) ? result : EntityFramework.Helpers.HashType.Sha256;

public DateTime? Expiration { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public static IServiceCollection AddAuditEventLogging<TAuditLoggingDbContext, TA
where TAuditLog : AuditLog, new()
where TAuditLoggingDbContext : IAuditLoggingDbContext<TAuditLog>
{
services.AddHttpContextAccessor();

var auditLoggingConfiguration = configuration.GetSection(nameof(AuditLoggingConfiguration))
.Get<AuditLoggingConfiguration>();
services.AddSingleton(auditLoggingConfiguration);
Expand Down Expand Up @@ -184,8 +186,8 @@ public static void AddApiAuthentication<TIdentityDbContext, TUser, TRole>(this I
{
var adminApiConfiguration = configuration.GetSection(nameof(AdminApiConfiguration)).Get<AdminApiConfiguration>();

services
.AddIdentity<TUser, TRole>(options => configuration.GetSection(nameof(IdentityOptions)).Bind(options))
services.AddIdentityCore<TUser>(options => configuration.GetSection(nameof(IdentityOptions)).Bind(options))
.AddRoles<TRole>()
.AddEntityFrameworkStores<TIdentityDbContext>()
.AddDefaultTokenProviders();

Expand All @@ -194,16 +196,8 @@ public static void AddApiAuthentication<TIdentityDbContext, TUser, TRole>(this I
{
options.Authority = adminApiConfiguration.IdentityServerBaseUrl;
options.RequireHttpsMetadata = adminApiConfiguration.RequireHttpsMetadata;
options.Audience = adminApiConfiguration.OidcApiName;
});

services.AddAuthorization(options =>
{
options.AddPolicy(AuthorizationConsts.ApiScopePolicy, policy =>
{
policy.RequireAuthenticatedUser();
policy.RequireClaim(JwtClaimTypes.Scope, adminApiConfiguration.OidcApiName);
});
});
}

/// <summary>
Expand Down Expand Up @@ -255,9 +249,9 @@ public static void AddAuthorizationPolicies(this IServiceCollection services)
options.AddPolicy(AuthorizationConsts.AdministrationPolicy,
policy =>
policy.RequireAssertion(context => context.User.HasClaim(c =>
(c.Type == JwtClaimTypes.Role && c.Value == adminApiConfiguration.AdministrationRole) ||
(c.Type == $"client_{JwtClaimTypes.Role}" && c.Value == adminApiConfiguration.AdministrationRole)
)
((c.Type == JwtClaimTypes.Role && c.Value == adminApiConfiguration.AdministrationRole) ||
(c.Type == $"client_{JwtClaimTypes.Role}" && c.Value == adminApiConfiguration.AdministrationRole))
) && context.User.HasClaim(c => c.Type == JwtClaimTypes.Scope && c.Value == adminApiConfiguration.OidcApiName)
));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>1.0.0-preview4</Version>
<Version>1.0.0-preview5</Version>
<Authors>Jan Škoruba</Authors>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<UserSecretsId>1cc472a2-4e4b-48ce-846b-5219f71fc643</UserSecretsId>
Expand Down Expand Up @@ -85,3 +85,4 @@




5 changes: 3 additions & 2 deletions src/Skoruba.Duende.IdentityServer.Admin.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
Expand Down Expand Up @@ -33,6 +34,7 @@ public class Startup
{
public Startup(IWebHostEnvironment env, IConfiguration configuration)
{
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
HostingEnvironment = env;
Configuration = configuration;
}
Expand Down Expand Up @@ -138,8 +140,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, AdminApi
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute()
.RequireAuthorization(AuthorizationConsts.ApiScopePolicy);
endpoints.MapControllers();
endpoints.MapHealthChecks("/health", new HealthCheckOptions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>1.0.0-preview4</Version>
<Version>1.0.0-preview5</Version>
<Authors>Jan Škoruba</Authors>
<Description>Business Logic layer for the administration of the Asp.Net Core Identity and Duende IdentityServer</Description>
<PackageTags>Duende IdentityServer Admin OpenIDConnect OAuth2 Identity</PackageTags>
Expand Down Expand Up @@ -42,3 +42,4 @@




Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>1.0.0-preview4</Version>
<Version>1.0.0-preview5</Version>
<Authors>Jan Škoruba</Authors>
<PackageTags>Duende IdentityServer Admin OpenIDConnect OAuth2 Identity</PackageTags>
<Description>Shared Business Logic layer for the administration of the Duende IdentityServer and Asp.Net Core Identity</Description>
Expand All @@ -25,3 +25,4 @@




Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public ClientDto()
Claims = new List<ClientClaimDto>();
ClientSecrets = new List<ClientSecretDto>();
Properties = new List<ClientPropertyDto>();
AllowedIdentityTokenSigningAlgorithms = new List<string>();
}

public ClientType ClientType { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>1.0.0-preview4</Version>
<Version>1.0.0-preview5</Version>
<Authors>Jan Škoruba</Authors>
<Description>Business Logic layer for the administration of the Duende IdentityServer</Description>
<PackageTags>Duende IdentityServer Admin OpenIDConnect OAuth2 Identity</PackageTags>
Expand Down Expand Up @@ -72,3 +72,4 @@




Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,23 @@ public static class DatabaseExtensions
// Config DB from existing connection
services.AddConfigurationDbContext<TConfigurationDbContext>(options =>
options.ConfigureDbContext = b =>
b.UseMySql(connectionStrings.IdentityDbConnection, ServerVersion.AutoDetect(connectionStrings.ConfigurationDbConnection), sql => sql.MigrationsAssembly(databaseMigrations.ConfigurationDbMigrationsAssembly ?? migrationsAssembly)));
b.UseMySql(connectionStrings.ConfigurationDbConnection, ServerVersion.AutoDetect(connectionStrings.ConfigurationDbConnection), sql => sql.MigrationsAssembly(databaseMigrations.ConfigurationDbMigrationsAssembly ?? migrationsAssembly)));

// Operational DB from existing connection
services.AddOperationalDbContext<TPersistedGrantDbContext>(options => options.ConfigureDbContext = b =>
b.UseMySql(connectionStrings.IdentityDbConnection, ServerVersion.AutoDetect(connectionStrings.PersistedGrantDbConnection), sql => sql.MigrationsAssembly(databaseMigrations.PersistedGrantDbMigrationsAssembly ?? migrationsAssembly)));
b.UseMySql(connectionStrings.PersistedGrantDbConnection, ServerVersion.AutoDetect(connectionStrings.PersistedGrantDbConnection), sql => sql.MigrationsAssembly(databaseMigrations.PersistedGrantDbMigrationsAssembly ?? migrationsAssembly)));

// Log DB from existing connection
services.AddDbContext<TLogDbContext>(options => options.UseMySql(connectionStrings.IdentityDbConnection, ServerVersion.AutoDetect(connectionStrings.AdminLogDbConnection),
services.AddDbContext<TLogDbContext>(options => options.UseMySql(connectionStrings.AdminLogDbConnection, ServerVersion.AutoDetect(connectionStrings.AdminLogDbConnection),
optionsSql => optionsSql.MigrationsAssembly(databaseMigrations.AdminLogDbMigrationsAssembly ?? migrationsAssembly)));

// Audit logging connection
services.AddDbContext<TAuditLoggingDbContext>(options => options.UseMySql(connectionStrings.IdentityDbConnection, ServerVersion.AutoDetect(connectionStrings.AdminAuditLogDbConnection),
services.AddDbContext<TAuditLoggingDbContext>(options => options.UseMySql(connectionStrings.AdminAuditLogDbConnection, ServerVersion.AutoDetect(connectionStrings.AdminAuditLogDbConnection),
optionsSql => optionsSql.MigrationsAssembly(databaseMigrations.AdminAuditLogDbMigrationsAssembly ?? migrationsAssembly)));

// DataProtectionKey DB from existing connection
if(!string.IsNullOrEmpty(connectionStrings.DataProtectionDbConnection))
services.AddDbContext<TDataProtectionDbContext>(options => options.UseMySql(connectionStrings.IdentityDbConnection, ServerVersion.AutoDetect(connectionStrings.DataProtectionDbConnection),
services.AddDbContext<TDataProtectionDbContext>(options => options.UseMySql(connectionStrings.DataProtectionDbConnection, ServerVersion.AutoDetect(connectionStrings.DataProtectionDbConnection),
optionsSql => optionsSql.MigrationsAssembly(databaseMigrations.DataProtectionDbMigrationsAssembly ?? migrationsAssembly)));
}

Expand Down Expand Up @@ -99,13 +99,13 @@ public static class DatabaseExtensions
services.AddDbContext<TIdentityDbContext>(options => options.UseMySql(identityConnectionString, ServerVersion.AutoDetect(identityConnectionString), sql => sql.MigrationsAssembly(migrationsAssembly)));

// Config DB from existing connection
services.AddConfigurationDbContext<TConfigurationDbContext>(options => options.ConfigureDbContext = b => b.UseMySql(identityConnectionString, ServerVersion.AutoDetect(configurationConnectionString), sql => sql.MigrationsAssembly(migrationsAssembly)));
services.AddConfigurationDbContext<TConfigurationDbContext>(options => options.ConfigureDbContext = b => b.UseMySql(configurationConnectionString, ServerVersion.AutoDetect(configurationConnectionString), sql => sql.MigrationsAssembly(migrationsAssembly)));

// Operational DB from existing connection
services.AddOperationalDbContext<TPersistedGrantDbContext>(options => options.ConfigureDbContext = b => b.UseMySql(identityConnectionString, ServerVersion.AutoDetect(persistedGrantConnectionString), sql => sql.MigrationsAssembly(migrationsAssembly)));
services.AddOperationalDbContext<TPersistedGrantDbContext>(options => options.ConfigureDbContext = b => b.UseMySql(persistedGrantConnectionString, ServerVersion.AutoDetect(persistedGrantConnectionString), sql => sql.MigrationsAssembly(migrationsAssembly)));

// DataProtectionKey DB from existing connection
services.AddDbContext<TDataProtectionDbContext>(options => options.UseMySql(identityConnectionString, ServerVersion.AutoDetect(dataProtectionConnectionString),
services.AddDbContext<TDataProtectionDbContext>(options => options.UseMySql(dataProtectionConnectionString, ServerVersion.AutoDetect(dataProtectionConnectionString),
optionsSql => optionsSql.MigrationsAssembly(migrationsAssembly)));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>1.0.0-preview4</Version>
<Version>1.0.0-preview5</Version>
<Authors>Jan Škoruba</Authors>
<PackageTags>Duende IdentityServer Admin OpenIDConnect OAuth2 Identity</PackageTags>
<Description>Entity Framework configuration for the administration of the Duende IdentityServer and Asp.Net Core Identity</Description>
Expand Down Expand Up @@ -32,3 +32,4 @@




Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>1.0.0-preview4</Version>
<Version>1.0.0-preview5</Version>
<Authors>Jan Škoruba</Authors>
<PackageTags>Duende IdentityServer Admin OpenIDConnect OAuth2 Identity</PackageTags>
<Description>EntityFramework extensions for the administration of the Duende IdentityServer and Asp.Net Core Identity</Description>
Expand All @@ -25,3 +25,4 @@




Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>1.0.0-preview4</Version>
<Version>1.0.0-preview5</Version>
<Authors>Jan Škoruba</Authors>
<Description>Entity Framework layer for the administration of the Asp.Net Core Identity and Duende IdentityServer</Description>
<PackageTags>Duende IdentityServer Admin OpenIDConnect OAuth2 Identity</PackageTags>
Expand Down Expand Up @@ -34,3 +34,4 @@




Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>1.0.0-preview4</Version>
<Version>1.0.0-preview5</Version>
<Authors>Jan Škoruba</Authors>
<PackageTags>Duende IdentityServer Admin OpenIDConnect OAuth2 Identity</PackageTags>
<Description>Entity Framework layer for the administration of the Duende IdentityServer and Asp.Net Core Identity with MySql support</Description>
Expand Down Expand Up @@ -37,3 +37,4 @@




Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>1.0.0-preview4</Version>
<Version>1.0.0-preview5</Version>
<Authors>Jan Škoruba</Authors>
<PackageTags>Duende IdentityServer Admin OpenIDConnect OAuth2 Identity</PackageTags>
<Description>Entity Framework layer for the administration of the Duende IdentityServer and Asp.Net Core Identity with PostrgreSQL support</Description>
Expand Down Expand Up @@ -36,3 +36,4 @@




Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>1.0.0-preview4</Version>
<Version>1.0.0-preview5</Version>
<Authors>Jan Škoruba</Authors>
<PackageTags>Duende IdentityServer Admin OpenIDConnect OAuth2 Identity</PackageTags>
<Description>DbContexts and Identity entities for the administration of the Duende IdentityServer and Asp.Net Core Identity</Description>
Expand Down Expand Up @@ -35,3 +35,4 @@




Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>1.0.0-preview4</Version>
<Version>1.0.0-preview5</Version>
<Authors>Jan Škoruba</Authors>
<PackageTags>Duende IdentityServer Admin OpenIDConnect OAuth2 Identity</PackageTags>
<Description>Entity Framework layer for the administration of the Duende IdentityServer and Asp.Net Core Identity with SqlServer support</Description>
Expand Down Expand Up @@ -36,3 +36,4 @@




Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>1.0.0-preview4</Version>
<Version>1.0.0-preview5</Version>
<Authors>Jan Škoruba</Authors>
<PackageTags>Duende IdentityServer Admin OpenIDConnect OAuth2 Identity</PackageTags>
<Description>Entity Framework layer for the administration of the Duende IdentityServer</Description>
Expand Down Expand Up @@ -33,3 +33,4 @@




Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>1.0.0-preview4</Version>
<Version>1.0.0-preview5</Version>
<Authors>Jan Škoruba</Authors>
<Description>The package with UI for the administration of the Duende IdentityServer</Description>
<PackageTags>Duende IdentityServer Admin OpenIDConnect OAuth2 Identity</PackageTags>
Expand Down Expand Up @@ -125,3 +125,4 @@




Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>1.0.0-preview4</Version>
<Version>1.0.0-preview5</Version>
<Authors>Jan Škoruba</Authors>
<LangVersion>latest</LangVersion>
<UserSecretsId>8fe260ca-ef4c-4fa3-9364-029146f8d339</UserSecretsId>
Expand Down Expand Up @@ -76,3 +76,4 @@




Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>1.0.0-preview4</Version>
<Version>1.0.0-preview5</Version>
<Authors>Jan Škoruba</Authors>
<UserSecretsId>9c91d295-54c5-4d09-9bd6-fa56fb74011b</UserSecretsId>
<DockerComposeProjectPath>..\..\docker-compose.dcproj</DockerComposeProjectPath>
Expand Down Expand Up @@ -101,3 +101,4 @@




Loading

0 comments on commit 0d20724

Please sign in to comment.