Пример #1
0
        private string GetToken(string tenantId, PromptBehavior promptBehavior, bool updateUI = false)
        {
            //"d94647e7-c4ff-4a93-bbe0-d993badcc5b8"
            AuthenticationContext context = new AuthenticationContext(ServiceUrls.GetLoginUrl(app.Default.AzureAuth) + tenantId);

            AuthenticationResult result = null;

            try
            {
                result = context.AcquireToken(ServiceUrls.GetServiceManagementUrl(app.Default.AzureAuth), app.Default.ClientId, new Uri(app.Default.ReturnURL), promptBehavior);
                if (result == null)
                {
                    throw new InvalidOperationException("Failed to obtain the token");
                }
                if (updateUI)
                {
                    // lblSignInText.Text = $"Signed in as {result.UserInfo.DisplayableId}";
                }

                return(result.AccessToken);
            }
            catch (Exception exception)
            {
                DialogResult dialogresult = MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }
        }
Пример #2
0
        private Uri CreateBaseUrl()
        {
            var serviceUrl = ServiceUrls.ByEnvironment(_environment);
            var uri        = new Uri(serviceUrl);

            return(uri);
        }
Пример #3
0
        private string GetToken(string tenantId, PromptBehavior promptBehavior, bool updateUI = false, string AuthType = "AzureAuth")
        {
            lblStatus.Text = "BUSY: Authenticating...";
            //"d94647e7-c4ff-4a93-bbe0-d993badcc5b8"
            AuthenticationContext context = new AuthenticationContext(ServiceUrls.GetLoginUrl(app.Default.AzureAuth) + tenantId);

            AuthenticationResult result = null;
            string AuthUri = null;

            if (AuthType == "AzureAuth")
            {
                AuthUri = ServiceUrls.GetServiceManagementUrl(app.Default.AzureAuth);
            }
            else
            {
                AuthUri = ServiceUrls.GetServiceManagementUrl(app.Default.GraphAuth);
            }

            try
            {
                if (_userId == null)
                {
                    result  = context.AcquireToken(AuthUri, app.Default.ClientId, new Uri(app.Default.ReturnURL), promptBehavior);
                    _userId = new UserIdentifier(result.UserInfo.DisplayableId, UserIdentifierType.RequiredDisplayableId);
                }
                else
                {
                    result = context.AcquireToken(AuthUri, app.Default.ClientId, new Uri(app.Default.ReturnURL), PromptBehavior.Never, _userId);
                    // result = context.AcquireTokenSilent(ServiceUrls.GetServiceManagementUrl(app.Default.GraphAuth), app.Default.ClientId, _userId)
                }

                if (result == null)
                {
                    throw new InvalidOperationException("Failed to obtain the token");
                }
                if (updateUI)
                {
                    lblSignInText.Text = $"Signed in as {result.UserInfo.DisplayableId}";
                }

                return(result.AccessToken);
            }
            catch (Exception exception)
            {
                DialogResult dialogresult = MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }
        }
 public ServiceUrls GetServiceURL(string loginDomain)
 {
     try
     {
         if (_serviceUrls == null)
         {
             var getServiceTask = Task.Run(async() => { _serviceUrls = await bLoyal.Connectors.bLoyalService.GetServiceUrlsAsync(_conFigHelper.LOGIN_DOMAIN, _conFigHelper.DOMAIN_URL); });
             getServiceTask.Wait();
         }
         return(_serviceUrls);
     }
     catch (Exception ex)
     {
     }
     return(null);
 }
Пример #5
0
        private string GetToken(string tenantId, PromptBehavior promptBehavior, bool updateUI = false)
        {
            lblStatus.Text = "BUSY: Authenticating...";
            AuthenticationContext context = new AuthenticationContext(ServiceUrls.GetLoginUrl(app.Default.AzureEnvironment) + tenantId);

            AuthenticationResult result = null;

            result = context.AcquireToken(ServiceUrls.GetServiceManagementUrl(app.Default.AzureEnvironment), app.Default.ClientId, new Uri(app.Default.ReturnURL), promptBehavior);
            if (result == null)
            {
                throw new InvalidOperationException("Failed to obtain the token");
            }
            if (updateUI)
            {
                lblSignInText.Text = $"Signed in as {result.UserInfo.DisplayableId}";
            }

            return(result.AccessToken);
        }
