Skip to content

Commit f33345f

Browse files
WIP
1 parent cc077ff commit f33345f

48 files changed

Lines changed: 353 additions & 205 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

SimpleIdServer.IdServer.Host.sln

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleIdServer.IdServer.Web
3333
EndProject
3434
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleIdServer.IdServer.Website.Startup", "src\IdServer\SimpleIdServer.IdServer.Website.Startup\SimpleIdServer.IdServer.Website.Startup.csproj", "{75CB19CC-AD5A-47B8-8337-FB11B15D660A}"
3535
EndProject
36-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleIdServer.IdServer.ConformanceSuite.Startup", "src\IdServer\SimpleIdServer.IdServer.ConformanceSuite.Startup\SimpleIdServer.IdServer.ConformanceSuite.Startup.csproj", "{CACFC943-091F-4008-8CC4-FC689851DBC0}"
37-
EndProject
3836
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleIdServer.OpenIdConnect", "src\IdServer\SimpleIdServer.OpenIdConnect\SimpleIdServer.OpenIdConnect.csproj", "{D8593C20-6BF5-4B84-AD08-590B03407CF3}"
3937
EndProject
4038
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleIdServer.Scim.Client", "src\Scim\SimpleIdServer.Scim.Client\SimpleIdServer.Scim.Client.csproj", "{8E4A021B-6525-4326-B290-CFA57FFEFFEA}"
@@ -111,8 +109,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "06. Stores", "06. Stores",
111109
EndProject
112110
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleIdServer.IdServer.Store.EF", "src\IdServer\SimpleIdServer.IdServer.Store.EF\SimpleIdServer.IdServer.Store.EF.csproj", "{BE501B31-2CF6-4218-AA74-F536C11AD9D7}"
113111
EndProject
114-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleIdServer.IdServer.SqlSugar.Startup", "src\IdServer\SimpleIdServer.IdServer.SqlSugar.Startup\SimpleIdServer.IdServer.SqlSugar.Startup.csproj", "{0D76EB63-29B1-4878-84D1-2D35897EE1FA}"
115-
EndProject
116112
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleIdServer.SelfIdServer.Host.Acceptance.Tests", "tests\SimpleIdServer.SelfIssuedIdServer.Host.Acceptance.Tests\SimpleIdServer.SelfIdServer.Host.Acceptance.Tests.csproj", "{467B3D10-E6C9-427F-A29F-373AE95ECF69}"
117113
EndProject
118114
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "07. OpenidFederation", "07. OpenidFederation", "{0473E3F7-F4CB-4305-A980-174A953CF0DB}"
@@ -185,10 +181,6 @@ Global
185181
{75CB19CC-AD5A-47B8-8337-FB11B15D660A}.Debug|Any CPU.Build.0 = Debug|Any CPU
186182
{75CB19CC-AD5A-47B8-8337-FB11B15D660A}.Release|Any CPU.ActiveCfg = Release|Any CPU
187183
{75CB19CC-AD5A-47B8-8337-FB11B15D660A}.Release|Any CPU.Build.0 = Release|Any CPU
188-
{CACFC943-091F-4008-8CC4-FC689851DBC0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
189-
{CACFC943-091F-4008-8CC4-FC689851DBC0}.Debug|Any CPU.Build.0 = Debug|Any CPU
190-
{CACFC943-091F-4008-8CC4-FC689851DBC0}.Release|Any CPU.ActiveCfg = Release|Any CPU
191-
{CACFC943-091F-4008-8CC4-FC689851DBC0}.Release|Any CPU.Build.0 = Release|Any CPU
192184
{D8593C20-6BF5-4B84-AD08-590B03407CF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
193185
{D8593C20-6BF5-4B84-AD08-590B03407CF3}.Debug|Any CPU.Build.0 = Debug|Any CPU
194186
{D8593C20-6BF5-4B84-AD08-590B03407CF3}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -317,10 +309,6 @@ Global
317309
{BE501B31-2CF6-4218-AA74-F536C11AD9D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
318310
{BE501B31-2CF6-4218-AA74-F536C11AD9D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
319311
{BE501B31-2CF6-4218-AA74-F536C11AD9D7}.Release|Any CPU.Build.0 = Release|Any CPU
320-
{0D76EB63-29B1-4878-84D1-2D35897EE1FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
321-
{0D76EB63-29B1-4878-84D1-2D35897EE1FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
322-
{0D76EB63-29B1-4878-84D1-2D35897EE1FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
323-
{0D76EB63-29B1-4878-84D1-2D35897EE1FA}.Release|Any CPU.Build.0 = Release|Any CPU
324312
{467B3D10-E6C9-427F-A29F-373AE95ECF69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
325313
{467B3D10-E6C9-427F-A29F-373AE95ECF69}.Debug|Any CPU.Build.0 = Debug|Any CPU
326314
{467B3D10-E6C9-427F-A29F-373AE95ECF69}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -374,7 +362,6 @@ Global
374362
{EA9F6F0A-5F8A-454D-A682-7CADD6704C44} = {033E4EF3-2FB5-450A-9B35-616D9B0D6EAA}
375363
{83A19793-668C-46B6-B1D7-134DFED8B430} = {4796A22B-91A9-42AF-87CA-F69392696B0A}
376364
{75CB19CC-AD5A-47B8-8337-FB11B15D660A} = {68306EFF-55D9-497B-9482-FEB81C485914}
377-
{CACFC943-091F-4008-8CC4-FC689851DBC0} = {68306EFF-55D9-497B-9482-FEB81C485914}
378365
{D8593C20-6BF5-4B84-AD08-590B03407CF3} = {4796A22B-91A9-42AF-87CA-F69392696B0A}
379366
{8E4A021B-6525-4326-B290-CFA57FFEFFEA} = {0CF45705-7CD6-48B6-B032-D9031BB67F18}
380367
{B188D040-77C3-4C6D-A5CE-A1D65F6935A1} = {DA65BA14-7FA4-4D99-A11D-C67F75F03771}
@@ -412,7 +399,6 @@ Global
412399
{80479B56-99CC-457E-9823-BD3B20814B9D} = {06BF894C-69D7-406A-A97F-BD990A3D59ED}
413400
{06BF894C-69D7-406A-A97F-BD990A3D59ED} = {4796A22B-91A9-42AF-87CA-F69392696B0A}
414401
{BE501B31-2CF6-4218-AA74-F536C11AD9D7} = {06BF894C-69D7-406A-A97F-BD990A3D59ED}
415-
{0D76EB63-29B1-4878-84D1-2D35897EE1FA} = {68306EFF-55D9-497B-9482-FEB81C485914}
416402
{467B3D10-E6C9-427F-A29F-373AE95ECF69} = {033E4EF3-2FB5-450A-9B35-616D9B0D6EAA}
417403
{0473E3F7-F4CB-4305-A980-174A953CF0DB} = {4796A22B-91A9-42AF-87CA-F69392696B0A}
418404
{4A7E1AFE-98FB-4B40-B41B-A912C448D020} = {0473E3F7-F4CB-4305-A980-174A953CF0DB}

src/IdServer/SimpleIdServer.Configuration/AutomaticConfigurationProvider.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using Microsoft.Extensions.Configuration;
44
using Microsoft.Extensions.Primitives;
55
using SimpleIdServer.IdServer.Helpers;
6-
using SimpleIdServer.IdServer.Middlewares;
76
using System;
87
using System.Collections.Generic;
98
using System.Diagnostics;
@@ -16,15 +15,17 @@ namespace SimpleIdServer.Configuration;
1615
public class AutomaticConfigurationProvider : IConfigurationProvider, IDisposable
1716
{
1817
private bool _isDisposed = false;
18+
private readonly IRealmStore _realmStore;
1919
private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
2020
private readonly AutomaticConfigurationOptions _options;
2121
private readonly IKeyValueConnector _connector;
2222
private readonly int _refreshIntervalInSeconds = 10;
2323
private Task? _pollTask;
2424
private ConfigurationReloadToken _reloadToken = new ConfigurationReloadToken();
2525

26-
public AutomaticConfigurationProvider(AutomaticConfigurationOptions options, IKeyValueConnector connector)
26+
public AutomaticConfigurationProvider(IRealmStore realmStore, AutomaticConfigurationOptions options, IKeyValueConnector connector)
2727
{
28+
_realmStore = realmStore;
2829
_options = options;
2930
_connector = connector;
3031
Data = new Dictionary<string, string?>(StringComparer.OrdinalIgnoreCase);
@@ -35,20 +36,20 @@ public AutomaticConfigurationProvider(AutomaticConfigurationOptions options, IKe
3536
public virtual bool TryGet(string key, out string? value)
3637
{
3738
value = null;
38-
if (string.IsNullOrWhiteSpace(RealmContext.Instance().Realm)) return false;
39+
if (string.IsNullOrWhiteSpace(_realmStore.Realm)) return false;
3940
var record = _options.ConfigurationDefinitions.SingleOrDefault(d => key.Contains(d.Name));
4041
if (record == null) return false;
41-
key = $"{RealmContext.Instance().Realm}:{key}";
42+
key = $"{_realmStore.Realm}:{key}";
4243
var result = Data.TryGetValue(key, out value);
4344
return result;
4445
}
4546

4647
public virtual void Set(string key, string? value)
4748
{
48-
if (string.IsNullOrWhiteSpace(RealmContext.Instance().Realm)) return;
49+
if (string.IsNullOrWhiteSpace(_realmStore.Realm)) return;
4950
var record = _options.ConfigurationDefinitions.SingleOrDefault(d => key.Contains(d.Name));
5051
if (record == null) return;
51-
key = $"{RealmContext.Instance().Realm}:{key}";
52+
key = $"{_realmStore.Realm}:{key}";
5253
_connector.Set(key, value, CancellationToken.None).Wait();
5354
if (!Data.ContainsKey(key)) Data.Add(key, value);
5455
else Data[key] = value;
@@ -78,8 +79,8 @@ public virtual IEnumerable<string> GetChildKeys(IEnumerable<string> earlierKeys,
7879
}
7980
else
8081
{
81-
var realm = RealmContext.Instance().Realm;
82-
if(!string.IsNullOrWhiteSpace(realm)) parentPath = $"{realm}:{parentPath}";
82+
var realm = _realmStore.Realm;
83+
if (!string.IsNullOrWhiteSpace(realm)) parentPath = $"{realm}:{parentPath}";
8384
Debug.Assert(ConfigurationPath.KeyDelimiter == ":");
8485

8586
foreach (KeyValuePair<string, string?> kv in Data)
@@ -116,7 +117,7 @@ private static string Segment(string key, int prefixLength)
116117

117118
private async Task PoolConfigurations(CancellationToken cancellationToken)
118119
{
119-
while(!cancellationToken.IsCancellationRequested)
120+
while (!cancellationToken.IsCancellationRequested)
120121
{
121122
await LoadConfigurations(cancellationToken);
122123
await Task.Delay(_refreshIntervalInSeconds * 1000);
@@ -136,7 +137,7 @@ private async Task LoadConfigurations(CancellationToken cancellationToken)
136137
Data = newData;
137138
}
138139
}
139-
catch(Exception ex)
140+
catch (Exception ex)
140141
{
141142

142143
}
@@ -154,4 +155,4 @@ protected void OnReload()
154155
}
155156

156157
public override string ToString() => $"{GetType().Name}";
157-
}
158+
}

src/IdServer/SimpleIdServer.Configuration/AutomaticConfigurationSource.cs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,31 @@
22
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
33
using Microsoft.Extensions.Configuration;
44
using Microsoft.Extensions.DependencyInjection;
5+
using SimpleIdServer.IdServer.Helpers;
56
using System;
67

7-
namespace SimpleIdServer.Configuration
8+
namespace SimpleIdServer.Configuration;
9+
10+
public class AutomaticConfigurationSource : IConfigurationSource
811
{
9-
public class AutomaticConfigurationSource : IConfigurationSource
12+
private readonly AutomaticConfigurationOptions _options;
13+
private readonly IServiceProvider _serviceProvider;
14+
15+
public AutomaticConfigurationSource()
1016
{
11-
private readonly AutomaticConfigurationOptions _options;
12-
private readonly IServiceProvider _serviceProvider;
1317

14-
public AutomaticConfigurationSource()
15-
{
16-
17-
}
18+
}
1819

19-
public AutomaticConfigurationSource(AutomaticConfigurationOptions options, IServiceProvider serviceProvider)
20-
{
21-
_options = options;
22-
_serviceProvider = serviceProvider;
23-
}
20+
public AutomaticConfigurationSource(AutomaticConfigurationOptions options, IServiceProvider serviceProvider)
21+
{
22+
_options = options;
23+
_serviceProvider = serviceProvider;
24+
}
2425

25-
public IConfigurationProvider Build(IConfigurationBuilder builder)
26-
{
27-
var keyValueConnector = _serviceProvider.GetRequiredService<IKeyValueConnector>();
28-
return new AutomaticConfigurationProvider(_options, keyValueConnector);
29-
}
26+
public IConfigurationProvider Build(IConfigurationBuilder builder)
27+
{
28+
var keyValueConnector = _serviceProvider.GetRequiredService<IKeyValueConnector>();
29+
var realmStore = _serviceProvider.GetRequiredService<IRealmStore>();
30+
return new AutomaticConfigurationProvider(realmStore, _options, keyValueConnector);
3031
}
31-
}
32+
}

src/IdServer/SimpleIdServer.IdServer.Domains/Language.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,5 @@ public string TranslationKey
3333
[JsonPropertyName(LanguageNames.Description)]
3434
public string? Description { get; set; } = null;
3535

36-
[JsonIgnore]
3736
public ICollection<Translation> Descriptions { get; set; } = new List<Translation>();
3837
}

src/IdServer/SimpleIdServer.IdServer.Fido/Apis/U2FRegisterController.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class U2FRegisterController : BaseController
3333
private readonly IDistributedCache _distributedCache;
3434
private readonly ITransactionBuilder _transactionBuilder;
3535
private readonly IEnumerable<IAuthenticationMethodService> _authenticationMethodServices;
36+
private readonly IRealmStore _realmStore;
3637
private readonly IdServerHostOptions _idServerHostOptions;
3738

3839
public U2FRegisterController(
@@ -45,6 +46,7 @@ public U2FRegisterController(
4546
IEnumerable<IAuthenticationMethodService> authenticationMethodServices,
4647
ITokenRepository tokenRepository,
4748
IJwtBuilder jwtBuilder,
49+
IRealmStore realmStore,
4850
IOptions<IdServerHostOptions> idServerHostOptions) : base(tokenRepository, jwtBuilder)
4951
{
5052
_configuration = configuration;
@@ -54,6 +56,7 @@ public U2FRegisterController(
5456
_distributedCache = distributedCache;
5557
_transactionBuilder = transactionBuilder;
5658
_authenticationMethodServices = authenticationMethodServices;
59+
_realmStore = realmStore;
5760
_idServerHostOptions = idServerHostOptions.Value;
5861
}
5962

@@ -228,7 +231,7 @@ async Task<IActionResult> HandleWorkflowRegistration()
228231

229232
protected async Task<(BeginU2FRegisterResult, ContentResult)> CommonBegin(string prefix, BeginU2FRegisterRequest request, CancellationToken cancellationToken)
230233
{
231-
var cookieName = _idServerHostOptions.GetRegistrationCookieName();
234+
var cookieName = _idServerHostOptions.GetRegistrationCookieName(_realmStore.Realm);
232235
var cookieValue = string.Empty;
233236
if(Request.Cookies.ContainsKey(cookieName)) cookieValue = Request.Cookies[cookieName];
234237
var fidoOptions = GetOptions(request.CredentialType);
@@ -326,7 +329,7 @@ public CredentialCreateOptions Options
326329
private async Task<UserRegistrationProgress> GetRegistrationProgress(RegistrationSessionRecord sessionRecord = null)
327330
{
328331
var cookieValue = string.Empty;
329-
var cookieName = _idServerHostOptions.GetRegistrationCookieName();
332+
var cookieName = _idServerHostOptions.GetRegistrationCookieName(_realmStore.Realm);
330333
if (!Request.Cookies.ContainsKey(cookieName))
331334
{
332335
if (sessionRecord == null || string.IsNullOrWhiteSpace(sessionRecord.RegistrationCookieKey)) return null;

src/IdServer/SimpleIdServer.IdServer.Fido/UI/Mobile/RegisterController.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.Extensions.Options;
66
using SimpleIdServer.IdServer.Domains;
77
using SimpleIdServer.IdServer.Fido.UI.ViewModels;
8+
using SimpleIdServer.IdServer.Helpers;
89
using SimpleIdServer.IdServer.Jwt;
910
using SimpleIdServer.IdServer.Options;
1011
using SimpleIdServer.IdServer.Stores;
@@ -25,7 +26,8 @@ public RegisterController(
2526
IConfiguration configuration,
2627
ITokenRepository tokenRepository,
2728
ITransactionBuilder transactionBuilder,
28-
IJwtBuilder jwtBuilder) : base(options, distributedCache, userRepository, tokenRepository, transactionBuilder, jwtBuilder)
29+
IJwtBuilder jwtBuilder,
30+
IRealmStore realmStore) : base(options, distributedCache, userRepository, tokenRepository, transactionBuilder, jwtBuilder, realmStore)
2931
{
3032
_configuration = configuration;
3133
}

src/IdServer/SimpleIdServer.IdServer.Fido/UI/Webauthn/RegisterController.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.Extensions.Options;
88
using SimpleIdServer.IdServer.Domains;
99
using SimpleIdServer.IdServer.Fido.UI.ViewModels;
10+
using SimpleIdServer.IdServer.Helpers;
1011
using SimpleIdServer.IdServer.Jwt;
1112
using SimpleIdServer.IdServer.Options;
1213
using SimpleIdServer.IdServer.Stores;
@@ -24,7 +25,8 @@ public RegisterController(
2425
IUserRepository userRepository,
2526
ITokenRepository tokenRepository,
2627
ITransactionBuilder transactionBuilder,
27-
IJwtBuilder jwtBuilder) : base(options, distributedCache, userRepository, tokenRepository, transactionBuilder, jwtBuilder)
28+
IJwtBuilder jwtBuilder,
29+
IRealmStore realmStore) : base(options, distributedCache, userRepository, tokenRepository, transactionBuilder, jwtBuilder, realmStore)
2830
{
2931
}
3032

src/IdServer/SimpleIdServer.IdServer.Helpers/IRealmStore.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,4 @@ namespace SimpleIdServer.IdServer.Helpers;
66
public interface IRealmStore
77
{
88
string Realm { get; set; }
9-
}
10-
11-
public class RealmStore : IRealmStore
12-
{
13-
public string Realm { get; set; }
149
}

src/IdServer/SimpleIdServer.IdServer.Startup/Areas/console/Views/Authenticate/Index.cshtml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
@using Microsoft.Extensions.Options;
2+
@using SimpleIdServer.IdServer.Helpers
23
@using SimpleIdServer.IdServer.Options;
34
@using SimpleIdServer.IdServer.Startup;
45
@using SimpleIdServer.IdServer.Startup.Resources;
56
@model SimpleIdServer.IdServer.Console.UI.ViewModels.AuthenticateConsoleViewModel
67
@inject IOptions<IdServerHostOptions> configuration
8+
@inject IRealmStore realmStore
79

810
@{
911
ViewBag.Title = AuthenticateConsoleResource.title;
1012
Layout = "~/Views/Shared/_AuthenticateLayout.cshtml";
1113
var returnUrl = Microsoft.AspNetCore.Http.Extensions.UriHelper.GetDisplayUrl(Context.Request);
12-
var realm = SimpleIdServer.IdServer.Helpers.RealmContext.Instance()?.Realm;
14+
var realm = realmStore?.Realm;
1315
var registationUrl = $"{(string.IsNullOrWhiteSpace(realm) ? "/" : $"/{realm}/")}Registration?redirectUrl={returnUrl}&workflowName={Model.RegistrationWorkflow?.Name}";
1416
}
1517

src/IdServer/SimpleIdServer.IdServer.Startup/Areas/email/Views/Authenticate/Index.cshtml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
@using Microsoft.Extensions.Options;
2+
@using SimpleIdServer.IdServer.Helpers
23
@using SimpleIdServer.IdServer.Options;
34
@using SimpleIdServer.IdServer.Startup;
45
@using SimpleIdServer.IdServer.Startup.Resources;
56
@model SimpleIdServer.IdServer.Email.UI.ViewModels.AuthenticateEmailViewModel
67
@inject IOptions<IdServerHostOptions> configuration
8+
@inject IRealmStore realmStore
79

810
@{
911
ViewBag.Title = AuthenticateEmailResource.title;
1012
Layout = "~/Views/Shared/_AuthenticateLayout.cshtml";
1113
var returnUrl = Microsoft.AspNetCore.Http.Extensions.UriHelper.GetDisplayUrl(Context.Request);
12-
var realm = SimpleIdServer.IdServer.Helpers.RealmContext.Instance()?.Realm;
14+
var realm = realmStore?.Realm;
1315
var registationUrl = $"{(string.IsNullOrWhiteSpace(realm) ? "/" : $"/{realm}/")}Registration?redirectUrl={returnUrl}&workflowName={Model.RegistrationWorkflow?.Name}";
1416
}
1517

0 commit comments

Comments
 (0)