Skip to content

Commit 60f636d

Browse files
Joe ShookJoe Shook
authored andcommitted
Many dataholders in same organization using the same Auth Server
This is work to fixup the UI to to track with Auth Servers that publish registration endpoints and token endpoints with query parameter to enable a single UDAP client certificate to register different client Ids across multiple dataholders that share the same Authorization server.
1 parent 2d3a9f5 commit 60f636d

File tree

7 files changed

+67
-42
lines changed

7 files changed

+67
-42
lines changed

Shared/Components/SelectIdP_Dialog.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<DialogContent>
99
<MudForm>
1010
<MudSelect @bind-Value="IdP"
11-
Label="Select Client"
11+
Label="Select Idp hint"
1212
Placeholder="Please Select"
1313
AdornmentIcon="@Icons.Material.Outlined.ArrowDropDown"
1414
AdornmentColor="Color.Primary"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Collections.Immutable;
2+
using UdapEd.Shared.Components;
3+
using UdapEd.Shared.Model;
4+
5+
namespace UdapEd.Shared.Extensions;
6+
7+
public static class ClientRegistrationFilterExtensions
8+
{
9+
/// <summary>
10+
/// Filters registrations to those matching the current certificate (SAN), resource server (BaseUrl),
11+
/// plus any optional additional predicate.
12+
/// </summary>
13+
public static IDictionary<string, ClientRegistration?> FilterRegistrations(
14+
this ClientRegistrations? source,
15+
CascadingAppState appState,
16+
Func<ClientRegistration, bool>? predicate = null)
17+
{
18+
if (source?.Registrations == null ||
19+
appState.UdapClientCertificateInfo == null ||
20+
appState.UdapClientCertificateInfo?.SubjectAltNames == null)
21+
{
22+
return new Dictionary<string, ClientRegistration?>();
23+
}
24+
25+
var query = source.Registrations.Where(r =>
26+
r.Value != null &&
27+
appState.UdapClientCertificateInfo.SubjectAltNames.Contains(r.Value.SubjAltName) &&
28+
appState.BaseUrl == r.Value.ResourceServer &&
29+
appState.MetadataVerificationModel?.UdapServerMetaData?.RegistrationEndpoint == r.Value.RegistrationUrl);
30+
31+
if (predicate != null)
32+
{
33+
query = query.Where(r => r.Value != null && predicate(r.Value));
34+
}
35+
36+
// Preserve existing usage that calls ToImmutableDictionary()
37+
return query.ToImmutableDictionary();
38+
}
39+
}

Shared/Model/ClientRegistrations.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public class ClientRegistrations
3434
AuthServer = registrationDocument.Audience,
3535
ResourceServer = resourceServer,
3636
RedirectUri = registrationDocument.RedirectUris,
37-
Scope = resultModelResult.Scope
37+
Scope = resultModelResult.Scope,
38+
RegistrationUrl = resultModelResult.Audience // Token endpoint
3839
};
3940

4041
Registrations[resultModelResult.ClientId] = _clientRegistration;
@@ -96,4 +97,5 @@ public class ClientRegistration
9697
public ICollection<string>? RedirectUri { get; set; }
9798
public string? Scope { get; set; }
9899
public string? IdPBaseUrl { get; set; }
100+
public string? RegistrationUrl { get; set; }
99101
}

Shared/Pages/UdapBusinessToBusiness.razor.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ private void BuildAccessTokenRequestVisualForClientCredentials()
393393
var sb = new StringBuilder();
394394
sb.AppendLine("POST /token HTTP/1.1");
395395
sb.AppendLine("Content-Type: application/x-www-form-urlencoded");
396-
sb.AppendLine($"Host: {AppState.MetadataVerificationModel?.UdapServerMetaData?.AuthorizationEndpoint}");
396+
sb.AppendLine($"Host: {AppState.MetadataVerificationModel?.UdapServerMetaData?.TokenEndpoint}");
397397
sb.AppendLine("Content-type: application/x-www-form-urlencoded");
398398
sb.AppendLine();
399399
sb.AppendLine("grant_type=client_credentials&");
@@ -419,7 +419,7 @@ private void BuildAccessTokenRequestVisualForAuthorizationCode()
419419

420420
var sb = new StringBuilder();
421421
sb.AppendLine("POST /token HTTP/1.1");
422-
sb.AppendLine($"Host: {AppState.MetadataVerificationModel?.UdapServerMetaData?.AuthorizationEndpoint}");
422+
sb.AppendLine($"Host: {AppState.MetadataVerificationModel?.UdapServerMetaData?.TokenEndpoint}");
423423
sb.AppendLine("Content-type: application/x-www-form-urlencoded");
424424
sb.AppendLine();
425425
sb.AppendLine("grant_type=authorization_code&");
@@ -556,15 +556,7 @@ public string DeviceLoginCallback(bool reset = false)
556556

