Skip to content

Commit

Permalink
VCI-921: CloudAuth stores CloudToken if it is passed (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
krankenbro authored Oct 3, 2024
1 parent 1448b7a commit d44bcc7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
3 changes: 2 additions & 1 deletion docs/targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,11 @@ vc-build CloudEnvStatus -CloudToken <your token> -EnvironmentName <environment
:::
## CloudAuth
This target saves a token for accessing the VirtoCloud portal, eliminating the need to use the CloudToken parameter with every call to targets in the Cloud group.
Gets parameters: AzureAD (optional)
Gets parameters: AzureAD (optional), CloudToken (optional)
```console
vc-build CloudAuth
vc-build CloudAuth -AzureAD
vc-build CloudAuth -CloudToken <token>
```
:::
:::
Expand Down
40 changes: 24 additions & 16 deletions src/VirtoCommerce.Build/Cloud/Build.SaaS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit d44bcc7

Please sign in to comment.