diff --git a/src/Server/Program.cs b/src/Server/Program.cs index 1ec73c9..e4748e6 100755 --- a/src/Server/Program.cs +++ b/src/Server/Program.cs @@ -89,20 +89,20 @@ if (IPayment._PaymentType == PaymentType.StripeIntent) { RsaSecurityKey? PublicKey = null; using (HttpClient client = new HttpClient()) { - HttpResponseMessage PublicKeyResponse = await client.GetAsync("https://auth.mistox.com/api/auth/publickey"); - if (PublicKeyResponse.IsSuccessStatusCode) { - string publicKey = await PublicKeyResponse.Content.ReadAsStringAsync(); - RSA rsa = RSA.Create(); - rsa.ImportFromPem(publicKey); - PublicKey = new RsaSecurityKey(rsa); + while (PublicKey == null) { + HttpResponseMessage PublicKeyResponse = await client.GetAsync("https://auth.mistox.com/api/auth/publickey"); + if (PublicKeyResponse.IsSuccessStatusCode) { + string publicKey = await PublicKeyResponse.Content.ReadAsStringAsync(); + using (RSA rsa = RSA.Create()) { + rsa.ImportFromPem(publicKey); + PublicKey = new RsaSecurityKey(rsa); + } + } else { + await Task.Delay(2000); // sleep the main thread for 2 seconds before sending another request. Prevent DDOS of my own equiptment + } } } -if (PublicKey == null) { - Console.WriteLine("Unable to load RSA PubKey Shutting Down"); - Environment.Exit(100); -} - builder.Services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;