public static PSAzureAccount ToPSAzureAccount(this AzureAccount account)
        {
            string subscriptionsList = account.GetProperty(AzureAccount.Property.Subscriptions);
            string tenantsList       = account.GetProperty(AzureAccount.Property.Tenants);

            return(new PSAzureAccount
            {
                Id = account.Id,
                Type = account.Type,
                Subscriptions = subscriptionsList == null ? "" : subscriptionsList.Replace(",", "\r\n"),
                Tenants = tenantsList == null ? "" : tenantsList.Replace(",", "\r\n")
            });
        }
Beispiel #2
0
        public static PSAzureAccount ToPSAzureAccount(this AzureAccount account)
        {
            string subscriptionsList = account.GetProperty(AzureAccount.Property.Subscriptions);
            string tenantsList       = account.GetProperty(AzureAccount.Property.Tenants);

            return(new PSAzureAccount
            {
                Id = account.Id,
                Type = account.Type,
                Subscriptions = subscriptionsList == null ? "" : subscriptionsList.Replace(",", "\r\n"),
                Tenants = tenantsList == null ? null : new List <string>(tenantsList.Split(new [] { "," }, StringSplitOptions.RemoveEmptyEntries))
            });
        }
        public IAccessToken Authenticate(
            AzureAccount account,
            AzureEnvironment environment,
            string tenant,
            SecureString password,
            ShowDialog promptBehavior,
            TokenCache tokenCache,
            AzureEnvironment.Endpoint resourceId = AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId)
        {
            var configuration = GetAdalConfiguration(environment, tenant, resourceId, tokenCache);

            TracingAdapter.Information(Resources.AdalAuthConfigurationTrace, configuration.AdDomain, configuration.AdEndpoint,
                                       configuration.ClientId, configuration.ClientRedirectUri, configuration.ResourceClientUri, configuration.ValidateAuthority);
            IAccessToken token;

            if (account.IsPropertySet(AzureAccount.Property.CertificateThumbprint))
            {
                var thumbprint = account.GetProperty(AzureAccount.Property.CertificateThumbprint);
                token = TokenProvider.GetAccessTokenWithCertificate(configuration, account.Id, thumbprint, account.Type);
            }
            else
            {
                token = TokenProvider.GetAccessToken(configuration, promptBehavior, account.Id, password, account.Type);
            }

            account.Id = token.UserId;
            return(token);
        }
Beispiel #4
0
        private AzureAccount MergeAccountProperties(AzureAccount account1, AzureAccount account2)
        {
            if (account1 == null || account2 == null)
            {
                throw new ArgumentNullException("account1");
            }
            if (!string.Equals(account1.Id, account2.Id, StringComparison.InvariantCultureIgnoreCase))
            {
                throw new ArgumentException("Account Ids do not match.");
            }
            if (account1.Type != account2.Type)
            {
                throw new ArgumentException("Account1 types do not match.");
            }
            AzureAccount mergeAccount = new AzureAccount
            {
                Id   = account1.Id,
                Type = account1.Type
            };

            // Merge all properties
            foreach (AzureAccount.Property property in Enum.GetValues(typeof(AzureAccount.Property)))
            {
                string propertyValue = account1.GetProperty(property) ?? account2.GetProperty(property);
                if (propertyValue != null)
                {
                    mergeAccount.Properties[property] = propertyValue;
                }
            }

            // Merge Tenants
            var tenants = account1.GetPropertyAsArray(AzureAccount.Property.Tenants)
                          .Union(account2.GetPropertyAsArray(AzureAccount.Property.Tenants), StringComparer.CurrentCultureIgnoreCase);

            mergeAccount.SetProperty(AzureAccount.Property.Tenants, tenants.ToArray());

            // Merge Subscriptions
            var subscriptions = account1.GetPropertyAsArray(AzureAccount.Property.Subscriptions)
                                .Union(account2.GetPropertyAsArray(AzureAccount.Property.Subscriptions), StringComparer.CurrentCultureIgnoreCase);

            mergeAccount.SetProperty(AzureAccount.Property.Subscriptions, subscriptions.ToArray());

            return(mergeAccount);
        }
 /// <summary>
 /// Create a new access token from the given account and tenant id
 /// </summary>
 /// <param name="account">The account, containing user id, access token information</param>
 /// <param name="tenantId">The tenant id for the given access token</param>
 /// <param name="tokenType">The token type for the given token.</param>
 public SimpleAccessToken(AzureAccount account, string tenantId, string tokenType = _defaultTokenType)
 {
     if (account == null)
     {
         throw new ArgumentNullException("account");
     }
     if (string.IsNullOrWhiteSpace(account.Id))
     {
         throw new ArgumentOutOfRangeException("account", Resources.AccessTokenRequiresAccount);
     }
     if (account.Type != AzureAccount.AccountType.AccessToken ||
         !account.IsPropertySet(AzureAccount.Property.AccessToken))
     {
         throw new ArgumentException(Resources.TypeNotAccessToken);
     }
     this.UserId      = account.Id;
     this._tokenType  = tokenType;
     this.AccessToken = account.GetProperty(AzureAccount.Property.AccessToken);
     this.TenantId    = tenantId;
 }