From d44bcc7f66a682936fcfd0b89c74b48c8d07970b Mon Sep 17 00:00:00 2001 From: Alexander Morogov <42555001+krankenbro@users.noreply.github.com> Date: Thu, 3 Oct 2024 12:56:00 +0200 Subject: [PATCH] VCI-921: CloudAuth stores CloudToken if it is passed (#148) --- docs/targets.md | 3 +- src/VirtoCommerce.Build/Cloud/Build.SaaS.cs | 40 ++++++++++++--------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/docs/targets.md b/docs/targets.md index c556626..57251e0 100644 --- a/docs/targets.md +++ b/docs/targets.md @@ -250,10 +250,11 @@ vc-build CloudEnvStatus -CloudToken -EnvironmentName ``` ::: ::: diff --git a/src/VirtoCommerce.Build/Cloud/Build.SaaS.cs b/src/VirtoCommerce.Build/Cloud/Build.SaaS.cs index 47bd07d..fd4ab51 100644 --- a/src/VirtoCommerce.Build/Cloud/Build.SaaS.cs +++ b/src/VirtoCommerce.Build/Cloud/Build.SaaS.cs @@ -298,24 +298,32 @@ private static void CopyPlatformDirectory(AbsolutePath platformDirectory, Absolu public Target CloudAuth => _ => _ .Executes(async () => { - var port = "60123"; - var listenerPrefix = $"http://localhost:{port}/"; - - var listener = new HttpListener() + string apiKey; + if (string.IsNullOrWhiteSpace(CloudToken)) { - Prefixes = { listenerPrefix } - }; - listener.Start(); + var port = "60123"; + var listenerPrefix = $"http://localhost:{port}/"; - Log.Information("Openning browser window"); - var authUrl = $"{CloudUrl}/externalsignin?authenticationType={CloudAuthProvider}&returnUrl=/api/saas/token/{port}"; - Process.Start(new ProcessStartInfo(authUrl) { UseShellExecute = true }); - - var context = await listener.GetContextAsync(); - context.Response.StatusCode = (int)HttpStatusCode.OK; - var apiKey = context.Request.QueryString["apiKey"]; - context.Response.Redirect($"{CloudUrl}/vcbuild/login/success"); - context.Response.Close(); + var listener = new HttpListener() + { + Prefixes = { listenerPrefix } + }; + listener.Start(); + + Log.Information("Openning browser window"); + var authUrl = $"{CloudUrl}/externalsignin?authenticationType={CloudAuthProvider}&returnUrl=/api/saas/token/{port}"; + Process.Start(new ProcessStartInfo(authUrl) { UseShellExecute = true }); + + var context = await listener.GetContextAsync(); + context.Response.StatusCode = (int)HttpStatusCode.OK; + apiKey = context.Request.QueryString["apiKey"]; + context.Response.Redirect($"{CloudUrl}/vcbuild/login/success"); + context.Response.Close(); + } + else + { + apiKey = CloudToken; + } SaveCloudToken(apiKey); });