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

Support AccountOptions configuration #63

Merged
merged 2 commits into from
Dec 26, 2020
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ This is the sample of using the server in `docker-compose` configuration:
"ShowKeySet": true
}
}
ACCOUNT_OPTIONS_INLINE: |
{
"AutomaticRedirectAfterSignOut": true
}
API_SCOPES_INLINE: |
[
{
Expand Down Expand Up @@ -130,6 +134,7 @@ Clients configuration should be provided. Test user configuration is optional (u
There are two ways to provide configuration for supported scopes, clients and users. You can either provide it inline as environment variable:

* `SERVER_OPTIONS_INLINE`
* `ACCOUNT_OPTIONS_INLINE`
* `API_SCOPES_INLINE`
* `USERS_CONFIGURATION_INLINE`
* `CLIENTS_CONFIGURATION_INLINE`
Expand All @@ -139,6 +144,7 @@ There are two ways to provide configuration for supported scopes, clients and us
or mount volume and provide the path to configuration json as environment variable:

* `SERVER_OPTIONS_PATH`
* `ACCOUNT_OPTIONS_PATH`
* `API_SCOPES_PATH`
* `USERS_CONFIGURATION_PATH`
* `CLIENTS_CONFIGURATION_PATH`
Expand Down
3 changes: 3 additions & 0 deletions e2e/config/account-options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"AutomaticRedirectAfterSignOut": true
}
1 change: 1 addition & 0 deletions e2e/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
ASPNETCORE_Kestrel__Certificates__Default__Password: oidc-server-mock-pwd
ASPNETCORE_Kestrel__Certificates__Default__Path: /https/aspnetapp.pfx
SERVER_OPTIONS_PATH: /config/server-options.json
ACCOUNT_OPTIONS_PATH: /config/account-options.json
API_SCOPES_PATH: /config/api-scopes.json
API_RESOURCES_PATH: /config/api-resources.json
USERS_CONFIGURATION_PATH: /config/user-configuration.json
Expand Down
15 changes: 15 additions & 0 deletions src/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ public static IdentityServerOptions GetServerOptions()
return serverOptions;
}

public static void ConfigureAccountOptions()
{
string accountOptionsStr = Environment.GetEnvironmentVariable("ACCOUNT_OPTIONS_INLINE");
if (string.IsNullOrWhiteSpace(accountOptionsStr))
{
var accountOptionsFilePath = Environment.GetEnvironmentVariable("ACCOUNT_OPTIONS_PATH");
if (string.IsNullOrWhiteSpace(accountOptionsFilePath))
{
return;
}
accountOptionsStr = File.ReadAllText(accountOptionsFilePath);
}
AccountOptionsHelper.ConfigureAccountOptions(accountOptionsStr);
}

public static IEnumerable<string> GetServerCorsAllowedOrigins()
{
string allowedOriginsStr = Environment.GetEnvironmentVariable("SERVER_CORS_ALLOWED_ORIGINS_INLINE");
Expand Down
26 changes: 26 additions & 0 deletions src/Helpers/AccountOptionsHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Serilog;

namespace OpenIdConnectServer.Helpers
{
public class AccountOptionsHelper
{
public static void ConfigureAccountOptions(string accountOptionsStr)
{
var accountOptions = JsonConvert.DeserializeObject<JObject>(accountOptionsStr);
var targetFields = typeof(IdentityServerHost.Quickstart.UI.AccountOptions).GetFields();
var jValueValueProp = typeof(JValue).GetProperty(nameof(JValue.Value));
Array.ForEach(targetFields, k => {
if (accountOptions.ContainsKey(k.Name)) {
var fieldJValue = accountOptions[k.Name] as JValue;
var fieldValue = jValueValueProp.GetValue(fieldJValue);
k.SetValue(null, fieldValue);
}
});
}
}
}
2 changes: 2 additions & 0 deletions src/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public void ConfigureServices(IServiceCollection services)
var aspNetServicesOptions = Config.GetAspNetServicesOptions();
AspNetServicesHelper.ConfigureAspNetServices(services, aspNetServicesOptions);

Config.ConfigureAccountOptions();

services.AddRouting();
}

Expand Down