Skip to content

Commit f0ad84f

Browse files
Joe ShookJoe Shook
authored andcommitted
WIP
Experimental at the moment. If I did this then the functionality should live in the Udap.Client package.
1 parent 010cba0 commit f0ad84f

File tree

7 files changed

+69
-25
lines changed

7 files changed

+69
-25
lines changed

Shared/Components/CascadingAppState.razor

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@using Udap.Model.Registration
22
@using System.Collections.Specialized
33
@using System.Text.Json.Serialization
4+
@using Udap.Smart.Model
45
@using UdapEd.Shared.Model.AuthExtObjects
56
@using UdapEd.Shared.Model.Discovery
67
@using UdapEd.Shared.Model.Smart;
@@ -194,6 +195,8 @@
194195

195196
public MetadataVerificationModel? MetadataVerificationModel { get; private set; }
196197

198+
public SmartMetadata? SmartMetadataModel { get; private set; }
199+
197200
public RawSoftwareStatementAndHeader? SoftwareStatementBeforeEncoding { get; private set; }
198201

199202
public RawSoftwareStatementAndHeader? CertSoftwareStatementBeforeEncoding { get; private set; }

Shared/Pages/UdapDiscovery.razor

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,27 +81,38 @@
8181
<MudGrid Spacing="1" Class="mt-8">
8282
<MudItem sm="6" xs="12">
8383
<MudPaper Class="udap-input" Elevation="3">
84-
@if (!_isLoading && ModelSizeInBytes.HasValue && !string.IsNullOrEmpty(Result))
85-
{
86-
<MudAlert Severity="Severity.Info" Variant="Variant.Text" Dense="true" ContentAlignment="HorizontalAlignment.Right">
87-
<span><b>Size:</b> @ModelSizeInBytesFormatted bytes</span>
88-
</MudAlert>
84+
@if (!_isLoading && ModelSizeInBytes.HasValue && !string.IsNullOrEmpty(Result))
85+
{
86+
<MudAlert Severity="Severity.Info" Variant="Variant.Text" Dense="true" ContentAlignment="HorizontalAlignment.Right">
87+
<span><b>Size:</b> @ModelSizeInBytesFormatted bytes</span>
88+
</MudAlert>
8989

90-
<div style="position: relative;">
91-
<MudIconButton Icon="@Icons.Material.TwoTone.ContentCopy"
92-
Color="Color.Surface"
93-
OnClick="CopyResultToClipboard"
94-
Disabled="@string.IsNullOrEmpty(Result)"
95-
Title="Copy to clipboard"
96-
style="position: absolute; right: 0.5rem; top: 0.5rem; z-index: 1;" />
97-
<pre style="padding-right: 2.5rem;">@Result</pre>
98-
</div>
99-
}
100-
else
101-
{
102-
<pre style="padding-right: 2.5rem;">@Result</pre>
103-
}
90+
<div style="position: relative;">
91+
<MudIconButton Icon="@Icons.Material.TwoTone.ContentCopy"
92+
Color="Color.Surface"
93+
OnClick="CopyResultToClipboard"
94+
Disabled="@string.IsNullOrEmpty(Result)"
95+
Title="Copy to clipboard"
96+
style="position: absolute; right: 0.5rem; top: 0.5rem; z-index: 1;" />
97+
<pre style="padding-right: 2.5rem;">@Result</pre>
98+
</div>
99+
}
100+
else
101+
{
102+
<pre style="padding-right: 2.5rem;">@Result</pre>
103+
}
104104
</MudPaper>
105+
106+
@if (AppState.SmartMetadataModel != null)
107+
{
108+
<MudPaper>
109+
<MudAlert Severity="Severity.Info" Variant="Variant.Text" Dense="true">
110+
<span><b>Note:</b> Missing Udap scopes. Scopes found in .well-known/smart-configuration</span>
111+
</MudAlert>
112+
<pre style="padding-right: 2.5rem;">@AppState.SmartMetadataModel?.scopes_supported.AsJson()</pre>
113+
</MudPaper>
114+
}
115+
105116
</MudItem>
106117
<MudItem sm="6" xs="12">
107118
<MudPaper Class="udap-analyzed" Elevation="3">

Shared/Pages/UdapDiscovery.razor.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using Microsoft.IdentityModel.Tokens;
1919
using Microsoft.JSInterop;
2020
using MudBlazor;
21+
using Udap.Common.Extensions;
2122
using Udap.Model;
2223
using UdapEd.Shared.Components;
2324
using UdapEd.Shared.Services;
@@ -180,6 +181,18 @@ private async Task GetMetadata()
180181
var model = await MetadataService.GetUdapMetadataVerificationModel(BaseUrl, Community, default);
181182
await AppState.SetPropertyAsync(this, nameof(AppState.MetadataVerificationModel), model);
182183
UpdateModelSize(model.UdapServerMetaData);
184+
185+
if (model.UdapServerMetaData == null ||
186+
model.UdapServerMetaData.ScopesSupported == null ||
187+
!model.UdapServerMetaData.ScopesSupported.Any())
188+
{
189+
var smartModel = await MetadataService.GetSmartMetadata($"{BaseUrl.EnsureTrailingSlash()}.well-known/smart-configuration", default);
190+
await AppState.SetPropertyAsync(this, nameof(AppState.SmartMetadataModel), smartModel);
191+
}
192+
else
193+
{
194+
await AppState.SetPropertyAsync(this, nameof(AppState.SmartMetadataModel), null);
195+
}
183196
}
184197

185198
Result = AppState.MetadataVerificationModel?.UdapServerMetaData != null

