Skip to content

Commit 427febe

Browse files
Ticket #920 : IdServerUi templmate can now work with the administration website
1 parent 5201839 commit 427febe

File tree

10 files changed

+115
-8
lines changed

10 files changed

+115
-8
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<VersionPrefix>6.0.4</VersionPrefix>
3+
<VersionPrefix>6.0.5</VersionPrefix>
44
<Authors>SimpleIdServer</Authors>
55
<Owners>SimpleIdServer</Owners>
66
</PropertyGroup>

src/IdServer/SimpleIdServer.IdServer.Ui.Startup/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"environmentVariables": {
77
"ASPNETCORE_ENVIRONMENT": "Development"
88
},
9-
"applicationUrl": "https://localhost:65455;http://localhost:65456"
9+
"applicationUrl": "https://localhost:5001"
1010
}
1111
}
1212
}

src/IdServer/SimpleIdServer.IdServer.Website/IdServerWebsiteOptions.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,24 @@ public class IdServerWebsiteOptions
77
{
88
public string DefaultLanguage { get; set; } = "en";
99
public string ScimUrl { get; set; } = "https://localhost:5003";
10+
public IdServerWebsiteFeatures Features { get; set; } = new IdServerWebsiteFeatures();
1011
internal bool IsReamEnabled { get; set; } = false;
1112
internal string Issuer { get; set; } = "https://localhost:5001";
1213
internal bool ForceHttps { get; set; } = false;
1314
internal string ClientId { get; set; }
1415
internal string ClientSecret { get; set; }
1516
internal bool IgnoreCertificateError { get; set; }
1617
}
18+
19+
public class IdServerWebsiteFeatures
20+
{
21+
public bool IsFederationEntitiesEnabled
22+
{
23+
get; set;
24+
} = true;
25+
26+
public bool IsMigrationsEnabled
27+
{
28+
get; set;
29+
} = true;
30+
}

src/IdServer/SimpleIdServer.IdServer.Website/Shared/MainLayout.razor

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
@using SimpleIdServer.IdServer.Helpers
1+
@using Microsoft.Extensions.Options
2+
@using SimpleIdServer.IdServer.Helpers
23
@using SimpleIdServer.IdServer.Website.Infrastructures
34
@using SimpleIdServer.IdServer.Website.Stores.AcrsStore;
45
@using SimpleIdServer.IdServer.Website.Stores.AuthMethodsStore;
@@ -11,6 +12,7 @@
1112
@inherits Fluxor.Blazor.Web.Components.FluxorLayout
1213
@inject IState<RealmsState> state
1314
@inject IState<LanguagesState> languagesState
15+
@inject IOptions<IdServerWebsiteOptions> options
1416
@inject ContextMenuService contextMenuService
1517
@inject IDispatcher dispatcher
1618
@inject IUrlHelper urlHelper
@@ -75,10 +77,17 @@
7577
</RadzenPanelMenuItem>
7678
<RadzenPanelMenuItem Text="@Global.Configure" />
7779
<RadzenPanelMenuItem Text="@Global.CertificateAuthoritiesTitle" Icon="shield" Path="@(urlHelper.GetUrl("/certificateauthorities"))" />
78-
<RadzenPanelMenuItem Text="@Global.FederationEntitiesTitle" Icon="anchor" Path="@(urlHelper.GetUrl("/federationentities"))" />
80+
@if(options.Value.Features.IsFederationEntitiesEnabled)
81+
{
82+
<RadzenPanelMenuItem Text="@Global.FederationEntitiesTitle" Icon="anchor" Path="@(urlHelper.GetUrl("/federationentities"))" />
83+
}
84+
7985
<RadzenPanelMenuItem Text="@Global.Auditing" Icon="source" Path="@(urlHelper.GetUrl("/auditing"))" />
8086
<RadzenPanelMenuItem Text="@Global.RecurringJobs" Icon="schedule" Path="@(urlHelper.GetUrl("/recurringjobs/list"))" />
81-
<RadzenPanelMenuItem Text="@Global.Migrations" Icon="upgrade" Path="@(urlHelper.GetUrl("/migrations"))" />
87+
@if(options.Value.Features.IsMigrationsEnabled)
88+
{
89+
<RadzenPanelMenuItem Text="@Global.Migrations" Icon="upgrade" Path="@(urlHelper.GetUrl("/migrations"))" />
90+
}
8291
</RadzenPanelMenu>
8392
</RadzenSidebar>
8493
<RadzenBody>

