Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Auth0.ManagementApi/Clients/CustomDomainsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,16 @@ public Task<CustomDomain> UpdateAsync(string id, CustomDomainUpdateRequest reque
{
return Connection.SendAsync<CustomDomain>(new HttpMethod("PATCH"), BuildUri($"custom-domains/{EncodePath(id)}"), request, DefaultHeaders, cancellationToken: cancellationToken);
}

/// <inheritdoc />
public Task<CustomDomain> GetDefaultAsync(CancellationToken cancellationToken = default)
{
return Connection.GetAsync<CustomDomain>(BuildUri("custom-domains/default"), DefaultHeaders, cancellationToken: cancellationToken);
}

/// <inheritdoc />
public Task<CustomDomain> SetDefaultAsync(CustomDomainSetDefaultRequest request, CancellationToken cancellationToken = default)
{
return Connection.SendAsync<CustomDomain>(new HttpMethod("PATCH"), BuildUri("custom-domains/default"), request, DefaultHeaders, cancellationToken: cancellationToken);
}
}
16 changes: 16 additions & 0 deletions src/Auth0.ManagementApi/Clients/ICustomDomainsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,20 @@ public interface ICustomDomainsClient
/// <param name="cancellationToken"><see cref="CancellationToken"/></param>
/// <returns>Updated <see cref="CustomDomain"/></returns>
Task<CustomDomain> UpdateAsync(string id, CustomDomainUpdateRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieves the default custom domain for the tenant.
/// Returns the custom domain marked as default, or the canonical domain if none is set.
/// </summary>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>The default <see cref="CustomDomain"/>.</returns>
Task<CustomDomain> GetDefaultAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Sets the default custom domain for the tenant.
/// </summary>
/// <param name="request">A <see cref="CustomDomainSetDefaultRequest"/> containing the domain to set as default.</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>The updated default <see cref="CustomDomain"/>.</returns>
Task<CustomDomain> SetDefaultAsync(CustomDomainSetDefaultRequest request, CancellationToken cancellationToken = default);
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,10 @@ public abstract class CustomDomainBase
/// </summary>
[JsonProperty("custom_client_ip_header")]
public string CustomClientIpHeader { get; set; }

/// <summary>
/// Whether this is the default custom domain for the tenant.
/// </summary>
[JsonProperty("is_default")]
public bool IsDefault { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Newtonsoft.Json;

namespace Auth0.ManagementApi.Models;

/// <summary>
/// Represents a request to set the default custom domain for a tenant.
/// </summary>
public class CustomDomainSetDefaultRequest
{
/// <summary>
/// The domain to set as default.
/// Must match a verified custom domain or the canonical domain.
/// </summary>
[JsonProperty("domain")]
public string Domain { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Auth0.ManagementApi.IntegrationTests.Testing;
using Auth0.ManagementApi.Models;
using Auth0.ManagementApi.Paging;
using System.Net.Http;

using FluentAssertions;
using Moq;
Expand Down Expand Up @@ -241,5 +242,79 @@ public async Task GetAllAsync_Passes_CheckpointConverters_To_Connection()
getConverters()[0].Should().BeAssignableTo<JsonConverter>();
getConverters()[0].CanConvert(typeof(ICheckpointPagedList<CustomDomain>)).Should().BeTrue();
}


/// <summary>
/// Sets up the mock to capture the HTTP method, URI, and body passed to SendAsync.
/// Returns holders whose values are populated after the call under test completes.
/// </summary>
private (Func<Uri> GetUri, Func<HttpMethod> GetMethod, Func<object> GetBody) SetupSendCapture(
CustomDomain response = null)
{
Uri capturedUri = null;
HttpMethod capturedMethod = null;
object capturedBody = null;

_mockConnection
.Setup(c => c.SendAsync<CustomDomain>(
It.IsAny<HttpMethod>(),
It.IsAny<Uri>(),
It.IsAny<object>(),
It.IsAny<IDictionary<string, string>>(),
It.IsAny<IList<FileUploadParameter>>(),
It.IsAny<JsonConverter[]>(),
It.IsAny<CancellationToken>()))
.Callback<HttpMethod, Uri, object, IDictionary<string, string>, IList<FileUploadParameter>, JsonConverter[], CancellationToken>(
(method, uri, body, _, _, _, _) =>
{
capturedMethod = method;
capturedUri = uri;
capturedBody = body;
})
.ReturnsAsync(response ?? new CustomDomain());

return (() => capturedUri, () => capturedMethod, () => capturedBody);
}

[Fact]
public async Task GetDefaultAsync_Calls_Correct_Endpoint()
{
Uri capturedUri = null;
_mockConnection
.Setup(c => c.GetAsync<CustomDomain>(
It.IsAny<Uri>(),
It.IsAny<IDictionary<string, string>>(),
It.IsAny<JsonConverter[]>(),
It.IsAny<CancellationToken>()))
.Callback<Uri, IDictionary<string, string>, JsonConverter[], CancellationToken>(
(uri, _, _, _) => capturedUri = uri)
.ReturnsAsync(new CustomDomain());

await _client.GetDefaultAsync();

capturedUri.AbsolutePath.Should().EndWith("custom-domains/default");
}

[Fact]
public async Task SetDefaultAsync_Calls_Correct_Endpoint_With_PATCH()
{
var (getUri, getMethod, _) = SetupSendCapture();

await _client.SetDefaultAsync(new CustomDomainSetDefaultRequest { Domain = "login.example.com" });

getUri().AbsolutePath.Should().EndWith("custom-domains/default");
getMethod().Method.Should().Be("PATCH");
}

[Fact]
public async Task SetDefaultAsync_Sends_Domain_In_Body()
{
var (_, _, getBody) = SetupSendCapture();

await _client.SetDefaultAsync(new CustomDomainSetDefaultRequest { Domain = "login.example.com" });

var body = getBody().Should().BeOfType<CustomDomainSetDefaultRequest>().Subject;
body.Domain.Should().Be("login.example.com");
}


}
Loading