Skip to content

Commit

Permalink
Add support to Update a Custom Domain
Browse files Browse the repository at this point in the history
  • Loading branch information
kailash-b committed Jan 15, 2025
1 parent 72e9295 commit a11bd86
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Auth0.ManagementApi/Clients/CustomDomainsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,11 @@ public Task<CustomDomainVerificationResponse> VerifyAsync(string id, Cancellatio
{
return Connection.SendAsync<CustomDomainVerificationResponse>(HttpMethod.Post, BuildUri($"custom-domains/{EncodePath(id)}/verify"), null, DefaultHeaders, cancellationToken: cancellationToken);
}

/// <inheritdoc />
public Task<CustomDomain> UpdateAsync(string id, CustomDomainUpdateRequest request, CancellationToken cancellationToken = default)
{
return Connection.SendAsync<CustomDomain>(new HttpMethod("PATCH"), BuildUri($"custom-domains/{EncodePath(id)}"), request, DefaultHeaders, cancellationToken: cancellationToken);
}
}
}
9 changes: 9 additions & 0 deletions src/Auth0.ManagementApi/Clients/ICustomDomainsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,14 @@ public interface ICustomDomainsClient
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>The <see cref="CustomDomainVerification"/> that was requested.</returns>
Task<CustomDomainVerificationResponse> VerifyAsync(string id, CancellationToken cancellationToken = default);

/// <summary>
/// Update a custom domain.
/// </summary>
/// <param name="id">The ID of the domain to update.</param>
/// <param name="request"><see cref="CustomDomainUpdateRequest"/></param>
/// <param name="cancellationToken"><see cref="CancellationToken"/></param>
/// <returns>Updated <see cref="CustomDomain"/></returns>
Task<CustomDomain> UpdateAsync(string id, CustomDomainUpdateRequest request, CancellationToken cancellationToken = default);
}
}
14 changes: 14 additions & 0 deletions src/Auth0.ManagementApi/Models/CustomDomain/CustomDomainBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,19 @@ public abstract class CustomDomainBase
/// </summary>
[JsonProperty("verification")]
public CustomDomainVerification Verification { get; set; }

/// <summary>
/// Possible values: [recommended, compatible]
/// recommended includes TLS 1.2
/// </summary>
[JsonProperty("tls_policy")]
public string TlsPolicy { get; set; }

/// <summary>
/// Possible values: [true-client-ip, cf-connecting-ip, x-forwarded-for, x-azure-clientip, null]
/// HTTP header to fetch client IP header. Ex: CF-Connecting-IP, X-Forwarded-For or True-Client-IP.
/// </summary>
[JsonProperty("custom_client_ip_header")]
public string CustomClientIpHeader { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,19 @@ public class CustomDomainCreateRequest
/// </summary>
[JsonProperty("verification_method")]
public string VerificationMethod { get; set; }

/// <summary>
/// Possible values: [recommended, compatible]
/// recommended includes TLS 1.2
/// </summary>
[JsonProperty("tls_policy")]
public string TlsPolicy { get; set; }

/// <summary>
/// Possible values: [true-client-ip, cf-connecting-ip, x-forwarded-for, x-azure-clientip, null]
/// HTTP header to fetch client IP header. Ex: CF-Connecting-IP, X-Forwarded-For or True-Client-IP.
/// </summary>
[JsonProperty("custom_client_ip_header")]
public string CustomClientIpHeader { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Newtonsoft.Json;

namespace Auth0.ManagementApi.Models
{
public class CustomDomainUpdateRequest
{
/// <summary>
/// Possible values: [recommended]
/// recommended includes TLS 1.2
/// </summary>
[JsonProperty("tls_policy")]
public string TlsPolicy { get; set; }

/// <summary>
/// Possible values: [true-client-ip, cf-connecting-ip, x-forwarded-for, x-azure-clientip, null]
/// HTTP header to fetch client IP header. Ex: CF-Connecting-IP, X-Forwarded-For or True-Client-IP.
/// </summary>
[JsonProperty("custom_client_ip_header")]
public string CustomClientIpHeader { get; set; }
}
}
12 changes: 12 additions & 0 deletions tests/Auth0.ManagementApi.IntegrationTests/CustomDomainsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ public async Task Test_custom_domains()
var domain = await apiClient.CustomDomains.GetAsync(id);
domain.Should().NotBeNull();
domain.CustomDomainId.Should().Be(id);

// Test updating a custom domain
var updateRequest = new CustomDomainUpdateRequest()
{
TlsPolicy = "recommended",
CustomClientIpHeader = null
};

var updatedCustomDomain = await apiClient.CustomDomains.UpdateAsync(id, updateRequest);
updatedCustomDomain.Should().NotBeNull();
updatedCustomDomain.CustomClientIpHeader.Should().Be(updateRequest.CustomClientIpHeader);
updatedCustomDomain.TlsPolicy.Should().Be(updateRequest.TlsPolicy);

string non_existent_id = "cd_XXw4P8C04x1Aa9e5";

Expand Down

0 comments on commit a11bd86

Please sign in to comment.