diff --git a/src/Auth0.ManagementApi/Clients/PromptsClient.cs b/src/Auth0.ManagementApi/Clients/PromptsClient.cs new file mode 100644 index 000000000..a1d2317e2 --- /dev/null +++ b/src/Auth0.ManagementApi/Clients/PromptsClient.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; +using Auth0.ManagementApi.Models.Prompts; + +namespace Auth0.ManagementApi.Clients +{ + /// + /// Contains methods to access the /prompts endpoints. + /// + public class PromptsClient : BaseClient + { + private const string PromptsBasePath = "prompts"; + /// + /// Initializes a new instance on + /// + /// used to make all API calls. + /// of the endpoint to use in making API calls. + /// Dictionary containing default headers included with every request this client makes. + public PromptsClient(IManagementConnection connection, Uri baseUri, IDictionary defaultHeaders) + : base(connection, baseUri, defaultHeaders) + { + } + + /// + /// Get prompts settings + /// + /// + /// Get prompts settings + /// + /// The cancellation token to cancel operation. + /// A instance containing the information about the prompt settings. + public Task GetAsync(CancellationToken cancellationToken = default) + { + return Connection.GetAsync(BuildUri($"{PromptsBasePath}"), DefaultHeaders, cancellationToken: cancellationToken); + } + + /// + /// Update prompts settings. + /// + /// + /// Update prompts settings. + /// + /// Specifies prompt setting values that are to be updated. + /// The cancellation token to cancel operation. + /// The that was updated. + public Task UpdateAsync(PromptUpdateRequest request, CancellationToken cancellationToken = default) + { + return Connection.SendAsync(new HttpMethod("PATCH"), BuildUri($"{PromptsBasePath}"), request, DefaultHeaders, cancellationToken: cancellationToken); + } + } +} diff --git a/src/Auth0.ManagementApi/ManagementApiClient.cs b/src/Auth0.ManagementApi/ManagementApiClient.cs index 05fa064c9..60a2859f7 100644 --- a/src/Auth0.ManagementApi/ManagementApiClient.cs +++ b/src/Auth0.ManagementApi/ManagementApiClient.cs @@ -91,6 +91,11 @@ public class ManagementApiClient : IDisposable /// public OrganizationsClient Organizations { get; } + /// + /// Contains all the methods to call the /prompts endpoints. + /// + public PromptsClient Prompts { get; } + /// /// Contains all the methods to call the /resource-servers endpoints. /// @@ -171,6 +176,7 @@ public ManagementApiClient(string token, Uri baseUri, IManagementConnection mana Jobs = new JobsClient(managementConnection, baseUri, defaultHeaders); Logs = new LogsClient(managementConnection, baseUri, defaultHeaders); LogStreams = new LogStreamsClient(managementConnection, baseUri, defaultHeaders); + Prompts = new PromptsClient(managementConnection, baseUri, defaultHeaders); Organizations = new OrganizationsClient(managementConnection, baseUri, defaultHeaders); ResourceServers = new ResourceServersClient(managementConnection, baseUri, defaultHeaders); Roles = new RolesClient(managementConnection, baseUri, defaultHeaders); diff --git a/src/Auth0.ManagementApi/Models/Prompts/Prompt.cs b/src/Auth0.ManagementApi/Models/Prompts/Prompt.cs new file mode 100644 index 000000000..a062e6a5b --- /dev/null +++ b/src/Auth0.ManagementApi/Models/Prompts/Prompt.cs @@ -0,0 +1,28 @@ +using Newtonsoft.Json; + +namespace Auth0.ManagementApi.Models.Prompts +{ + /// + /// Represents Prompt Settings. + /// + public class Prompt + { + /// + /// Which login experience to use. Can be new or classic + /// + [JsonProperty("universal_login_experience")] + public string UniversalLoginExperience { get; set; } + + /// + /// Whether identifier first is enabled or not. + /// + [JsonProperty("identifier_first")] + public bool IdentifierFirst { get; set; } + + /// + /// Use WebAuthn with Device Biometrics as the first authentication factor + /// + [JsonProperty("webauthn_platform_first_factor")] + public bool WebAuthnPlatformFirstFactor { get; set; } + } +} diff --git a/src/Auth0.ManagementApi/Models/Prompts/PromptUpdateRequest.cs b/src/Auth0.ManagementApi/Models/Prompts/PromptUpdateRequest.cs new file mode 100644 index 000000000..08ae88602 --- /dev/null +++ b/src/Auth0.ManagementApi/Models/Prompts/PromptUpdateRequest.cs @@ -0,0 +1,9 @@ +namespace Auth0.ManagementApi.Models.Prompts +{ + /// + /// Request configuration for updating prompt settings. + /// + public class PromptUpdateRequest : Prompt + { + } +} diff --git a/tests/Auth0.ManagementApi.IntegrationTests/PromptsTests.cs b/tests/Auth0.ManagementApi.IntegrationTests/PromptsTests.cs new file mode 100644 index 000000000..963799733 --- /dev/null +++ b/tests/Auth0.ManagementApi.IntegrationTests/PromptsTests.cs @@ -0,0 +1,47 @@ +using Auth0.Tests.Shared; +using FluentAssertions; +using System.Threading.Tasks; +using Auth0.ManagementApi.Models.Prompts; +using Xunit; + +namespace Auth0.ManagementApi.IntegrationTests +{ + public class PromptsTests : TestBase, IAsyncLifetime + { + private ManagementApiClient _apiClient; + public async Task InitializeAsync() + { + string token = await GenerateManagementApiToken(); + + _apiClient = new ManagementApiClient(token, GetVariable("AUTH0_MANAGEMENT_API_URL"), new HttpClientManagementConnection(options: new HttpClientManagementConnectionOptions { NumberOfHttpRetries = 9 })); + } + + public Task DisposeAsync() + { + _apiClient.Dispose(); + return Task.CompletedTask; + } + + [Fact] + public async Task Test_get_and_update_prompts() + { + var prompts = await _apiClient.Prompts.GetAsync(); + prompts.Should().NotBeNull(); + + var originalExperience = prompts.UniversalLoginExperience; + var newExperience = originalExperience == "classic" ? "new" : "classic"; + + await _apiClient.Prompts.UpdateAsync(new PromptUpdateRequest {UniversalLoginExperience = newExperience }); + + prompts = await _apiClient.Prompts.GetAsync(); + prompts.Should().NotBeNull(); + prompts.UniversalLoginExperience.Should().Be(newExperience); + + await _apiClient.Prompts.UpdateAsync(new PromptUpdateRequest { UniversalLoginExperience = originalExperience }); + + prompts = await _apiClient.Prompts.GetAsync(); + prompts.Should().NotBeNull(); + prompts.UniversalLoginExperience.Should().Be(originalExperience); + } + } +}