diff --git a/src/Tools/dotnet-user-jwts/src/Helpers/DevJwtCliHelpers.cs b/src/Tools/dotnet-user-jwts/src/Helpers/DevJwtCliHelpers.cs index 999d5e751461f7768a49e06ac75bbb6124d486b9..7a7dc7541c329dac6d4c241b3b0ba68396ed8dda 100644 --- a/src/Tools/dotnet-user-jwts/src/Helpers/DevJwtCliHelpers.cs +++ b/src/Tools/dotnet-user-jwts/src/Helpers/DevJwtCliHelpers.cs @@ -114,13 +114,19 @@ internal static class DevJwtCliHelpers ArgumentException.ThrowIfNullOrEmpty(nameof(project)); var launchSettingsFilePath = Path.Combine(Path.GetDirectoryName(project)!, "Properties", "launchSettings.json"); - var applicationUrls = new List<string>(); + var applicationUrls = new HashSet<string>(); if (File.Exists(launchSettingsFilePath)) { using var launchSettingsFileStream = new FileStream(launchSettingsFilePath, FileMode.Open, FileAccess.Read); if (launchSettingsFileStream.Length > 0) { var launchSettingsJson = JsonDocument.Parse(launchSettingsFileStream); + + if (ExtractIISExpressUrlFromProfile(launchSettingsJson.RootElement) is { } iisUrls) + { + applicationUrls.UnionWith(iisUrls); + } + if (launchSettingsJson.RootElement.TryGetProperty("profiles", out var profiles)) { var profilesEnumerator = profiles.EnumerateObject(); @@ -128,25 +134,20 @@ internal static class DevJwtCliHelpers { if (ExtractKestrelUrlsFromProfile(profile) is { } kestrelUrls) { - applicationUrls.AddRange(kestrelUrls); - } - - if (ExtractIISExpressUrlFromProfile(profile) is { } iisUrls) - { - applicationUrls.AddRange(iisUrls); + applicationUrls.UnionWith(kestrelUrls); } } } } } - return applicationUrls; + return applicationUrls.ToList(); - static List<string> ExtractIISExpressUrlFromProfile(JsonProperty profile) + static List<string> ExtractIISExpressUrlFromProfile(JsonElement rootElement) { - if (profile.NameEquals("iisSettings")) + if (rootElement.TryGetProperty("iisSettings", out var iisSettings)) { - if (profile.Value.TryGetProperty("iisExpress", out var iisExpress)) + if (iisSettings.TryGetProperty("iisExpress", out var iisExpress)) { List<string> iisUrls = new(); if (iisExpress.TryGetProperty("applicationUrl", out var iisUrl)) diff --git a/src/Tools/dotnet-user-jwts/test/UserJwtsTestFixture.cs b/src/Tools/dotnet-user-jwts/test/UserJwtsTestFixture.cs index d3af1030c3edb397d4b280188e2447d3011a4931..c4364d33cb020295eb32cb4a5fbc543cde96194e 100644 --- a/src/Tools/dotnet-user-jwts/test/UserJwtsTestFixture.cs +++ b/src/Tools/dotnet-user-jwts/test/UserJwtsTestFixture.cs @@ -25,16 +25,16 @@ public class UserJwtsTestFixture : IDisposable private const string LaunchSettingsTemplate = @" { + ""iisSettings"": { + ""windowsAuthentication"": false, + ""anonymousAuthentication"": true, + ""iisExpress"": { + ""applicationUrl"": ""http://localhost:23528"", + ""sslPort"": 44395 + } + }, ""profiles"": { - ""iisSettings"": { - ""windowsAuthentication"": false, - ""anonymousAuthentication"": true, - ""iisExpress"": { - ""applicationUrl"": ""http://localhost:23528"", - ""sslPort"": 44395 - } - }, - ""HttpApiSampleApp"": { + ""HttpWebApp"": { ""commandName"": ""Project"", ""dotnetRunMessages"": true, ""launchBrowser"": true, @@ -42,6 +42,22 @@ public class UserJwtsTestFixture : IDisposable ""environmentVariables"": { ""ASPNETCORE_ENVIRONMENT"": ""Development"" } + }, + ""HttpsOnly"": { + ""commandName"": ""Project"", + ""dotnetRunMessages"": true, + ""launchBrowser"": true, + ""applicationUrl"": ""https://localhost:5001"", + ""environmentVariables"": { + ""ASPNETCORE_ENVIRONMENT"": ""Development"" + } + }, + ""IIS Express"": { + ""commandName"": ""IISExpress"", + ""launchBrowser"": true, + ""environmentVariables"": { + ""ASPNETCORE_ENVIRONMENT"": ""Development"" + } } } }";