557557
private IDictionary<string, ClientRegistration?> FilterRegistrations()
558558
{
559-
return AppState.ClientRegistrations.Registrations
560-
.Where(r => r.Value != null &&
561-
AppState.UdapClientCertificateInfo != null &&
562-
AppState.UdapClientCertificateInfo.SubjectAltNames.Contains(r.Value.SubjAltName) &&
563-
AppState.BaseUrl == r.Value.ResourceServer)
564-
.ToImmutableDictionary();
559+
return AppState.ClientRegistrations.FilterRegistrations(AppState);
565560
}
566-
567-
568-
569561
}
570562

Shared/Pages/UdapConsumer.razor.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,8 @@ private string GetJwtHeader(string? tokenString)
470470

471471
private IDictionary<string, ClientRegistration?> FilterRegistrations()
472472
{
473-
return AppState.ClientRegistrations.Registrations
474-
.Where(r => r.Value != null &&
475-
r.Value.UserFlowSelected.Equals("authorization_code") &&
476-
AppState.UdapClientCertificateInfo != null &&
477-
AppState.UdapClientCertificateInfo.SubjectAltNames.Contains(r.Value.SubjAltName) &&
478-
AppState.BaseUrl == r.Value.ResourceServer)
479-
.ToImmutableDictionary();
473+
return AppState.ClientRegistrations.FilterRegistrations(
474+
AppState,
475+
r => r.UserFlowSelected.Equals("authorization_code")); ;
480476
}
481477
}

Shared/Pages/UdapRegistration.razor.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,23 @@
77
// */
88
#endregion
99

10-
using System.Net.NetworkInformation;
11-
using System.Reflection;
12-
using System.Text.Json;
13-
using System.Text.Json.Nodes;
14-
using System.Text.Json.Serialization;
15-
using System.Text.RegularExpressions;
1610
using Google.Api.Gax;
1711
using Hl7.Fhir.Rest;
1812
using Microsoft.AspNetCore.Components;
1913
using Microsoft.AspNetCore.Components.Web;
2014
using Microsoft.IdentityModel.Tokens;
2115
using Microsoft.JSInterop;
2216
using Org.BouncyCastle.Ocsp;
17+
using System.Net.NetworkInformation;
18+
using System.Reflection;
19+
using System.Text.Json;
20+
using System.Text.Json.Nodes;
21+
using System.Text.Json.Serialization;
22+
using System.Text.RegularExpressions;
2323
using Udap.Model;
2424
using Udap.Model.Registration;
2525
using UdapEd.Shared.Components;
26+
using UdapEd.Shared.Extensions;
2627
using UdapEd.Shared.Model;
2728
using UdapEd.Shared.Model.Registration;
2829
using UdapEd.Shared.Services;
@@ -867,12 +868,11 @@ private IEnumerable<ClientRegistration?>? CurrentClientRegistrations
867868
{
868869
get
869870
{
870-
return AppState.ClientRegistrations?.Registrations
871-
.Where(r => r.Value != null &&
872-
AppState.UdapClientCertificateInfo != null &&
873-
AppState.UdapClientCertificateInfo.SubjectAltNames.Contains(r.Value.SubjAltName) &&
874-
AppState.BaseUrl == r.Value.ResourceServer)
875-
.Select(r => r.Value);
871+
var filtered = AppState.ClientRegistrations?.FilterRegistrations(
872+
AppState,
873+
r => AppState.MetadataVerificationModel?.UdapServerMetaData?.RegistrationEndpoint == r.RegistrationUrl);
874+
875+
return filtered?.Values;
876876
}
877877
}
878878

Shared/Pages/UdapTieredOAuth.razor.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -479,14 +479,10 @@ public string DeviceLoginCallback(bool reset = false)
479479

480480
private IDictionary<string, ClientRegistration?>? FilterRegistrations()
481481
{
482-
return AppState.ClientRegistrations?.Registrations
483-
.Where(r => r.Value != null &&
484-
r.Value.UserFlowSelected != "client_credentials" &&
485-
r.Value.Scope != null &&
486-
r.Value.Scope.Contains("udap") &&
487-
AppState.UdapClientCertificateInfo != null &&
488-
AppState.UdapClientCertificateInfo.SubjectAltNames.Contains(r.Value.SubjAltName) &&
489-
AppState.BaseUrl == r.Value.ResourceServer)
490-
.ToImmutableDictionary();
482+
return AppState.ClientRegistrations?.FilterRegistrations(
483+
AppState,
484+
r => r.UserFlowSelected != "client_credentials" &&
485+
!string.IsNullOrEmpty(r.Scope) &&
486+
r.Scope.Contains("udap"));
491487
}
492-
}
488+
}

0 commit comments

Comments
 (0)