Shared/Pages/UdapRegistration.razor

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
<MudLink Href="/udapDiscovery" Color="Color.Info"> [ @RequestUrl.GetWellKnownUdap(AppState.BaseUrl, AppState.Community) ]</MudLink>
1212
</MudItem>
1313
<MudItem>
14-
@if (AppState.MetadataVerificationModel?.UdapServerMetaData?.ScopesSupported == null ||
15-
AppState.MetadataVerificationModel?.UdapServerMetaData?.ScopesSupported.Any() == false)
14+
@if ((AppState.MetadataVerificationModel?.UdapServerMetaData?.ScopesSupported == null ||
15+
AppState.MetadataVerificationModel?.UdapServerMetaData?.ScopesSupported.Any() == false) &&
16+
AppState.SmartMetadataModel?.scopes_supported == null ||
17+
AppState.SmartMetadataModel?.scopes_supported.Any() == false)
1618
{
1719
<MudAlert Severity="Severity.Warning">No advertised scopes in metadata.</MudAlert>
1820
}

Shared/Pages/UdapRegistration.razor.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ private void PersistSoftwareStatement()
282282
{
283283
_udapDcrDocument = JsonSerializer
284284
.Deserialize<UdapDynamicClientRegistrationDocument>(_beforeEncodingStatement);
285+
285286
var beforeEncodingScope = _udapDcrDocument?.Scope;
286287

287288
var rawStatement = new RawSoftwareStatementAndHeader
@@ -399,9 +400,14 @@ private async Task BuildRawSoftwareStatement()
399400
}
400401
else
401402
{
403+
//TODO: Why don't we pass scopes to BuildRawSoftwareStatementForClientCredentials. Pattern seems different here
404+
var scopes = AppState.MetadataVerificationModel?.UdapServerMetaData?.ScopesSupported?.Any() == true ?
405+
AppState.SmartMetadataModel?.scopes_supported :
406+
AppState.MetadataVerificationModel?.UdapServerMetaData?.ScopesSupported;
407+
402408
await BuildRawSoftwareStatementForAuthorizationCode(
403409
RegisterService.GetScopesForAuthorizationCode(
404-
AppState.MetadataVerificationModel?.UdapServerMetaData?.ScopesSupported,
410+
scopes,
405411
TieredOauth,
406412
OpenIdScope,
407413
AppSharedState.ScopeLevelSelected,
@@ -439,6 +445,10 @@ private async Task BuildRawSoftwareStatementForClientCredentials(bool cancelRegi
439445
UdapDcrBuilderForClientCredentialsUnchecked.Cancel() :
440446
UdapDcrBuilderForClientCredentialsUnchecked.Create();
441447

448+
var scopes = AppState.MetadataVerificationModel?.UdapServerMetaData?.ScopesSupported?.Any() == true ?
449+
AppState.MetadataVerificationModel?.UdapServerMetaData?.ScopesSupported:
450+
AppState.SmartMetadataModel?.scopes_supported;
451+
442452
dcrBuilder.WithAudience(AppState.MetadataVerificationModel?.UdapServerMetaData?.RegistrationEndpoint)
443453
.WithExpiration(TimeSpan.FromMinutes(5))
444454
.WithJwtId()
@@ -448,8 +458,7 @@ private async Task BuildRawSoftwareStatementForClientCredentials(bool cancelRegi
448458
449459
})
450460
.WithTokenEndpointAuthMethod(UdapConstants.RegistrationDocumentValues.TokenEndpointAuthMethodValue)
451-
.WithScope(RegisterService.GetScopesForClientCredentials(
452-
AppState.MetadataVerificationModel?.UdapServerMetaData?.ScopesSupported,
461+
.WithScope(RegisterService.GetScopesForClientCredentials(scopes,
453462
SmartV1Scopes,
454463
SmartV2Scopes));
455464

@@ -471,7 +480,7 @@ private async Task BuildRawSoftwareStatementForClientCredentials(bool cancelRegi
471480
{
472481
_missingScope = true;
473482
}
474-
// Console.WriteLine(request.SerializeToJson(true));
483+
// Console.WriteLine(request.SerializeToJson(trueNo advertised scopes in metada
475484
var statement = await RegisterService
476485
.BuildSoftwareStatementForClientCredentials(request, _signingAlgorithm);
477486
if (statement != null)

Shared/Services/IAppState.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Specialized;
22
using Microsoft.AspNetCore.Components;
33
using Udap.Model.Registration;
4+
using Udap.Smart.Model;
45
using UdapEd.Shared.Model;
56
using UdapEd.Shared.Model.AuthExtObjects;
67
using UdapEd.Shared.Model.Discovery;
@@ -18,6 +19,8 @@ public interface IAppState
1819

1920
public MetadataVerificationModel? MetadataVerificationModel { get; }
2021

22+
SmartMetadata? SmartMetadataModel { get; }
23+
2124
RawSoftwareStatementAndHeader SoftwareStatementBeforeEncoding { get; }
2225

2326
RawSoftwareStatementAndHeader? CertSoftwareStatementBeforeEncoding { get; }

Shared/Services/UdapClientState.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Collections.Specialized;
1212
using Microsoft.AspNetCore.Components;
1313
using Udap.Model.Registration;
14+
using Udap.Smart.Model;
1415
using UdapEd.Shared.Model;
1516
using UdapEd.Shared.Model.AuthExtObjects;
1617
using UdapEd.Shared.Model.Discovery;
@@ -31,6 +32,8 @@ public class UdapClientState : IAppState
3132

3233
public MetadataVerificationModel? MetadataVerificationModel { get; set; }
3334

35+
public SmartMetadata? SmartMetadataModel { get; }
36+
3437
public RawSoftwareStatementAndHeader? SoftwareStatementBeforeEncoding { get; set; }
3538

3639
public RawSoftwareStatementAndHeader? CertSoftwareStatementBeforeEncoding { get; set; }

0 commit comments

Comments
 (0)