/// <summary> /// Updates the details of the authorization server specified by its /// identifier. /// </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='authsid'> /// Identifier of the authorization server. /// </param> /// <param name='parameters'> /// OAuth2 Server settings Update parameters. /// </param> /// <param name='ifMatch'> /// ETag of the Entity. ETag should match the current entity state from the /// header response of the GET request or it should be * for unconditional /// update. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task UpdateAsync(this IAuthorizationServerOperations operations, string resourceGroupName, string serviceName, string authsid, AuthorizationServerUpdateContract parameters, string ifMatch, CancellationToken cancellationToken = default(CancellationToken)) { (await operations.UpdateWithHttpMessagesAsync(resourceGroupName, serviceName, authsid, parameters, ifMatch, null, cancellationToken).ConfigureAwait(false)).Dispose(); }
public async Task CreateListUpdateDelete() { Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback"); using (MockContext context = MockContext.Start(this.GetType())) { var testBase = new ApiManagementTestBase(context); testBase.TryCreateApiManagementService(); // list all server var listResponse = testBase.client.AuthorizationServer.ListByService( testBase.rgName, testBase.serviceName, null); Assert.NotNull(listResponse); Assert.Empty(listResponse); // create server string authsid = TestUtilities.GenerateName("authsid"); try { var authorizationServerContract = new AuthorizationServerContract { DisplayName = TestUtilities.GenerateName("authName"), DefaultScope = TestUtilities.GenerateName("oauth2scope"), AuthorizationEndpoint = "https://contoso.com/auth", TokenEndpoint = "https://contoso.com/token", ClientRegistrationEndpoint = "https://contoso.com/clients/reg", GrantTypes = new List <string> { GrantType.AuthorizationCode, GrantType.Implicit, GrantType.ResourceOwnerPassword }, AuthorizationMethods = new List <AuthorizationMethod?> { AuthorizationMethod.POST, AuthorizationMethod.GET }, BearerTokenSendingMethods = new List <string> { BearerTokenSendingMethod.AuthorizationHeader, BearerTokenSendingMethod.Query }, ClientId = TestUtilities.GenerateName("clientid"), Description = TestUtilities.GenerateName("authdescription"), ClientAuthenticationMethod = new List <string> { ClientAuthenticationMethod.Basic }, ClientSecret = TestUtilities.GenerateName("authclientsecret"), ResourceOwnerPassword = TestUtilities.GenerateName("authresourceownerpwd"), ResourceOwnerUsername = TestUtilities.GenerateName("authresourceownerusername"), SupportState = true, TokenBodyParameters = new[] { new TokenBodyParameterContract { Name = TestUtilities.GenerateName("tokenname"), Value = TestUtilities.GenerateName("tokenvalue") } } }; var createResponse = testBase.client.AuthorizationServer.CreateOrUpdate( testBase.rgName, testBase.serviceName, authsid, authorizationServerContract); Assert.NotNull(createResponse); // get to check is was created var getResponse = await testBase.client.AuthorizationServer.GetWithHttpMessagesAsync( testBase.rgName, testBase.serviceName, authsid); Assert.NotNull(getResponse); Assert.NotNull(getResponse.Headers.ETag); Assert.NotNull(getResponse.Body); Assert.Equal(authsid, getResponse.Body.Name); Assert.Equal(authorizationServerContract.DisplayName, getResponse.Body.DisplayName); Assert.Equal(authorizationServerContract.Description, getResponse.Body.Description); Assert.Equal(authorizationServerContract.DefaultScope, getResponse.Body.DefaultScope); Assert.Equal(authorizationServerContract.AuthorizationEndpoint, getResponse.Body.AuthorizationEndpoint); Assert.Equal(authorizationServerContract.TokenEndpoint, getResponse.Body.TokenEndpoint); Assert.Equal(authorizationServerContract.ClientId, getResponse.Body.ClientId); Assert.Equal(authorizationServerContract.ClientRegistrationEndpoint, getResponse.Body.ClientRegistrationEndpoint); Assert.Equal(authorizationServerContract.ClientSecret, getResponse.Body.ClientSecret); Assert.Equal(authorizationServerContract.ResourceOwnerPassword, getResponse.Body.ResourceOwnerPassword); Assert.Equal(authorizationServerContract.ResourceOwnerUsername, getResponse.Body.ResourceOwnerUsername); Assert.Equal(authorizationServerContract.GrantTypes.Count, getResponse.Body.GrantTypes.Count); Assert.True(getResponse.Body.GrantTypes.All(gt => authorizationServerContract.GrantTypes.Contains(gt))); Assert.Equal(authorizationServerContract.AuthorizationMethods.Count, getResponse.Body.AuthorizationMethods.Count); Assert.True(getResponse.Body.AuthorizationMethods.All(gt => authorizationServerContract.AuthorizationMethods.Contains(gt))); Assert.Equal(authorizationServerContract.ClientAuthenticationMethod.Count, getResponse.Body.ClientAuthenticationMethod.Count); Assert.True(getResponse.Body.ClientAuthenticationMethod.All(gt => authorizationServerContract.ClientAuthenticationMethod.Contains(gt))); Assert.Equal(authorizationServerContract.SupportState, getResponse.Body.SupportState); Assert.Equal(authorizationServerContract.TokenBodyParameters.Count, getResponse.Body.TokenBodyParameters.Count); Assert.True(getResponse.Body.TokenBodyParameters.All(p => authorizationServerContract.TokenBodyParameters.Any(p1 => p1.Name.Equals(p.Name, StringComparison.OrdinalIgnoreCase) && p1.Value.Equals(p.Value, StringComparison.OrdinalIgnoreCase)))); // list again listResponse = testBase.client.AuthorizationServer.ListByService( testBase.rgName, testBase.serviceName, null); Assert.NotNull(listResponse); Assert.Single(listResponse); // update var updateParameters = new AuthorizationServerUpdateContract { GrantTypes = new List <string> { GrantType.AuthorizationCode, GrantType.ResourceOwnerPassword } }; testBase.client.AuthorizationServer.Update( testBase.rgName, testBase.serviceName, authsid, updateParameters, getResponse.Headers.ETag); // get to check is was updated getResponse = await testBase.client.AuthorizationServer.GetWithHttpMessagesAsync( testBase.rgName, testBase.serviceName, authsid); Assert.NotNull(getResponse); Assert.NotNull(getResponse.Headers.ETag); Assert.NotNull(getResponse.Body); Assert.Equal(authsid, getResponse.Body.Name); Assert.Equal(authorizationServerContract.DisplayName, getResponse.Body.DisplayName); Assert.Equal(authorizationServerContract.Description, getResponse.Body.Description); Assert.Equal(authorizationServerContract.DefaultScope, getResponse.Body.DefaultScope); Assert.Equal(authorizationServerContract.AuthorizationEndpoint, getResponse.Body.AuthorizationEndpoint); Assert.Equal(authorizationServerContract.TokenEndpoint, getResponse.Body.TokenEndpoint); Assert.Equal(authorizationServerContract.ClientId, getResponse.Body.ClientId); Assert.Equal(authorizationServerContract.ClientRegistrationEndpoint, getResponse.Body.ClientRegistrationEndpoint); Assert.Equal(authorizationServerContract.ClientSecret, getResponse.Body.ClientSecret); Assert.Equal(authorizationServerContract.ResourceOwnerPassword, getResponse.Body.ResourceOwnerPassword); Assert.Equal(authorizationServerContract.ResourceOwnerUsername, getResponse.Body.ResourceOwnerUsername); Assert.Equal(updateParameters.GrantTypes.Count, getResponse.Body.GrantTypes.Count); Assert.True(getResponse.Body.GrantTypes.All(gt => updateParameters.GrantTypes.Contains(gt))); Assert.Equal(authorizationServerContract.AuthorizationMethods.Count, getResponse.Body.AuthorizationMethods.Count); Assert.True(getResponse.Body.AuthorizationMethods.All(gt => authorizationServerContract.AuthorizationMethods.Contains(gt))); Assert.Equal(authorizationServerContract.ClientAuthenticationMethod.Count, getResponse.Body.ClientAuthenticationMethod.Count); Assert.True(getResponse.Body.ClientAuthenticationMethod.All(gt => authorizationServerContract.ClientAuthenticationMethod.Contains(gt))); Assert.Equal(authorizationServerContract.SupportState, getResponse.Body.SupportState); Assert.Equal(authorizationServerContract.TokenBodyParameters.Count, getResponse.Body.TokenBodyParameters.Count); Assert.True(getResponse.Body.TokenBodyParameters.All(p => authorizationServerContract.TokenBodyParameters.Any(p1 => p1.Name.Equals(p.Name, StringComparison.OrdinalIgnoreCase) && p1.Value.Equals(p.Value, StringComparison.OrdinalIgnoreCase)))); // delete testBase.client.AuthorizationServer.Delete( testBase.rgName, testBase.serviceName, authsid, getResponse.Headers.ETag); // get to check is was deleted try { testBase.client.AuthorizationServer.Get( testBase.rgName, testBase.serviceName, authsid); throw new Exception("This code should not have been executed."); } catch (ErrorResponseException ex) { Assert.Equal((int)HttpStatusCode.NotFound, (int)ex.Response.StatusCode); } } finally { // delete testBase.client.AuthorizationServer.Delete( testBase.rgName, testBase.serviceName, authsid, "*"); } } }
/// <summary> /// Updates the details of the authorization server specified by its /// identifier. /// </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='authsid'> /// Identifier of the authorization server. /// </param> /// <param name='parameters'> /// OAuth2 Server settings Update parameters. /// </param> /// <param name='ifMatch'> /// ETag of the Entity. ETag should match the current entity state from the /// header response of the GET request or it should be * for unconditional /// update. /// </param> public static void Update(this IAuthorizationServerOperations operations, string resourceGroupName, string serviceName, string authsid, AuthorizationServerUpdateContract parameters, string ifMatch) { operations.UpdateAsync(resourceGroupName, serviceName, authsid, parameters, ifMatch).GetAwaiter().GetResult(); }
/// <summary> /// Updates the details of the authorization server specified by its /// identifier. /// </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='authsid'> /// Identifier of the authorization server. /// </param> /// <param name='parameters'> /// OAuth2 Server settings Update parameters. /// </param> /// <param name='ifMatch'> /// ETag of the Entity. ETag should match the current entity state from the /// header response of the GET request or it should be * for unconditional /// update. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <AuthorizationServerContract> UpdateAsync(this IAuthorizationServerOperations operations, string resourceGroupName, string serviceName, string authsid, AuthorizationServerUpdateContract parameters, string ifMatch, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.UpdateWithHttpMessagesAsync(resourceGroupName, serviceName, authsid, parameters, ifMatch, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }