Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added configuration from json file #231

Merged
merged 20 commits into from
Oct 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e52b4cd
Added configuration from json file
Mar 27, 2019
a3100d2
Added hashing secret for api resources
Mar 27, 2019
c7df0e8
Removed no longer required hardcoded configuration
Mar 27, 2019
daa616c
Removed unnecessary info from codebase that is already in appsettings…
Mar 27, 2019
d26ebad
The name of default role is now configurable
Mar 27, 2019
aba54d1
Removed unused constant field
Mar 27, 2019
03d1249
Also adjustible admin role in STS
Mar 27, 2019
51042b7
Minor update allowing for seeding users without passwords attached
Apr 17, 2019
01f79c6
Minor update allowing for seeding users without passwords attached
Apr 17, 2019
c8d2da8
Merge branch 'seeding-db-with-json-document' of https://github.com/sk…
Apr 17, 2019
b8afaf0
Merge branch 'seeding-db-with-json-document' of https://github.com/sk…
Apr 17, 2019
f23314a
Merge branch 'seeding-db-with-json-document' of https://github.com/sk…
Apr 17, 2019
3327d31
Fixed importing client claims
Jun 1, 2019
da6b978
Merge branch 'dev' into seeding-db-with-json-document
skoruba Oct 5, 2019
1e2599c
Update AdminConfiguration
skoruba Oct 5, 2019
859988a
Remove secrets from constants; Polish AdminConfiguration; Add client …
skoruba Oct 5, 2019
93ea959
Clean api resources and use api swagger only; Polish DbMigrationHelpe…
skoruba Oct 5, 2019
455c7b3
Rename UserDataConfiguration to IdentityDataConfiguration and ClientD…
skoruba Oct 5, 2019
47aeea8
Remove AuthorizationConsts from API, expose adminrole into appsettings
skoruba Oct 5, 2019
0e0ea47
Add configuration of Authentication middleware into appsettings
skoruba Oct 5, 2019
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
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
using Skoruba.IdentityServer4.Admin.Api.Configuration.Constants;

