Skip to content

Commit 34d1f49

Browse files
authored
Fix up parsing of IIS settings in user-jwts (#42350)
1 parent 4baffff commit 34d1f49

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

src/Tools/dotnet-user-jwts/src/Helpers/DevJwtCliHelpers.cs

+12-11
Original file line numberDiff line numberDiff line change
@@ -114,39 +114,40 @@ public static List<string> GetAudienceCandidatesFromLaunchSettings(string projec
114114
ArgumentException.ThrowIfNullOrEmpty(nameof(project));
115115

116116
var launchSettingsFilePath = Path.Combine(Path.GetDirectoryName(project)!, "Properties", "launchSettings.json");
117-
var applicationUrls = new List<string>();
117+
var applicationUrls = new HashSet<string>();
118118
if (File.Exists(launchSettingsFilePath))
119119
{
120120
using var launchSettingsFileStream = new FileStream(launchSettingsFilePath, FileMode.Open, FileAccess.Read);
121121
if (launchSettingsFileStream.Length > 0)
122122
{
123123
var launchSettingsJson = JsonDocument.Parse(launchSettingsFileStream);
124+
125+
if (ExtractIISExpressUrlFromProfile(launchSettingsJson.RootElement) is { } iisUrls)
126+
{
127+
applicationUrls.UnionWith(iisUrls);
128+
}
129+
124130
if (launchSettingsJson.RootElement.TryGetProperty("profiles", out var profiles))
125131
{
126132
var profilesEnumerator = profiles.EnumerateObject();
127133
foreach (var profile in profilesEnumerator)
128134
{
129135
if (ExtractKestrelUrlsFromProfile(profile) is { } kestrelUrls)
130136
{
131-
applicationUrls.AddRange(kestrelUrls);
132-
}
133-
134-
if (ExtractIISExpressUrlFromProfile(profile) is { } iisUrls)
135-
{
136-
applicationUrls.AddRange(iisUrls);
137+
applicationUrls.UnionWith(kestrelUrls);
137138
}
138139
}
139140
}
140141
}
141142
}
142143

143-
return applicationUrls;
144+
return applicationUrls.ToList();
144145

145-
static List<string> ExtractIISExpressUrlFromProfile(JsonProperty profile)
146+
static List<string> ExtractIISExpressUrlFromProfile(JsonElement rootElement)
146147
{
147-
if (profile.NameEquals("iisSettings"))
148+
if (rootElement.TryGetProperty("iisSettings", out var iisSettings))
148149
{
149-
if (profile.Value.TryGetProperty("iisExpress", out var iisExpress))
150+
if (iisSettings.TryGetProperty("iisExpress", out var iisExpress))
150151
{
151152
List<string> iisUrls = new();
152153
if (iisExpress.TryGetProperty("applicationUrl", out var iisUrl))

src/Tools/dotnet-user-jwts/test/UserJwtsTestFixture.cs

+25-9
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,39 @@ public class UserJwtsTestFixture : IDisposable
2525

2626
private const string LaunchSettingsTemplate = @"
2727
{
28+
""iisSettings"": {
29+
""windowsAuthentication"": false,
30+
""anonymousAuthentication"": true,
31+
""iisExpress"": {
32+
""applicationUrl"": ""http://localhost:23528"",
33+
""sslPort"": 44395
34+
}
35+
},
2836
""profiles"": {
29-
""iisSettings"": {
30-
""windowsAuthentication"": false,
31-
""anonymousAuthentication"": true,
32-
""iisExpress"": {
33-
""applicationUrl"": ""http://localhost:23528"",
34-
""sslPort"": 44395
35-
}
36-
},
37-
""HttpApiSampleApp"": {
37+
""HttpWebApp"": {
3838
""commandName"": ""Project"",
3939
""dotnetRunMessages"": true,
4040
""launchBrowser"": true,
4141
""applicationUrl"": ""https://localhost:5001;http://localhost:5000"",
4242
""environmentVariables"": {
4343
""ASPNETCORE_ENVIRONMENT"": ""Development""
4444
}
45+
},
46+
""HttpsOnly"": {
47+
""commandName"": ""Project"",
48+
""dotnetRunMessages"": true,
49+
""launchBrowser"": true,
50+
""applicationUrl"": ""https://localhost:5001"",
51+
""environmentVariables"": {
52+
""ASPNETCORE_ENVIRONMENT"": ""Development""
53+
}
54+
},
55+
""IIS Express"": {
56+
""commandName"": ""IISExpress"",
57+
""launchBrowser"": true,
58+
""environmentVariables"": {
59+
""ASPNETCORE_ENVIRONMENT"": ""Development""
60+
}
4561
}
4662
}
4763
}";

0 commit comments

Comments
 (0)