Пример #1
0
        public Orchestrator(IInitializer initializer,
                            ILog log, IAdo ado,
                            IAuthenticationWrapper authWrapper, IRetryClient retryClient, ILogAppender logAppender,
                            IO365ActivityApiWrapper o365ActivityApiWrapper)
        {
            _log                    = log;
            _logAppender            = logAppender;
            _authWrapper            = authWrapper;
            _o365ActivityApiWrapper = o365ActivityApiWrapper;
            _ado                    = ado;
            _initializer            = initializer;
            _configuration          = _initializer.Configuration;
            _retryClient            = retryClient;

            AuditLogTimeStampsForPowerPlatform = GetLatestTimeStampForPowerPlatform;

            _O365ServiceAuthenticationContract = new ServiceAuthenticationContract
            {
                ClientId     = _configuration.AppSettings.AuditLogClientId,
                ClientSecret = _configuration.AppSettings.AuditLogClientSecret,
                LoginUrl     = _configuration.AppSettings.LoginUrl,
                ResourceUrl  = _configuration.AppSettings.Office365ResourceId,
                TenantId     = _configuration.AppSettings.TenantId
            };
        }
Пример #2
0
        /// <summary>
        /// Fetches Office 365 access token. If Token is expired,
        /// </summary>
        /// <returns></returns>
        private async Task ApplyAccessTokenAsync(ServiceAuthenticationContract serviceAuthenticationContract)
        {
            if (_authenticationResult == null || DateTime.UtcNow >= _authenticationResult.ExpiresOn)
            {
                _authenticationResult = await _authWrapper.GetAuthenticationResult(serviceAuthenticationContract);

                _httpClient.DefaultRequestHeaders.Clear();
                _httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + _authenticationResult.AccessToken);
            }
        }
        /// <summary>
        /// This method authenticates app registration against resource and returns JWT access token.
        /// The access token can be used to access Azure Resource
        /// </summary>
        /// <param name="serviceAuthenticationContract"></param>
        /// <returns> Authentication Result</returns>
        public async Task <AuthenticationResult> GetAuthenticationResult(ServiceAuthenticationContract serviceAuthenticationContract)
        {
            var authContext      = new AuthenticationContext(string.Format("{0}/{1}", serviceAuthenticationContract.LoginUrl, serviceAuthenticationContract.TenantId));
            var clientCredential = new ClientCredential(serviceAuthenticationContract.ClientId, serviceAuthenticationContract.ClientSecret);
            var result           = await authContext.AcquireTokenAsync(serviceAuthenticationContract.ResourceUrl, clientCredential);

            if (result == null)
            {
                throw new InvalidOperationException("Could not get token");
            }

            return(result);
        }
        public MetadataStoreContextFactory(IInitializer initializer, IAuthenticationWrapper authWrapper)
        {
            _configuration = initializer.Configuration;
            _authWrapper   = authWrapper;

            _sqlServiceAuthenticationContract = new ServiceAuthenticationContract
            {
                ClientId     = _configuration.AppSettings.DatabaseClientId,
                ClientSecret = _configuration.AppSettings.DatabaseClientSecret,
                LoginUrl     = _configuration.AppSettings.LoginUrl,
                ResourceUrl  = _configuration.AppSettings.DatabaseResourceId,
                TenantId     = _configuration.AppSettings.TenantId
            };
        }
Пример #5
0
        public O365ActivityApiWrapper(ILog log, IInitializer initializer, IRetryClient retryClient)
        {
            _log           = log;
            _retryClient   = retryClient;
            _configuration = initializer.Configuration;

            _O365ServiceAuthenticationContract = new ServiceAuthenticationContract
            {
                ClientId     = _configuration.AppSettings.AuditLogClientId,
                ClientSecret = _configuration.AppSettings.AuditLogClientSecret,
                LoginUrl     = _configuration.AppSettings.LoginUrl,
                ResourceUrl  = _configuration.AppSettings.Office365ResourceId,
                TenantId     = _configuration.AppSettings.TenantId
            };
        }
Пример #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="url"></param>
        /// <param name="serviceAuthenticationContract"></param>
        /// <returns></returns>
        public async Task <HttpResponseMessage> GetAsyncWithRetryAsync(string url, ServiceAuthenticationContract serviceAuthenticationContract)
        {
            try
            {
                var response = await _asyncRetryPolicy.ExecuteAsync(async() =>
                {
                    await ApplyAccessTokenAsync(serviceAuthenticationContract).ConfigureAwait(false);
                    return(await _httpClient.GetAsync(url).ConfigureAwait(false));
                });

                return(response);
            }
            catch (Exception e)
            {
                _log.Error(e.GetExceptionFootprints());
                return(new HttpResponseMessage
                {
                    StatusCode = System.Net.HttpStatusCode.InternalServerError,
                    Content = new StringContent($"Request Failed {e.GetExceptionFootprints()}")
                });
            }
        }