namespace Skoruba.IdentityServer4.Admin.Api.Configuration
namespace Skoruba.IdentityServer4.Admin.Api.Configuration
{
public class AdminApiConfiguration
{
public string IdentityServerBaseUrl { get; set; } = AuthorizationConsts.IdentityServerBaseUrl;
public string ApiName { get; set; }

public string ApiVersion { get; set; }

public string IdentityServerBaseUrl { get; set; }

public string OidcSwaggerUIClientId { get; set; }

public string OidcSwaggerUIClientId { get; set; } = AuthorizationConsts.OidcSwaggerUIClientId;
public string OidcApiName { get; set; }

public string OidcApiName { get; set; } = AuthorizationConsts.OidcApiName;
public string AdministrationRole { get; set; }
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
{
public class AuthorizationConsts
{
public const string IdentityServerBaseUrl = "http://localhost:5000";
public const string OidcSwaggerUIClientId = "skoruba_identity_admin_api_swaggerui";
public const string OidcApiName = "skoruba_identity_admin_api";

public const string AdministrationPolicy = "RequireAdministratorRole";
public const string AdministrationRole = "SkorubaIdentityAdminAdministrator";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,12 @@ public static void AddApiAuthentication<TIdentityDbContext, TUser, TRole>(this I

public static void AddAuthorizationPolicies(this IServiceCollection services)
{
var adminApiConfiguration = services.BuildServiceProvider().GetService<AdminApiConfiguration>();

services.AddAuthorization(options =>
{
options.AddPolicy(AuthorizationConsts.AdministrationPolicy,
policy => policy.RequireRole(AuthorizationConsts.AdministrationRole));
policy => policy.RequireRole(adminApiConfiguration.AdministrationRole));
});
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Skoruba.IdentityServer4.Admin.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ public void ConfigureServices(IServiceCollection services)

services.AddSwaggerGen(options =>
{
options.SwaggerDoc(ApiConfigurationConsts.ApiVersionV1, new Info { Title = ApiConfigurationConsts.ApiName, Version = ApiConfigurationConsts.ApiVersionV1 });
options.SwaggerDoc(adminApiConfiguration.ApiVersion, new Info { Title = adminApiConfiguration.ApiName, Version = adminApiConfiguration.ApiVersion });

options.AddSecurityDefinition("oauth2", new OAuth2Scheme
{
Flow = "implicit",
AuthorizationUrl = $"{adminApiConfiguration.IdentityServerBaseUrl}/connect/authorize",
Scopes = new Dictionary<string, string> {
{ adminApiConfiguration.OidcApiName, ApiConfigurationConsts.ApiName }
{ adminApiConfiguration.OidcApiName, adminApiConfiguration.ApiName }
}
});

Expand All @@ -102,10 +102,10 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, AdminApi
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", ApiConfigurationConsts.ApiName);
c.SwaggerEndpoint("/swagger/v1/swagger.json", adminApiConfiguration.ApiName);

c.OAuthClientId(adminApiConfiguration.OidcSwaggerUIClientId);
c.OAuthAppName(ApiConfigurationConsts.ApiName);
c.OAuthAppName(adminApiConfiguration.ApiName);
});

app.UseMvc();
Expand Down
5 changes: 4 additions & 1 deletion src/Skoruba.IdentityServer4.Admin.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
"AdminLogDbConnection": "Server=(localdb)\\mssqllocaldb;Database=IdentityServer4Admin;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"AdminApiConfiguration": {
"ApiName": "Skoruba IdentityServer4 Admin Api",
"ApiVersion": "v1",
"IdentityServerBaseUrl": "http://localhost:5000",
"OidcSwaggerUIClientId": "skoruba_identity_admin_api_swaggerui",
"OidcApiName": "skoruba_identity_admin_api"
"OidcApiName": "skoruba_identity_admin_api",
"AdministrationRole": "SkorubaIdentityAdminAdministrator"
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
using Skoruba.IdentityServer4.Admin.Configuration.Constants;
using Skoruba.IdentityServer4.Admin.Configuration.Interfaces;
using Skoruba.IdentityServer4.Admin.Configuration.Interfaces;

namespace Skoruba.IdentityServer4.Admin.Configuration
{
public class AdminConfiguration : IAdminConfiguration
{
public string IdentityAdminBaseUrl { get; set; } = "http://localhost:9000";
public string IdentityAdminRedirectUri { get; set; } = "http://localhost:9000/signin-oidc";

public string IdentityServerBaseUrl { get; set; } = "http://localhost:5000";
public string ClientId { get; set; } = AuthenticationConsts.OidcClientId;
public string IdentityAdminRedirectUri { get; set; }
public string[] Scopes { get; set; }

public string IdentityAdminApiSwaggerUIClientId { get; } = AuthenticationConsts.IdentityAdminApiSwaggerClientId;
public string IdentityAdminApiSwaggerUIRedirectUrl { get; } = "http://localhost:5001/swagger/oauth2-redirect.html";
public string IdentityAdminApiScope { get; } = AuthenticationConsts.IdentityAdminApiScope;

public string ClientSecret { get; set; } = AuthenticationConsts.OidcClientSecret;
public string OidcResponseType { get; set; } = AuthenticationConsts.OidcResponseType;


public string AdministrationRole { get; set; }
public bool RequireHttpsMetadata { get; set; }
public string IdentityAdminCookieName { get; set; }
public double IdentityAdminCookieExpiresUtcHours { get; set; }
public string TokenValidationClaimName { get; set; }
public string TokenValidationClaimRole { get; set; }
public string IdentityServerBaseUrl { get; set; }
public string ClientId { get; set; }
public string ClientSecret { get; set; }
public string OidcResponseType { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
using System.Collections.Generic;

namespace Skoruba.IdentityServer4.Admin.Configuration.Constants
namespace Skoruba.IdentityServer4.Admin.Configuration.Constants
{
public class AuthenticationConsts
{
public const string IdentityAdminCookieName = "IdentityServerAdmin";
public const string UserNameClaimType = "name";
public const string SignInScheme = "Cookies";
public const string OidcClientId = "skoruba_identity_admin";
public const string OidcClientSecret = "skoruba_admin_client_secret";
public const string OidcAuthenticationScheme = "oidc";
public const string OidcResponseType = "code id_token";
public static List<string> Scopes = new List<string> { ScopeOpenId, ScopeProfile, ScopeEmail, ScopeRoles };

public const string IdentityAdminApiSwaggerClientId = "skoruba_identity_admin_api_swaggerui";
public const string IdentityAdminApiScope = "skoruba_identity_admin_api";

public const string ScopeOpenId = "openid";
public const string ScopeProfile = "profile";
public const string ScopeEmail = "email";
public const string ScopeRoles = "roles";

public const string RoleClaim = "role";

public const string AccountLoginPage = "Account/Login";
public const string AccountAccessDeniedPage = "/Account/AccessDenied/";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
public class AuthorizationConsts
{
public const string AdministrationPolicy = "RequireAdministratorRole";
public const string AdministrationRole = "SkorubaIdentityAdminAdministrator";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ public class ConfigurationConsts
public const string ResourcesPath = "Resources";

public const string AdminConfigurationKey = "AdminConfiguration";

public const string IdentityServerDataConfigurationKey = "IdentityServerData";

public const string IdentityDataConfigurationKey = "IdentityData";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Skoruba.IdentityServer4.Admin.Configuration.Identity
{
public class Claim
{
public string Type { get; set; }
public string Value { get; set; }
}
}
10 changes: 10 additions & 0 deletions src/Skoruba.IdentityServer4.Admin/Configuration/Identity/Role.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Collections.Generic;

namespace Skoruba.IdentityServer4.Admin.Configuration.Identity
{
public class Role
{
public string Name { get; set; }
public List<Claim> Claims { get; set; } = new List<Claim>();
}
}
13 changes: 13 additions & 0 deletions src/Skoruba.IdentityServer4.Admin/Configuration/Identity/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;

namespace Skoruba.IdentityServer4.Admin.Configuration.Identity
{
public class User
{
public string Username { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public List<Claim> Claims { get; set; } = new List<Claim>();
public List<string> Roles { get; set; } = new List<string>();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Skoruba.IdentityServer4.Admin.Configuration.Identity;
using Skoruba.IdentityServer4.Admin.Configuration.Interfaces;
using System.Collections.Generic;

namespace Skoruba.IdentityServer4.Admin.Configuration
{
public class IdentityDataConfiguration : IIdentityDataConfiguration
{
public List<Role> Roles { get; set; }
public List<User> Users { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Collections.Generic;
using Skoruba.IdentityServer4.Admin.Configuration.Identity;

namespace Skoruba.IdentityServer4.Admin.Configuration.IdentityServer
{
public class Client : global::IdentityServer4.Models.Client
{
public List<Claim> ClientClaims { get; set; } = new List<Claim>();
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using IdentityServer4.Models;
using Skoruba.IdentityServer4.Admin.Configuration.Interfaces;
using System.Collections.Generic;
using Client = Skoruba.IdentityServer4.Admin.Configuration.IdentityServer.Client;

namespace Skoruba.IdentityServer4.Admin.Configuration
{
public class IdentityServerDataConfiguration : IIdentityServerDataConfiguration
{
public List<Client> Clients { get; set; } = new List<Client>();
public List<IdentityResource> IdentityResources { get; set; } = new List<IdentityResource>();
public List<ApiResource> ApiResources { get; set; } = new List<ApiResource>();
}
}
Loading