-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Prompt Client to Management API SDK (#522)
Closes #518
- Loading branch information
1 parent
a2d6ebe
commit b77ad8f
Showing
5 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
{ | ||
/// <summary> | ||
/// Contains methods to access the /prompts endpoints. | ||
/// </summary> | ||
public class PromptsClient : BaseClient | ||
{ | ||
private const string PromptsBasePath = "prompts"; | ||
/// <summary> | ||
/// Initializes a new instance on <see cref="PromptsClient"/> | ||
/// </summary> | ||
/// <param name="connection"><see cref="IManagementConnection"/> used to make all API calls.</param> | ||
/// <param name="baseUri"><see cref="Uri"/> of the endpoint to use in making API calls.</param> | ||
/// <param name="defaultHeaders">Dictionary containing default headers included with every request this client makes.</param> | ||
public PromptsClient(IManagementConnection connection, Uri baseUri, IDictionary<string, string> defaultHeaders) | ||
: base(connection, baseUri, defaultHeaders) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Get prompts settings | ||
/// </summary> | ||
/// <remarks> | ||
/// Get prompts settings | ||
/// </remarks> | ||
/// <param name="cancellationToken">The cancellation token to cancel operation.</param> | ||
/// <returns>A <see cref="Prompt"/> instance containing the information about the prompt settings.</returns> | ||
public Task<Prompt> GetAsync(CancellationToken cancellationToken = default) | ||
{ | ||
return Connection.GetAsync<Prompt>(BuildUri($"{PromptsBasePath}"), DefaultHeaders, cancellationToken: cancellationToken); | ||
} | ||
|
||
/// <summary> | ||
/// Update prompts settings. | ||
/// </summary> | ||
/// <remarks> | ||
/// Update prompts settings. | ||
/// </remarks> | ||
/// <param name="request">Specifies prompt setting values that are to be updated.</param> | ||
/// <param name="cancellationToken">The cancellation token to cancel operation.</param> | ||
/// <returns>The <see cref="Prompt"/> that was updated.</returns> | ||
public Task<Prompt> UpdateAsync(PromptUpdateRequest request, CancellationToken cancellationToken = default) | ||
{ | ||
return Connection.SendAsync<Prompt>(new HttpMethod("PATCH"), BuildUri($"{PromptsBasePath}"), request, DefaultHeaders, cancellationToken: cancellationToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace Auth0.ManagementApi.Models.Prompts | ||
{ | ||
/// <summary> | ||
/// Represents Prompt Settings. | ||
/// </summary> | ||
public class Prompt | ||
{ | ||
/// <summary> | ||
/// Which login experience to use. Can be new or classic | ||
/// </summary> | ||
[JsonProperty("universal_login_experience")] | ||
public string UniversalLoginExperience { get; set; } | ||
|
||
/// <summary> | ||
/// Whether identifier first is enabled or not. | ||
/// </summary> | ||
[JsonProperty("identifier_first")] | ||
public bool IdentifierFirst { get; set; } | ||
|
||
/// <summary> | ||
/// Use WebAuthn with Device Biometrics as the first authentication factor | ||
/// </summary> | ||
[JsonProperty("webauthn_platform_first_factor")] | ||
public bool WebAuthnPlatformFirstFactor { get; set; } | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Auth0.ManagementApi/Models/Prompts/PromptUpdateRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Auth0.ManagementApi.Models.Prompts | ||
{ | ||
/// <summary> | ||
/// Request configuration for updating prompt settings. | ||
/// </summary> | ||
public class PromptUpdateRequest : Prompt | ||
{ | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
tests/Auth0.ManagementApi.IntegrationTests/PromptsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |