Skip to content

Commit

Permalink
Add support for managing Branding Phone Provider settings (#780)
Browse files Browse the repository at this point in the history
  • Loading branch information
kailash-b authored Feb 6, 2025
2 parents 6bd109c + e6d4b7f commit 49a40a7
Show file tree
Hide file tree
Showing 10 changed files with 293 additions and 40 deletions.
104 changes: 76 additions & 28 deletions src/Auth0.ManagementApi/Clients/BrandingClient.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
using Auth0.ManagementApi.Models;

using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

using Newtonsoft.Json;

namespace Auth0.ManagementApi.Clients
{
/// <summary>
/// Contains methods to access the /branding endpoints.
/// </summary>
public class BrandingClient : BaseClient, IBrandingClient
{
private readonly JsonConverter[] _brandingPhoneProviderConverters =
{ new ListConverter<BrandingPhoneProvider>("providers") };

/// <summary>
/// Initializes a new instance of <see cref="BrandingClient"/>.
/// </summary>
Expand All @@ -23,42 +29,25 @@ public BrandingClient(IManagementConnection connection, Uri baseUri, IDictionary
{
}

/// <summary>
/// Retrieves branding settings for a tenant.
/// </summary>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>A <see cref="Branding"/> containing the branding for the tenant.</returns>
/// <inheritdoc />
public Task<Branding> GetAsync(CancellationToken cancellationToken = default)
{
return Connection.GetAsync<Branding>(BuildUri("branding"), DefaultHeaders, cancellationToken: cancellationToken);
}

/// <summary>s
/// Updates the branding for a tenant.
/// </summary>
/// <param name="request">A <see cref="BrandingUpdateRequest" /> containing the branding information to update.</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>The newly updated <see cref="Branding"/>.</returns>
/// <inheritdoc />
public Task<Branding> UpdateAsync(BrandingUpdateRequest request, CancellationToken cancellationToken = default)
{
return Connection.SendAsync<Branding>(new HttpMethod("PATCH"), BuildUri("branding"), request, DefaultHeaders, cancellationToken: cancellationToken);
}

/// <summary>
/// Retrieves the template for the New Universal Login Experience.
/// </summary>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>The <see cref="UniversalLoginTemplate"/> for the new universal login experience.</returns>
/// <inheritdoc />
public Task<UniversalLoginTemplate> GetUniversalLoginTemplateAsync(CancellationToken cancellationToken = default)
{
return Connection.GetAsync<UniversalLoginTemplate>(BuildUri("branding/templates/universal-login"), DefaultHeaders, cancellationToken: cancellationToken);
}

/// <summary>
/// Delete the template for the New Universal Login Experience
/// </summary>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous delete operation.</returns>
/// <inheritdoc />
public Task DeleteUniversalLoginTemplateAsync(CancellationToken cancellationToken = default)
{
return Connection
Expand All @@ -69,16 +58,75 @@ public Task DeleteUniversalLoginTemplateAsync(CancellationToken cancellationToke
DefaultHeaders,
cancellationToken: cancellationToken);
}

/// <summary>
/// Sets the template for the New Universal Login Experience.
/// </summary>
/// <param name="request">The <see cref="UniversalLoginTemplateUpdateRequest"/> containing details of the template to set.</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>The newly updated <see cref="UniversalLoginTemplate"/>.</returns>

/// <inheritdoc />
public Task<UniversalLoginTemplate> SetUniversalLoginTemplateAsync(UniversalLoginTemplateUpdateRequest request, CancellationToken cancellationToken = default)
{
return Connection.SendAsync<UniversalLoginTemplate>(HttpMethod.Put, BuildUri("branding/templates/universal-login"), request, DefaultHeaders, cancellationToken: cancellationToken);
}

/// <inheritdoc />
public Task<IList<BrandingPhoneProvider>> GetAllPhoneProvidersAsync(
BrandingPhoneProviderGetRequest request,
CancellationToken cancellationToken = default)
{
var queryStrings = new Dictionary<string, string>
{
{"disabled", request.Disabled?.ToString().ToLower()},
};
return Connection.GetAsync<IList<BrandingPhoneProvider>>(
BuildUri("branding/phone/providers", queryStrings),
DefaultHeaders,
cancellationToken: cancellationToken,
converters:_brandingPhoneProviderConverters);
}

/// <inheritdoc />
public Task<BrandingPhoneProvider> CreatePhoneProviderAsync(
BrandingPhoneProviderCreateRequest request,
CancellationToken cancellationToken = default)
{
return Connection.SendAsync<BrandingPhoneProvider>(
HttpMethod.Post,
BuildUri("branding/phone/providers"),
request,
DefaultHeaders,
cancellationToken: cancellationToken);
}

/// <inheritdoc />
public Task<BrandingPhoneProvider> GetPhoneProviderAsync(string id, CancellationToken cancellationToken = default)
{
return Connection.GetAsync<BrandingPhoneProvider>(
BuildUri($"branding/phone/providers/{EncodePath(id)}"),
DefaultHeaders,
cancellationToken: cancellationToken);
}

/// <inheritdoc />
public Task DeletePhoneProviderAsync(string id, CancellationToken cancellationToken = default)
{
return Connection
.SendAsync<object>(
HttpMethod.Delete,
BuildUri($"branding/phone/providers/{EncodePath(id)}"),
null,
DefaultHeaders,
cancellationToken: cancellationToken);
}

/// <inheritdoc />
public Task<BrandingPhoneProvider> UpdatePhoneProviderAsync(
string id,
BrandingPhoneProviderUpdateRequest request,
CancellationToken cancellationToken = default)
{
return Connection.SendAsync<BrandingPhoneProvider>(
new HttpMethod("PATCH"),
BuildUri($"branding/phone/providers/{EncodePath(id)}"),
request,
DefaultHeaders,
cancellationToken: cancellationToken);
}
}
}
54 changes: 53 additions & 1 deletion src/Auth0.ManagementApi/Clients/IBrandingClient.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Collections.Generic;

namespace Auth0.ManagementApi.Clients
{
using System.Threading;
Expand All @@ -7,7 +9,7 @@ namespace Auth0.ManagementApi.Clients
public interface IBrandingClient
{
/// <summary>
/// Retrieves branding settings for a tenant.
/// Retrieve branding settings.
/// </summary>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>A <see cref="Branding"/> containing the branding for the tenant.</returns>
Expand Down Expand Up @@ -42,5 +44,55 @@ public interface IBrandingClient
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>The newly updated <see cref="UniversalLoginTemplate"/>.</returns>
Task<UniversalLoginTemplate> SetUniversalLoginTemplateAsync(UniversalLoginTemplateUpdateRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieve a list of
/// <a href="https://auth0.com/docs/phone/providers"> phone providers </a>
/// details set for a Tenant. A list of fields to include or exclude may also be specified.
/// </summary>
/// <param name="request"><see cref="BrandingPhoneProviderGetRequest"/></param>
/// <param name="cancellationToken"></param>
/// <returns>List of <see cref="BrandingPhoneProvider"/>s</returns>
Task<IList<BrandingPhoneProvider> > GetAllPhoneProvidersAsync(BrandingPhoneProviderGetRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Create a
/// <a href="https://auth0.com/docs/phone/providers"> phone provider </a>.
/// The credentials object requires different properties depending on the phone provider
/// (which is specified using the name property).
/// </summary>
/// <param name="request"><see cref="BrandingPhoneProviderCreateRequest"/> containing information required to create a <see cref="BrandingPhoneProvider"/></param>
/// <param name="cancellationToken"><see cref="CancellationToken"/></param>
/// <returns>The newly created <see cref="BrandingPhoneProvider"/></returns>
Task<BrandingPhoneProvider> CreatePhoneProviderAsync(BrandingPhoneProviderCreateRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieve <a href="https://auth0.com/docs/phone/providers"> phone provider </a>details.
/// A list of fields to include or exclude may also be specified.
/// </summary>
/// <param name="id">ID of the <see cref="BrandingPhoneProvider"/> to be retrieved.</param>
/// <param name="cancellationToken"><see cref="CancellationToken"/></param>
/// <returns><see cref="BrandingPhoneProvider"/></returns>
Task<BrandingPhoneProvider> GetPhoneProviderAsync(string id, CancellationToken cancellationToken = default);

/// <summary>
/// Delete the configured phone provider.
/// </summary>
/// <param name="id">ID of the <see cref="BrandingPhoneProvider"/> to delete</param>
/// <param name="cancellationToken"><see cref="CancellationToken"/></param>
/// <returns></returns>
Task DeletePhoneProviderAsync(string id, CancellationToken cancellationToken = default);

/// <summary>
/// Update a
/// <a href="https://auth0.com/docs/phone/providers"> phone provider </a>.
/// The credentials object requires different properties depending on the email provider
/// (which is specified using the name property).
/// </summary>
/// <param name="id">ID of the <see cref="BrandingPhoneProvider"/> to update</param>
/// <param name="request">A <see cref="BrandingPhoneProviderUpdateRequest"/> containing the information to update</param>
/// <param name="cancellationToken"><see cref="CancellationToken"/></param>
/// <returns>Updated <see cref="BrandingPhoneProvider"/></returns>
Task<BrandingPhoneProvider> UpdatePhoneProviderAsync(string id, BrandingPhoneProviderUpdateRequest request, CancellationToken cancellationToken = default);
}
}
11 changes: 11 additions & 0 deletions src/Auth0.ManagementApi/Models/Branding/BrandingPhoneProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Newtonsoft.Json;

namespace Auth0.ManagementApi.Models
{
public class BrandingPhoneProvider : BrandingPhoneProviderBase
{
[JsonProperty("id")]
public string Id { get; set; }
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Newtonsoft.Json;

namespace Auth0.ManagementApi.Models
{
/// <summary>
/// Phone provider configuration schema
/// </summary>
public class BrandingPhoneProviderBase
{
/// <summary>
/// Name of the phone notification provider
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }

/// <summary>
/// Whether the provider is enabled (false) or disabled (true).
/// </summary>
[JsonProperty("disabled")]
public bool? Disabled { get; set; }

[JsonProperty("configuration")]
public dynamic Configuration { get; set; }
}

/// <summary>
/// Provider credentials required to use authenticate to the provider.
/// </summary>
public class BrandingCredential
{
[JsonProperty("auth_token")]
public string AuthToken { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Newtonsoft.Json;

namespace Auth0.ManagementApi.Models
{

public class BrandingPhoneProviderCreateRequest : BrandingPhoneProviderBase
{
[JsonProperty("credentials")]
public BrandingCredential Credentials { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Newtonsoft.Json;

namespace Auth0.ManagementApi.Models
{
public class BrandingPhoneProviderGetRequest
{
/// <summary>
/// Whether the provider is enabled (false) or disabled (true).
/// </summary>
[JsonProperty("disabled")]
public bool? Disabled { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Newtonsoft.Json;

namespace Auth0.ManagementApi.Models
{

public class BrandingPhoneProviderUpdateRequest : BrandingPhoneProviderBase
{
[JsonProperty("credentials")]
public BrandingCredential Credentials { get; set; }
}
}
Loading

0 comments on commit 49a40a7

Please sign in to comment.