public GetAddesssApi(ApiKey apiKey, AdminKey adminKey, HttpClient httpClient = null) { _client = httpClient ?? new HttpClient { BaseAddress = _baseAddress }; _client.DefaultRequestHeaders.TryAddWithoutValidation("accept", "application/json"); AdminKey = adminKey; ApiKey = apiKey; DomainWhitelist = new DomainWhitelistApi(AdminKey, this); IpAddressWhitelist = new IpAddressWhitelistApi(AdminKey, this); PrivateAddress = new PrivateAddressApi(AdminKey, this); Usage = new UsageApi(AdminKey, this); BillingAddress = new BillingAddressApi(AdminKey, this); Address = new AddressApi(ApiKey, this); FirstLimitReachedWebhook = new FirstLimitReachedWebhookApi(AdminKey, this); Subscription = new SubscriptionApi(adminKey, this); ApiKeyApi = new ApiKeyApi(adminKey, this); }
public static void SetWorksheetName(this Worksheet worksheet, UsageApi usageApi, BillingApiType billingApiType) { int counter = 1; do { string worksheetName = null; switch (usageApi) { case UsageApi.CloudSolutionProvider: worksheetName = string.Format(CultureInfo.CurrentUICulture, billingApiType == BillingApiType.RateCard ? CspRateCardWorksheetNameTemplate : CspUsageReportWorksheetNameTemplate, counter); break; case UsageApi.EnterpriseAgreement: worksheetName = string.Format(CultureInfo.CurrentUICulture, billingApiType == BillingApiType.RateCard ? EaRateCardWorksheetNameTemplate : EaUsageReportWorksheetNameTemplate, counter); break; default: worksheetName = string.Format(CultureInfo.CurrentUICulture, billingApiType == BillingApiType.RateCard ? StandardRateCardWorksheetNameTemplate : StandardUsageReportWorksheetNameTemplate, counter); break; } if (!Globals.ThisAddIn.Application.Worksheets.Contains(worksheetName)) { worksheet.Name = worksheetName; return; } counter++; } while (counter < MaxNameRetries); }
public static string GetAuthorizationHeader(string tenantId, bool forceReAuthentication, UsageApi usageApi, string customApplicationId, string customApplicationKey, AzureEnvironment environment) { var authUrl = string.Format(CultureInfo.InvariantCulture, "{0}/{1}", usageApi == UsageApi.CloudSolutionProvider ? CspAzureAuthUrl : AzureAuthUrl, tenantId); var context = new AuthenticationContext(authUrl); var resourceUrl = usageApi == UsageApi.CloudSolutionProvider ? GraphResourceUrl : GetResourceUrlByEnvironment(environment); var customApplicationIdSpecified = !string.IsNullOrWhiteSpace(customApplicationId); var applicationId = customApplicationIdSpecified ? customApplicationId : ApplicationId; ClientCredential clientCredential = null; if (customApplicationIdSpecified && !string.IsNullOrWhiteSpace(customApplicationKey)) { clientCredential = new ClientCredential(applicationId, customApplicationKey); } AuthenticationResult result; if (!forceReAuthentication) { // First try a silent auth. try { var userId = TokenCache.DefaultShared.ReadItems().FirstOrDefault(); if (userId != null) { if (clientCredential != null) { result = context.AcquireTokenSilent( resourceUrl, clientCredential, new UserIdentifier(userId.UniqueId, UserIdentifierType.OptionalDisplayableId)); } else { result = context.AcquireTokenSilent( resourceUrl, applicationId, new UserIdentifier(userId.UniqueId, UserIdentifierType.OptionalDisplayableId)); } return(result.AccessToken); } } catch { /* swallowing auth exceptions only for silent auth */ } } if (clientCredential != null) { result = context.AcquireToken( resourceUrl, clientCredential); } else { result = context.AcquireToken( resourceUrl, applicationId, new Uri(usageApi == UsageApi.CloudSolutionProvider ? CspRedirectUrn : RedirectUrn), forceReAuthentication ? PromptBehavior.Always : PromptBehavior.Auto); } return(result.AccessToken); }
public static string GetAuthorizationHeader(string tenantId, bool forceReAuthentication, UsageApi usageApi, AzureEnvironment environment) { return(GetAuthorizationHeader(tenantId, forceReAuthentication, usageApi, null, null, environment)); }
public void Init() { instance = new UsageApi(); }