/// <param name='resourceGroupName'> /// Required. The name of the resource group. /// </param> /// <param name='serviceName'> /// Required. The name of the Api Management service. /// </param> /// <param name='query'> /// Optional. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// List IdentityProvider operation response details. /// </returns> public async Task <IdentityProviderListResponse> ListAsync(string resourceGroupName, string serviceName, QueryParameters query, CancellationToken cancellationToken) { // Validate if (resourceGroupName == null) { throw new ArgumentNullException("resourceGroupName"); } if (serviceName == null) { throw new ArgumentNullException("serviceName"); } // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("resourceGroupName", resourceGroupName); tracingParameters.Add("serviceName", serviceName); tracingParameters.Add("query", query); TracingAdapter.Enter(invocationId, this, "ListAsync", tracingParameters); } // Construct URL string url = ""; url = url + "/subscriptions/"; if (this.Client.Credentials.SubscriptionId != null) { url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId); } url = url + "/resourceGroups/"; url = url + Uri.EscapeDataString(resourceGroupName); url = url + "/providers/"; url = url + "Microsoft.ApiManagement"; url = url + "/service/"; url = url + Uri.EscapeDataString(serviceName); url = url + "/identityProviders"; List <string> queryParameters = new List <string>(); queryParameters.Add("api-version=2016-10-10"); List <string> odataFilter = new List <string>(); if (query != null && query.Filter != null) { odataFilter.Add(Uri.EscapeDataString(query.Filter)); } if (odataFilter.Count > 0) { queryParameters.Add("$filter=" + string.Join(null, odataFilter)); } if (query != null && query.Top != null) { queryParameters.Add("$top=" + Uri.EscapeDataString(query.Top.Value.ToString())); } if (query != null && query.Skip != null) { queryParameters.Add("$skip=" + Uri.EscapeDataString(query.Skip.Value.ToString())); } if (queryParameters.Count > 0) { url = url + "?" + string.Join("&", queryParameters); } string baseUrl = this.Client.BaseUri.AbsoluteUri; // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl[baseUrl.Length - 1] == '/') { baseUrl = baseUrl.Substring(0, baseUrl.Length - 1); } if (url[0] == '/') { url = url.Substring(1); } url = baseUrl + "/" + url; url = url.Replace(" ", "%20"); // Create HTTP transport objects HttpRequestMessage httpRequest = null; try { httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Get; httpRequest.RequestUri = new Uri(url); // Set Headers // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Send Request HttpResponseMessage httpResponse = null; try { if (shouldTrace) { TracingAdapter.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { TracingAdapter.ReceiveResponse(invocationId, httpResponse); } HttpStatusCode statusCode = httpResponse.StatusCode; if (statusCode != HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { TracingAdapter.Error(invocationId, ex); } throw ex; } // Create Result IdentityProviderListResponse result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new IdentityProviderListResponse(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { JToken resultArray = responseDoc; if (resultArray != null && resultArray.Type != JTokenType.Null) { foreach (JToken resultValue in ((JArray)resultArray)) { IdentityProviderContract identityProviderContractInstance = new IdentityProviderContract(); result.Result.Add(identityProviderContractInstance); JToken typeValue = resultValue["type"]; if (typeValue != null && typeValue.Type != JTokenType.Null) { IdentityProviderTypeContract typeInstance = ApiManagementClient.ParseIdentityProviderTypeContract(((string)typeValue)); identityProviderContractInstance.Type = typeInstance; } JToken clientIdValue = resultValue["clientId"]; if (clientIdValue != null && clientIdValue.Type != JTokenType.Null) { string clientIdInstance = ((string)clientIdValue); identityProviderContractInstance.ClientId = clientIdInstance; } JToken clientSecretValue = resultValue["clientSecret"]; if (clientSecretValue != null && clientSecretValue.Type != JTokenType.Null) { string clientSecretInstance = ((string)clientSecretValue); identityProviderContractInstance.ClientSecret = clientSecretInstance; } JToken allowedTenantsArray = resultValue["allowedTenants"]; if (allowedTenantsArray != null && allowedTenantsArray.Type != JTokenType.Null) { foreach (JToken allowedTenantsValue in ((JArray)allowedTenantsArray)) { identityProviderContractInstance.AllowedTenants.Add(((string)allowedTenantsValue)); } } } } } } result.StatusCode = statusCode; if (httpResponse.Headers.Contains("x-ms-request-id")) { result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (shouldTrace) { TracingAdapter.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }
/// <summary> /// Creates or Updates the IdentityProvider configuration. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='serviceName'> /// The name of the API Management service. /// </param> /// <param name='identityProviderName'> /// Identity Provider Type identifier. Possible values include: 'facebook', /// 'google', 'microsoft', 'twitter', 'aad', 'aadB2C' /// </param> /// <param name='parameters'> /// Create parameters. /// </param> /// <param name='ifMatch'> /// ETag of the Entity. Not required when creating an entity, but required when /// updating an entity. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <IdentityProviderContract> CreateOrUpdateAsync(this IIdentityProviderOperations operations, string resourceGroupName, string serviceName, string identityProviderName, IdentityProviderContract parameters, string ifMatch = default(string), CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, serviceName, identityProviderName, parameters, ifMatch, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
public async Task CreateListUpdateDelete() { Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback"); using (MockContext context = MockContext.Start(this.GetType())) { var testBase = new ApiManagementTestBase(context); testBase.TryCreateApiManagementService(); try { // create facebook external identity provider string clientId = TestUtilities.GenerateName("clientId"); string clientSecret = TestUtilities.GenerateName("clientSecret"); var identityProviderCreateParameters = new IdentityProviderContract(clientId, clientSecret); var identityProviderContract = testBase.client.IdentityProvider.CreateOrUpdate( testBase.rgName, testBase.serviceName, IdentityProviderType.Facebook, identityProviderCreateParameters); Assert.NotNull(identityProviderContract); Assert.Equal(IdentityProviderType.Facebook, identityProviderContract.IdentityProviderContractType); Assert.NotNull(identityProviderContract.ClientId); Assert.NotNull(identityProviderContract.ClientSecret); Assert.Equal(clientId, identityProviderContract.ClientId); Assert.Equal(clientSecret, identityProviderContract.ClientSecret); Assert.Equal(IdentityProviderType.Facebook, identityProviderContract.IdentityProviderContractType); // list var listIdentityProviders = testBase.client.IdentityProvider.ListByService(testBase.rgName, testBase.serviceName); Assert.NotNull(listIdentityProviders); Assert.True(listIdentityProviders.GetEnumerator().ToIEnumerable().Count() >= 1); // get the entity tag var identityProviderTag = await testBase.client.IdentityProvider.GetEntityTagAsync( testBase.rgName, testBase.serviceName, IdentityProviderType.Facebook); Assert.NotNull(identityProviderTag); Assert.NotNull(identityProviderTag.ETag); // patch identity provider string patchedSecret = TestUtilities.GenerateName("clientSecret"); testBase.client.IdentityProvider.Update( testBase.rgName, testBase.serviceName, IdentityProviderType.Facebook, new IdentityProviderUpdateParameters { ClientSecret = patchedSecret }, identityProviderTag.ETag); // get to check it was patched identityProviderContract = await testBase.client.IdentityProvider.GetAsync( testBase.rgName, testBase.serviceName, IdentityProviderType.Facebook); Assert.NotNull(identityProviderContract); Assert.Equal(IdentityProviderType.Facebook, identityProviderContract.IdentityProviderContractType); Assert.Equal(patchedSecret, identityProviderContract.ClientSecret); Assert.Equal(clientId, identityProviderContract.ClientId); // get the tag again identityProviderTag = await testBase.client.IdentityProvider.GetEntityTagAsync( testBase.rgName, testBase.serviceName, IdentityProviderType.Facebook); // delete the identity provider testBase.client.IdentityProvider.Delete( testBase.rgName, testBase.serviceName, IdentityProviderType.Facebook, identityProviderTag.ETag); // get the deleted identity provider to make sure it was deleted try { testBase.client.IdentityProvider.Get(testBase.rgName, testBase.serviceName, IdentityProviderType.Facebook); throw new Exception("This code should not have been executed."); } catch (ErrorResponseException ex) { Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode); } } finally { testBase.client.IdentityProvider.Delete( testBase.rgName, testBase.serviceName, IdentityProviderType.Facebook, "*"); } } }
/// <summary> /// Creates or Updates the IdentityProvider configuration. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='serviceName'> /// The name of the API Management service. /// </param> /// <param name='identityProviderName'> /// Identity Provider Type identifier. Possible values include: 'facebook', /// 'google', 'microsoft', 'twitter', 'aad', 'aadB2C' /// </param> /// <param name='parameters'> /// Create parameters. /// </param> /// <param name='ifMatch'> /// ETag of the Entity. Not required when creating an entity, but required when /// updating an entity. /// </param> public static IdentityProviderContract CreateOrUpdate(this IIdentityProviderOperations operations, string resourceGroupName, string serviceName, string identityProviderName, IdentityProviderContract parameters, string ifMatch = default(string)) { return(operations.CreateOrUpdateAsync(resourceGroupName, serviceName, identityProviderName, parameters, ifMatch).GetAwaiter().GetResult()); }