src/IdServer/SimpleIdServer.IdServer.Website/WebsiteHttpClientFactory.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,17 @@ private async Task<GetAccessTokenResult> GetAccessToken(string currentRealm = nu
8181
accessToken = _accessTokenStore.AccessTokens[realm];
8282
if (accessToken != null && accessToken.IsValid) return accessToken;
8383
if (accessToken != null && !accessToken.IsValid) _accessTokenStore.AccessTokens.TryRemove(realm, out GetAccessTokenResult r);
84+
var scope = "provisioning users acrs configurations authenticationschemeproviders authenticationmethods registrationworkflows apiresources auditing certificateauthorities clients realms groups scopes workflows forms recurringjobs templates migrations";
85+
if (_idServerWebsiteOptions.Features.IsFederationEntitiesEnabled)
86+
{
87+
scope += " federation_entities";
88+
}
89+
8490
var content = new List<KeyValuePair<string, string>>
8591
{
8692
new KeyValuePair<string, string>("client_id", _idServerWebsiteOptions.ClientId),
8793
new KeyValuePair<string, string>("client_secret", _idServerWebsiteOptions.ClientSecret),
88-
new KeyValuePair<string, string>("scope", "provisioning users acrs configurations authenticationschemeproviders authenticationmethods registrationworkflows apiresources auditing certificateauthorities clients realms groups scopes federation_entities workflows forms recurringjobs templates migrations"),
94+
new KeyValuePair<string, string>("scope", scope),
8995
new KeyValuePair<string, string>("grant_type", "client_credentials")
9096
};
9197
var url = _idServerWebsiteOptions.Issuer;

src/IdServer/SimpleIdServer.IdServer/Builders/ScopeBuilder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public static ScopeBuilder CreateApiScope(string name, bool isExposed = false)
2222
Id = Guid.NewGuid().ToString(),
2323
Name = name,
2424
IsExposedInConfigurationEdp = isExposed,
25+
Type = ScopeTypes.APIRESOURCE,
2526
Realms = new List<Domains.Realm>
2627
{
2728
Config.DefaultRealms.Master

src/IdServer/SimpleIdServer.IdServer/DataSeeder/InitUserDataSeeder.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using DataSeeder;
55
using SimpleIdServer.IdServer.Config;
66
using SimpleIdServer.IdServer.Stores;
7+
using System.Collections.Generic;
78
using System.Linq;
89
using System.Threading;
910
using System.Threading.Tasks;
@@ -35,10 +36,21 @@ protected override async Task Execute(CancellationToken cancellationToken)
3536
using (var transaction = _transactionBuilder.Build())
3637
{
3738
var subjects = DefaultUsers.All.Select(u => u.Name).ToList();
38-
var existingUsers = await _userRepository.GetUsersBySubjects(subjects, Constants.DefaultRealm, cancellationToken);
39+
var existingUsers = await _userRepository.GetUsersBySubjects(
40+
subjects,
41+
Constants.DefaultRealm,
42+
cancellationToken);
3943
var unknownUsers = DefaultUsers.All.Where(u => !existingUsers.Any(eu => eu.Name == u.Name));
44+
var allGroups = await _groupRepository.GetByIds(
45+
unknownUsers.SelectMany(u => u.Groups?.Where(g => !string.IsNullOrWhiteSpace(g.GroupsId)).Select(g => g.GroupsId)?.Distinct()?.ToList() ?? new List<string>()).ToList(),
46+
cancellationToken);
4047
foreach (var unknownUser in unknownUsers)
4148
{
49+
foreach (var group in unknownUser.Groups)
50+
{
51+
group.Group = allGroups.SingleOrDefault(g => g.Id == group.GroupsId);
52+
}
53+
4254
_userRepository.Add(unknownUser);
4355
}
4456

src/IdServer/SimpleIdServer.IdServer/IdServerBuilder.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@ public IdServerBuilder AddInMemoryUsers(List<User> users)
139139
Services.AddTransient<IDataSeeder, InitStaticUsersDataSeeder>();
140140
return this;
141141
}
142+
/// <summary>
143+
/// Adds an in-memory API resources repository using the provided list of API resources.
144+
/// </summary>
145+
public IdServerBuilder AddInMemoryApiResources(List<ApiResource> apiResources)
146+
{
147+
Services.AddSingleton(new StaticApiResourcesDataSeeder(apiResources));
148+
Services.AddTransient<IDataSeeder, InitStaticApiResourceDataSeeder>();
149+
return this;
150+
}
142151

143152
/// <summary>
144153
/// Adds an in-memory language repository using the provided list of languages.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright (c) SimpleIdServer. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
using DataSeeder;
4+
using SimpleIdServer.IdServer.Domains;
5+
using SimpleIdServer.IdServer.Stores;
6+
using System.Collections.Generic;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
10+
namespace SimpleIdServer.IdServer.Migrations.Static;
11+
12+
public class InitStaticApiResourceDataSeeder : BaseAfterDeploymentDataSeeder
13+
{
14+
private readonly IApiResourceRepository _apiResourceRepository;
15+
private readonly ITransactionBuilder _transactionBuilder;
16+
private readonly StaticApiResourcesDataSeeder _apiResourcesData;
17+
18+
public InitStaticApiResourceDataSeeder(
19+
IApiResourceRepository apiResourceRepository,
20+
ITransactionBuilder transactionBuilder,
21+
StaticApiResourcesDataSeeder apiResourcesData,
22+
IDataSeederExecutionHistoryRepository dataSeederExecutionHistoryRepository
23+
) : base(dataSeederExecutionHistoryRepository)
24+
{
25+
_apiResourceRepository = apiResourceRepository;
26+
_transactionBuilder = transactionBuilder;
27+
_apiResourcesData = apiResourcesData;
28+
}
29+
30+
public override string Name => nameof(InitStaticApiResourceDataSeeder);
31+
32+
protected override async Task Execute(CancellationToken cancellationToken)
33+
{
34+
using (var transaction = _transactionBuilder.Build())
35+
{
36+
foreach (var apiResource in _apiResourcesData.ApiResources)
37+
{
38+
_apiResourceRepository.Add(apiResource);
39+
}
40+
41+
await transaction.Commit(cancellationToken);
42+
}
43+
}
44+
}
45+
public class StaticApiResourcesDataSeeder
46+
{
47+
public StaticApiResourcesDataSeeder(List<ApiResource> apiResources)
48+
{
49+
ApiResources = apiResources;
50+
}
51+
52+
public List<ApiResource> ApiResources
53+
{
54+
get; private set;
55+
}
56+
}

src/IdServer/SimpleIdServer.IdServer/UI/CheckSessionController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public async Task<IActionResult> EndSession([FromRoute] string prefix, Cancellat
140140
url = $"/{Config.DefaultEndpoints.EndSessionCallback}?{string.Join("&", Request.Query.Select(q => $"{q.Key}={q.Value}"))}";
141141
}
142142

143-
if (!string.IsNullOrWhiteSpace(prefix))
143+
if (!string.IsNullOrWhiteSpace(prefix) && _options.RealmEnabled)
144144
{
145145
url = $"/{prefix}{url}";
146146
}

0 commit comments

Comments
 (0)