Пример #6
0
        /// <summary>
        /// Call SubmitLogsAsync every 5 minutes
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                ConfigurationHelper configObj = new ConfigurationHelper();
                if (configObj.ENABLE_bLOYAL == "true")
                {
                    if (_serviceUrls == null)
                    {
                        var getServiceTask = Task.Run(async() => { _serviceUrls = await bLoyalService.GetServiceUrlsAsync(_config.LOGIN_DOMAIN, _config.DOMAIN_URL); });
                        getServiceTask.Wait();
                    }

                    var task = Task.Run(async() => { await _logger.SubmitLogsAsync(_serviceUrls.LoggingApiUrl, _config.ACCESS_KEY); });
                    task.Wait();
                }
            }
            catch
            {
            }
        }
        public async Task OfTShouldCreateHttpRequestMessage()
        {
            // arrange
            var url             = ServiceUrls.ByEnvironment(Enums.ReloadlyEnvironment.Live);
            var reloadlyRequest =
                new ReloadlyRequest <object>(HttpMethod.Get, new Uri(url))
                .SetHeader("Accept", "application/json")
                .SetBody(new { name = "bodyValue" })
                .SetQueryParameter("param", "queryValue");

            // act
            var request = reloadlyRequest.CreateHttpRequestMessage();

            // assert
            Assert.AreEqual(new Uri(url).Host, request.RequestUri.Host);

            var requestBody = await request.Content.ReadAsStringAsync();

            Assert.IsTrue(requestBody.Contains("\"name\":\"bodyValue\""));

            Assert.AreEqual("?param=queryValue", request.RequestUri.Query);
        }
        public async Task ShouldThrowRateLimitException()
        {
            var mhMock = new Mock <HttpMessageHandler>();

            var baseUrl      = ServiceUrls.ByEnvironment(ReloadlyEnvironment.Sandbox);
            var mockResponse = new HttpResponseMessage
            {
                RequestMessage = new HttpRequestMessage()
                {
                    RequestUri = new System.Uri(baseUrl)
                },
                StatusCode = HttpStatusCode.TooManyRequests
            };

            mockResponse.Headers.TryAddWithoutValidation("X-RateLimit-Limit", "10");
            mockResponse.Headers.TryAddWithoutValidation("X-RateLimit-Remaining", "0");
            mockResponse.Headers.TryAddWithoutValidation("X-RateLimit-Reset", "0");

            mhMock.Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(mockResponse);

            var httpClient            = new HttpClient(mhMock.Object);
            var httpClientFactoryMock = new Mock <IHttpClientFactory>();

            httpClientFactoryMock.Setup(m => m.CreateClient(It.IsAny <string>())).Returns(httpClient);

            var reloadlyHttpClient = new ReloadlyHttpClient(
                httpClientFactoryMock.Object, ReloadlyApiVersion.AirtimeV1, disableTelemetry: false);

            var response = await reloadlyHttpClient
                           .SendAsync(new ReloadlyRequest <object>(HttpMethod.Get, new System.Uri(ServiceUrls.AirtimeSandbox)));
        }
 public PhotoHelper(IServicesBaseUrlSettings servicesBaseUrlSettings, IWebHostEnvironment environment)
 {
     currentServiceUrls = servicesBaseUrlSettings.GetServiceUrlsByEnvironment(environment);
 }
 public StudentService(HttpClient httpClient, IOptions <List <ServiceUrls> > servicerUrl)
 {
     _apiClient        = httpClient;
     _serviceUrl       = servicerUrl.Value.Where(x => x.Name == nameof(StudentService)).FirstOrDefault();
     _studentByPassUrl = $"{_serviceUrl.Url}/api/v{_serviceUrl.Version}";
 }