예제 #1
0
        public async Task <List <AzureDomain> > GetAzureARMDomains(AzureContext azureContext, bool allowRestCacheUse = false)
        {
            try
            {
                azureContext.LogProvider.WriteLog("GetAzureARMDomains", "Start");

                if (this == null)
                {
                    throw new ArgumentNullException("AzureContext is null.  Unable to call Azure API without Azure Context.");
                }
                if (azureContext.TokenProvider == null)
                {
                    throw new ArgumentNullException("TokenProvider Context is null.  Unable to call Azure API without TokenProvider.");
                }

                String domainUrl = azureContext.AzureEnvironment.GraphEndpoint + "myorganization/domains?api-version=1.6";

                AuthenticationResult tenantAuthenticationResult = await azureContext.TokenProvider.GetToken(azureContext.AzureEnvironment.GraphEndpoint, this.TenantId, PromptBehavior.Never);

                azureContext.StatusProvider.UpdateStatus("BUSY: Getting Tenant Domain details from Graph...");

                AzureRestRequest  azureRestRequest  = new AzureRestRequest(domainUrl, tenantAuthenticationResult, "GET", allowRestCacheUse);
                AzureRestResponse azureRestResponse = await azureContext.AzureRetriever.GetAzureRestResponse(azureRestRequest);

                JObject domainsJson = JObject.Parse(azureRestResponse.Response);

                var domains = from domain in domainsJson["value"]
                              select domain;

                _Domains = new List <AzureDomain>();

                foreach (JObject domainJson in domains)
                {
                    try
                    {
                        AzureDomain azureDomain = new AzureDomain(this, domainJson);
                        _Domains.Add(azureDomain);
                    }
                    catch (Exception exc)
                    {
                        azureContext.LogProvider.WriteLog("GetAzureARMDomains", "Error getting Azure AD Domain:" + exc.Message);
                    }
                }
            }
            catch (Exception exc)
            {
                azureContext.LogProvider.WriteLog("GetAzureARMDomains", "Error getting Azure Subscriptions:" + exc.Message);
            }

            return(_Domains);
        }
예제 #2
0
        public async Task <List <AzureDomain> > GetAzureARMDomains(AzureTenant azureTenant)
        {
            _AzureContext.LogProvider.WriteLog("GetAzureARMDomains", "Start");

            if (_AzureContext == null)
            {
                throw new ArgumentNullException("AzureContext is null.  Unable to call Azure API without Azure Context.");
            }
            if (_AzureContext.TokenProvider == null)
            {
                throw new ArgumentNullException("TokenProvider Context is null.  Unable to call Azure API without TokenProvider.");
            }
            if (_AzureContext.TokenProvider.AccessToken == null)
            {
                throw new ArgumentNullException("AccessToken Context is null.  Unable to call Azure API without AccessToken.");
            }

            String accessToken = _AzureContext.TokenProvider.AccessToken;

            String domainUrl = _AzureContext.AzureServiceUrls.GetGraphApiUrl() + "myorganization/domains?api-version=1.6";

            AuthenticationResult tenantAuthenticationResult = await _AzureContext.TokenProvider.GetGraphToken(azureTenant.TenantId.ToString());

            if (tenantAuthenticationResult != null)
            {
                accessToken = tenantAuthenticationResult.AccessToken;
            }

            _AzureContext.StatusProvider.UpdateStatus("BUSY: Getting Tenant Domain details from Graph...");

            AzureRestRequest  azureRestRequest  = new AzureRestRequest(domainUrl, accessToken, "GET", false);
            AzureRestResponse azureRestResponse = await _AzureContext.AzureRetriever.GetAzureRestResponse(azureRestRequest);

            JObject domainsJson = JObject.Parse(azureRestResponse.Response);

            var domains = from domain in domainsJson["value"]
                          select domain;

            List <AzureDomain> armTenantDomains = new List <AzureDomain>();

            foreach (JObject domainJson in domains)
            {
                AzureDomain azureDomain = new AzureDomain(domainJson, _AzureContext);
                armTenantDomains.Add(azureDomain);
            }

            return(armTenantDomains);
        }