support auto-login
This commit is contained in:
Родитель
245a1a3135
Коммит
93d3915fdc
|
@ -87,7 +87,7 @@ namespace ARMClient.Authentication.AADAuthentication
|
||||||
{
|
{
|
||||||
foreach (var authResult in authResults)
|
foreach (var authResult in authResults)
|
||||||
{
|
{
|
||||||
Console.WriteLine(authResult.UserInfo.UserId);
|
Trace.WriteLine(authResult.UserInfo.UserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new InvalidOperationException("Multiple users found. Please specify user argument!");
|
throw new InvalidOperationException("Multiple users found. Please specify user argument!");
|
||||||
|
@ -131,10 +131,10 @@ namespace ARMClient.Authentication.AADAuthentication
|
||||||
tenantId = tenantId
|
tenantId = tenantId
|
||||||
};
|
};
|
||||||
|
|
||||||
Console.WriteLine("App: {0}, Tenant: {1}", appId, tenantId);
|
Trace.WriteLine(String.Format("App: {0}, Tenant: {1}", appId, tenantId));
|
||||||
|
|
||||||
var subscriptions = await GetSubscriptions(authResult);
|
var subscriptions = await GetSubscriptions(authResult);
|
||||||
Console.WriteLine("\tThere are {0} subscriptions", subscriptions.Length);
|
Trace.WriteLine(String.Format("\tThere are {0} subscriptions", subscriptions.Length));
|
||||||
|
|
||||||
info.subscriptions = subscriptions.Select(subscription => new SubscriptionCacheInfo
|
info.subscriptions = subscriptions.Select(subscription => new SubscriptionCacheInfo
|
||||||
{
|
{
|
||||||
|
@ -144,7 +144,7 @@ namespace ARMClient.Authentication.AADAuthentication
|
||||||
|
|
||||||
foreach (var subscription in subscriptions)
|
foreach (var subscription in subscriptions)
|
||||||
{
|
{
|
||||||
Console.WriteLine("\tSubscription {0} ({1})", subscription.subscriptionId, subscription.displayName);
|
Trace.WriteLine(String.Format("\tSubscription {0} ({1})", subscription.subscriptionId, subscription.displayName));
|
||||||
}
|
}
|
||||||
|
|
||||||
tenantCache[tenantId] = info;
|
tenantCache[tenantId] = info;
|
||||||
|
@ -336,7 +336,7 @@ namespace ARMClient.Authentication.AADAuthentication
|
||||||
protected async Task<Dictionary<string, TenantCacheInfo>> GetTokenForTenants(Dictionary<TokenCacheKey, string> tokenCache, AuthenticationResult authResult)
|
protected async Task<Dictionary<string, TenantCacheInfo>> GetTokenForTenants(Dictionary<TokenCacheKey, string> tokenCache, AuthenticationResult authResult)
|
||||||
{
|
{
|
||||||
var tenantIds = await GetTenantIds(authResult);
|
var tenantIds = await GetTenantIds(authResult);
|
||||||
Console.WriteLine("User {0} belongs to {1} tenants", authResult.UserInfo.UserId, tenantIds.Length);
|
Trace.WriteLine(string.Format("User {0} belongs to {1} tenants", authResult.UserInfo.UserId, tenantIds.Length));
|
||||||
|
|
||||||
var tenantCache = this.TenantStorage.GetCache();
|
var tenantCache = this.TenantStorage.GetCache();
|
||||||
foreach (var tenantId in tenantIds)
|
foreach (var tenantId in tenantIds)
|
||||||
|
|
|
@ -106,17 +106,25 @@ namespace ARMClient
|
||||||
|| String.Equals(verb, "post", StringComparison.OrdinalIgnoreCase))
|
|| String.Equals(verb, "post", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
var path = _parameters.Get(1, keyName: "url");
|
var path = _parameters.Get(1, keyName: "url");
|
||||||
|
var verbose = _parameters.Get("-verbose", requires: false) != null;
|
||||||
var baseUri = new Uri(ARMClient.Authentication.Constants.CSMUrls[(int)AzureEnvironments.Prod]);
|
var baseUri = new Uri(ARMClient.Authentication.Constants.CSMUrls[(int)AzureEnvironments.Prod]);
|
||||||
var uri = new Uri(baseUri, path);
|
var uri = new Uri(baseUri, path);
|
||||||
|
|
||||||
// TODO: acquire token
|
if (!verbose)
|
||||||
EnsureTokenCache(persistentAuthHelper);
|
{
|
||||||
|
Trace.Listeners.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!persistentAuthHelper.IsCacheValid())
|
||||||
|
{
|
||||||
|
persistentAuthHelper.AzureEnvironments = GetAzureEnvironments(uri);
|
||||||
|
persistentAuthHelper.AcquireTokens().Wait();
|
||||||
|
}
|
||||||
|
|
||||||
var env = persistentAuthHelper.AzureEnvironments;
|
var env = persistentAuthHelper.AzureEnvironments;
|
||||||
baseUri = new Uri(ARMClient.Authentication.Constants.CSMUrls[(int)env]);
|
baseUri = new Uri(ARMClient.Authentication.Constants.CSMUrls[(int)env]);
|
||||||
uri = new Uri(baseUri, path);
|
uri = new Uri(baseUri, path);
|
||||||
var content = ParseHttpContent(verb, _parameters);
|
var content = ParseHttpContent(verb, _parameters);
|
||||||
var verbose = _parameters.Get("-verbose", requires: false) != null;
|
|
||||||
_parameters.ThrowIfUnknown();
|
_parameters.ThrowIfUnknown();
|
||||||
|
|
||||||
var subscriptionId = GetSubscription(uri);
|
var subscriptionId = GetSubscription(uri);
|
||||||
|
@ -141,14 +149,9 @@ namespace ARMClient
|
||||||
PrintUsage();
|
PrintUsage();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
catch (CommandLineException ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine(ex.Message);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine(ex);
|
Console.WriteLine(ex.GetBaseException().Message);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,7 +166,7 @@ namespace ARMClient.Library
|
||||||
using (var client = new HttpClient(new HttpClientHandler()))
|
using (var client = new HttpClient(new HttpClientHandler()))
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Add("Authorization", this._authorizationHeader);
|
client.DefaultRequestHeaders.Add("Authorization", this._authorizationHeader);
|
||||||
client.DefaultRequestHeaders.Add("User-Agent", "CSMClient-" + Environment.MachineName);
|
client.DefaultRequestHeaders.Add("User-Agent", "ARMClient-" + Environment.MachineName);
|
||||||
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||||
|
|
||||||
HttpResponseMessage response = null;
|
HttpResponseMessage response = null;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче