/// <summary> /// Copy Constructor /// </summary> /// <param name="testEndpoint">endPoint instance</param> private TestEndpoints(TestEndpoints testEndpoint) { Name = testEndpoint.Name; ServiceManagementUri = testEndpoint.ServiceManagementUri; ResourceManagementUri = testEndpoint.ResourceManagementUri; GraphUri = testEndpoint.GraphUri; GalleryUri = testEndpoint.GalleryUri; AADAuthUri = testEndpoint.AADAuthUri; RdfePortalUri = testEndpoint.RdfePortalUri; IbizaPortalUri = testEndpoint.IbizaPortalUri; DataLakeStoreServiceUri = testEndpoint.DataLakeStoreServiceUri; DataLakeAnalyticsJobAndCatalogServiceUri = testEndpoint.DataLakeAnalyticsJobAndCatalogServiceUri; AADTokenAudienceUri = testEndpoint.AADTokenAudienceUri; GraphTokenAudienceUri = testEndpoint.GraphTokenAudienceUri; PublishingSettingsFileUri = testEndpoint.PublishingSettingsFileUri; }
private static void LoginWithPromptAsync( Dictionary <TokenAudience, TokenCredentials> tokens, string domain, TestEndpoints endpoints) { var mgmSettings = new ActiveDirectoryServiceSettings() { AuthenticationEndpoint = new Uri(endpoints.AADAuthUri.ToString() + domain), TokenAudience = endpoints.AADTokenAudienceUri }; var grpSettings = new ActiveDirectoryServiceSettings() { AuthenticationEndpoint = new Uri(endpoints.AADAuthUri.ToString() + domain), TokenAudience = endpoints.GraphTokenAudienceUri }; var clientSettings = new ActiveDirectoryClientSettings() { ClientId = TestEnvironment.ClientIdDefault, ClientRedirectUri = new Uri("urn:ietf:wg:oauth:2.0:oob"), PromptBehavior = PromptBehavior.Auto }; var mgmAuthResult = (TokenCredentials)UserTokenProvider .LoginWithPromptAsync(domain, clientSettings, mgmSettings) .ConfigureAwait(false) .GetAwaiter().GetResult(); try { var graphAuthResult = (TokenCredentials)UserTokenProvider .LoginWithPromptAsync(domain, clientSettings, grpSettings) .GetAwaiter().GetResult(); tokens[TokenAudience.Graph] = graphAuthResult; } catch { // Not all accounts are registered to have access to Graph endpoints. } tokens[TokenAudience.Management] = mgmAuthResult; }
private static async Task LoginServicePrincipalAsync( Dictionary <TokenAudience, TokenCredentials> tokens, string domain, string servicePrincipalId, string key, TestEndpoints endpoints) { var mgmSettings = new ActiveDirectoryServiceSettings() { AuthenticationEndpoint = new Uri(endpoints.AADAuthUri.ToString() + domain), TokenAudience = endpoints.AADTokenAudienceUri }; var mgmAuthResult = (TokenCredentials)await ApplicationTokenProvider .LoginSilentAsync(domain, servicePrincipalId, key, mgmSettings) .ConfigureAwait(false); var grpSettings = new ActiveDirectoryServiceSettings() { AuthenticationEndpoint = new Uri(endpoints.AADAuthUri.ToString() + domain), TokenAudience = endpoints.GraphTokenAudienceUri }; try { var graphAuthResult = (TokenCredentials)await ApplicationTokenProvider .LoginSilentAsync(domain, servicePrincipalId, key, grpSettings) .ConfigureAwait(false); tokens[TokenAudience.Graph] = graphAuthResult; } catch { // Not all accounts are registered to have access to Graph endpoints. } tokens[TokenAudience.Management] = mgmAuthResult; }
private static async Task LoginUserAsync( Dictionary <TokenAudience, TokenCredentials> tokens, string domain, string username, string password, TestEndpoints endpoints) { var mgmSettings = new ActiveDirectoryServiceSettings() { AuthenticationEndpoint = new Uri(endpoints.AADAuthUri.ToString() + domain), TokenAudience = endpoints.AADTokenAudienceUri }; var grpSettings = new ActiveDirectoryServiceSettings() { AuthenticationEndpoint = new Uri(endpoints.AADAuthUri.ToString() + domain), TokenAudience = endpoints.GraphTokenAudienceUri }; var mgmAuthResult = (TokenCredentials)await UserTokenProvider .LoginSilentAsync(TestEnvironment.ClientIdDefault, domain, username, password, mgmSettings) .ConfigureAwait(false); try { var graphAuthResult = (TokenCredentials)await UserTokenProvider .LoginSilentAsync(TestEnvironment.ClientIdDefault, domain, username, password, grpSettings) .ConfigureAwait(false); tokens[TokenAudience.Graph] = graphAuthResult; } catch { // Not all accounts are registered to have access to Graph endpoints. } tokens[TokenAudience.Management] = mgmAuthResult; }
/// <summary> /// Constructor updates endpoint URI that matches provided connection string /// </summary> /// <param name="testEndpoint">endPoint that needs to be updated according to connection string</param> /// <param name="connString">User provided connection string</param> internal TestEndpoints(TestEndpoints testEndpoint, ConnectionString connStr) : this(testEndpoint) { UpdateEnvironmentEndpoint(connStr); }
private static bool MatchEnvironmentBaseUri(TestEndpoints testEndpoint, string endpointValue) { endpointValue = EnsureTrailingSlash(endpointValue); return(string.Equals(testEndpoint.ResourceManagementUri.ToString(), endpointValue, StringComparison.OrdinalIgnoreCase)); }
public TestEnvironment(IDictionary <string, string> connection) { this.TokenInfo = new Dictionary <TokenAudience, TokenCredentials>(); // Instantiate dictionary of parameters RawParameters = new Dictionary <string, string>(); // By default set env to Prod this.Endpoints = TestEnvironment.EnvEndpoints[EnvironmentDefault]; this.BaseUri = this.Endpoints.ResourceManagementUri; this.ClientId = TestEnvironment.ClientIdDefault; this.Tenant = TestEnvironment.AADTenantDefault; if (connection != null) { if (connection.ContainsKey(TestEnvironment.UserIdKey)) { this.UserName = connection[TestEnvironment.UserIdKey]; var splitUser = this.UserName.Split(new [] { '@' }, StringSplitOptions.RemoveEmptyEntries); if (splitUser.Length == 2) { this.Tenant = splitUser[1]; } } if (connection.ContainsKey(TestEnvironment.ServicePrincipalKey)) { this.ServicePrincipal = connection[TestEnvironment.ServicePrincipalKey]; } if (connection.ContainsKey(TestEnvironment.AADTenantKey)) { this.Tenant = connection[TestEnvironment.AADTenantKey]; } if (connection.ContainsKey(TestEnvironment.SubscriptionIdKey)) { this.SubscriptionId = connection[TestEnvironment.SubscriptionIdKey]; } if (connection.ContainsKey(TestEnvironment.ClientIdKey)) { this.ClientId = connection[TestEnvironment.ClientIdKey]; } if (connection.ContainsKey(TestEnvironment.EnvironmentKey)) { if (ConnectionStringContainsEndpoint(connection)) { throw new ArgumentException("Invalid connection string, can contain endpoints or environment but not both", "connection"); } var envNameString = connection[TestEnvironment.EnvironmentKey]; EnvironmentNames envName; if (!Enum.TryParse <EnvironmentNames>(envNameString, out envName)) { throw new Exception( string.Format("Environment \"{0}\" is not valid", envNameString)); } this.Endpoints = TestEnvironment.EnvEndpoints[envName]; //need to set the right baseUri this.BaseUri = this.Endpoints.ResourceManagementUri; } if (connection.ContainsKey(TestEnvironment.BaseUriKey)) { var baseUriString = connection[TestEnvironment.BaseUriKey]; this.BaseUri = new Uri(baseUriString); if (!connection.ContainsKey(TestEnvironment.EnvironmentKey)) { EnvironmentNames envName = LookupEnvironmentFromBaseUri(baseUriString); this.Endpoints = TestEnvironment.EnvEndpoints[envName]; } } if (connection.ContainsKey(ConnectionStringFields.AADAuthenticationEndpoint)) { this.Endpoints.AADAuthUri = new Uri(connection[ConnectionStringFields.AADAuthenticationEndpoint]); } if (connection.ContainsKey(ConnectionStringFields.GraphUri)) { this.Endpoints.GraphUri = new Uri(connection[ConnectionStringFields.GraphUri]); } if (connection.ContainsKey(ConnectionStringFields.GalleryUri)) { this.Endpoints.GalleryUri = new Uri(connection[ConnectionStringFields.GalleryUri]); } if (connection.ContainsKey(ConnectionStringFields.IbizaPortalUri)) { this.Endpoints.IbizaPortalUri = new Uri(connection[ConnectionStringFields.IbizaPortalUri]); } if (connection.ContainsKey(ConnectionStringFields.RdfePortalUri)) { this.Endpoints.RdfePortalUri = new Uri(connection[ConnectionStringFields.RdfePortalUri]); } if (connection.ContainsKey(ConnectionStringFields.DataLakeStoreServiceUri)) { this.Endpoints.DataLakeStoreServiceUri = new Uri(connection[ConnectionStringFields.DataLakeStoreServiceUri]); } if (connection.ContainsKey(ConnectionStringFields.DataLakeAnalyticsJobAndCatalogServiceUri)) { this.Endpoints.DataLakeAnalyticsJobAndCatalogServiceUri = new Uri(connection[ConnectionStringFields.DataLakeAnalyticsJobAndCatalogServiceUri]); } RawParameters = connection; } }