diff --git a/src/AppAuthentication/Constants.cs b/src/AppAuthentication/Constants.cs index 2af120d..29c2163 100644 --- a/src/AppAuthentication/Constants.cs +++ b/src/AppAuthentication/Constants.cs @@ -9,7 +9,7 @@ internal static class Constants public static readonly string MsiAppServiceSecretEnv = "MSI_SECRET"; - public static readonly string MsiContinerUrl = "host.docker.internal"; + public static readonly string MsiContainerUrl = "host.docker.internal"; public static readonly string HostUrl = "http://{0}:{1}/"; diff --git a/src/AppAuthentication/EnvironmentHostedService.cs b/src/AppAuthentication/EnvironmentHostedService.cs index 47d125a..eb1c52d 100644 --- a/src/AppAuthentication/EnvironmentHostedService.cs +++ b/src/AppAuthentication/EnvironmentHostedService.cs @@ -18,7 +18,7 @@ public Task StartAsync(CancellationToken cancellationToken) { Environment.SetEnvironmentVariable( Constants.MsiAppServiceEndpointEnv, - $"{string.Format(Constants.HostUrl,Constants.MsiContinerUrl,_options.Port)}{Constants.MsiEndpoint}", + $"{string.Format(Constants.HostUrl,Constants.MsiContainerUrl,_options.Port)}{Constants.MsiEndpoint}", EnvironmentVariableTarget.User); Environment.SetEnvironmentVariable( diff --git a/src/AppAuthentication/Helpers/ConsoleHandler.cs b/src/AppAuthentication/Helpers/ConsoleHandler.cs index 9b0b403..a69c04e 100644 --- a/src/AppAuthentication/Helpers/ConsoleHandler.cs +++ b/src/AppAuthentication/Helpers/ConsoleHandler.cs @@ -63,8 +63,19 @@ internal static string GetUserSecretsId() internal static int GetRandomUnusedPort() { - var listener = new TcpListener(IPAddress.Loopback, 5050); - listener.Start(); + TcpListener listener = null; + + try + { + listener = new TcpListener(IPAddress.Loopback, 5050); + listener.Start(); + } + catch (Exception) + { + listener = new TcpListener(IPAddress.Loopback, 0); + listener.Start(); + } + var port = ((IPEndPoint)listener.LocalEndpoint).Port; listener.Stop(); return port; diff --git a/src/AppAuthentication/RunCommand.cs b/src/AppAuthentication/RunCommand.cs index a3cf6c6..5694b1a 100644 --- a/src/AppAuthentication/RunCommand.cs +++ b/src/AppAuthentication/RunCommand.cs @@ -48,7 +48,7 @@ private async Task OnExecuteAsync() var builderConfig = new WebHostBuilderOptions { Authority = Authority, - HostingEnviroment = !string.IsNullOrWhiteSpace(HostingEnviroment) ? HostingEnviroment : "Development", + HostingEnvironment = !string.IsNullOrWhiteSpace(HostingEnviroment) ? HostingEnviroment : "Development", Resource = !string.IsNullOrWhiteSpace(Resource) ? Resource : "https://vault.azure.net/", Verbose = Verbose, ConfigFile = ConfigFile, diff --git a/src/AppAuthentication/WebHostBuilderExtensions.cs b/src/AppAuthentication/WebHostBuilderExtensions.cs index 031309f..df88718 100644 --- a/src/AppAuthentication/WebHostBuilderExtensions.cs +++ b/src/AppAuthentication/WebHostBuilderExtensions.cs @@ -15,7 +15,7 @@ internal static WebHostBuilder CreateDefaultBuilder(WebHostBuilderOptions option { var builder = new WebHostBuilder(); - builder.UseEnvironment(options.HostingEnviroment); + builder.UseEnvironment(options.HostingEnvironment); var fullPath = Directory.GetCurrentDirectory(); if (!string.IsNullOrWhiteSpace(Path.GetDirectoryName(options.ConfigFile))) @@ -38,7 +38,7 @@ internal static WebHostBuilder CreateDefaultBuilder(WebHostBuilderOptions option // appsettings file or others config.AddJsonFile(Path.Combine(fullPath, $"{(defaultConfigName).Split(".")[0]}.json"), optional: true) - .AddJsonFile(Path.Combine(fullPath, $"{(defaultConfigName).Split(".")[0]}.{options.HostingEnviroment}.json"), optional: true); + .AddJsonFile(Path.Combine(fullPath, $"{(defaultConfigName).Split(".")[0]}.{options.HostingEnvironment}.json"), optional: true); if (options.Arguments != null) { diff --git a/src/AppAuthentication/WebHostBuilderOptions.cs b/src/AppAuthentication/WebHostBuilderOptions.cs index f36c713..8aed569 100644 --- a/src/AppAuthentication/WebHostBuilderOptions.cs +++ b/src/AppAuthentication/WebHostBuilderOptions.cs @@ -13,9 +13,9 @@ internal class WebHostBuilderOptions public string Authority { get; set; } /// - /// Specify environment. + /// Specify Environment. /// - public string HostingEnviroment { get; set; } + public string HostingEnvironment { get; set; } public bool Verbose { get; set; }