protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request,
                                                                CancellationToken cancellationToken)
        {
            var requestUri = request.RequestUri;
            var authority  = string.Empty;
            var targetUri  = requestUri;

            // NOTE: The KmsNetworkUrl setting is purely for development testing on the
            //       Microsoft Azure Development Fabric and should not be used outside that environment.
            string networkUrl = TestConfigurationManager.TryGetEnvironmentOrAppSetting("KmsNetworkUrl");

            if (!string.IsNullOrEmpty(networkUrl))
            {
                authority = targetUri.Authority;
                targetUri = new Uri(new Uri(networkUrl), targetUri.PathAndQuery);

                request.Headers.Add("Host", authority);
                request.RequestUri = targetUri;
            }

            return(base.SendAsync(request, cancellationToken).ContinueWith <HttpResponseMessage>(response =>
            {
                return response.Result;
            }));
        }
예제 #2
0
        private bool FromConfiguration()
        {
            string vault                   = TestConfigurationManager.TryGetEnvironmentOrAppSetting("VaultUrl");
            string authClientId            = TestConfigurationManager.TryGetEnvironmentOrAppSetting("AuthClientId");
            string authSecret              = TestConfigurationManager.TryGetEnvironmentOrAppSetting("AuthClientSecret");
            string standardVaultOnlyString = TestConfigurationManager.TryGetEnvironmentOrAppSetting("StandardVaultOnly");
            bool   result;

            if (!bool.TryParse(standardVaultOnlyString, out result))
            {
                result = false;
            }

            if (string.IsNullOrWhiteSpace(vault) || string.IsNullOrWhiteSpace(authClientId) || string.IsNullOrWhiteSpace(authSecret))
            {
                return(false);
            }
            else
            {
                this.vaultAddress      = vault;
                this.clientCredential  = new ClientCredential(authClientId, authSecret);
                this.standardVaultOnly = result;
                return(true);
            }
        }
예제 #3
0
        public async Task <string> GetUserAccessToken(string authority, string resource, string scope)
        {
            string clientId = TestConfigurationManager.TryGetEnvironmentOrAppSetting("NativeClientId");
            var    context  = new AuthenticationContext(authority, tokenCache);

            if (_deviceCodeForStorageTests == null)
            {
                _deviceCodeForStorageTests =
                    await context.AcquireDeviceCodeAsync(resource, clientId).ConfigureAwait(false);

                Debug.WriteLine("############################################################################################");
                Debug.WriteLine("Test won't run until you perform following steps:");
                Debug.WriteLine($"1. Go to following url: {_deviceCodeForStorageTests.VerificationUrl}.");
                Debug.WriteLine($"2. Insert following User Code: {_deviceCodeForStorageTests.UserCode}.");
                Debug.WriteLine("3. Login with your username and password credentials.");
                Debug.WriteLine("############################################################################################");
            }

            var result = await context.AcquireTokenByDeviceCodeAsync(_deviceCodeForStorageTests).ConfigureAwait(false);

            return(result.AccessToken);
        }
예제 #4
0
        private bool FromConfiguration()
        {
            string vault                   = TestConfigurationManager.TryGetEnvironmentOrAppSetting("VaultUrl");
            string authClientId            = TestConfigurationManager.TryGetEnvironmentOrAppSetting("AuthClientId");
            string authSecret              = TestConfigurationManager.TryGetEnvironmentOrAppSetting("AuthClientSecret");
            string standardVaultOnlyString = TestConfigurationManager.TryGetEnvironmentOrAppSetting("StandardVaultOnly");
            string softDeleteEnabledString = TestConfigurationManager.TryGetEnvironmentOrAppSetting("SoftDeleteEnabled");
            string storageUrl1             = TestConfigurationManager.TryGetEnvironmentOrAppSetting("StorageResourceUrl1");
            string storageUrl2             = TestConfigurationManager.TryGetEnvironmentOrAppSetting("StorageResourceUrl2");
            bool   standardVaultOnlyresult;

            if (!bool.TryParse(standardVaultOnlyString, out standardVaultOnlyresult))
            {
                standardVaultOnlyresult = false;
            }

            bool softDeleteEnabledresult;

            if (!bool.TryParse(softDeleteEnabledString, out softDeleteEnabledresult))
            {
                softDeleteEnabledresult = false;
            }

            if (string.IsNullOrWhiteSpace(vault) || string.IsNullOrWhiteSpace(authClientId) || string.IsNullOrWhiteSpace(authSecret) ||
                string.IsNullOrWhiteSpace(storageUrl1) || string.IsNullOrWhiteSpace(storageUrl2))
            {
                return(false);
            }
            else
            {
                this.vaultAddress        = vault;
                this.clientCredential    = new ClientCredential(authClientId, authSecret);
                this.standardVaultOnly   = standardVaultOnlyresult;
                this.softDeleteEnabled   = softDeleteEnabledresult;
                this.StorageResourceUrl1 = storageUrl1;
                this.StorageResourceUrl2 = storageUrl2;
                return(true);
            }
        }