Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for listing authenticators and deleting specific authenticator #698

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
44 changes: 44 additions & 0 deletions src/Auth0.AuthenticationApi/AuthenticationApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,50 @@ public Task<PushedAuthorizationRequestResponse> PushedAuthorizationRequestAsync(
);
}

/// <inheritdoc/>
public Task DeleteMfaAuthenticatorAsync(
DeleteMfaAuthenticatorRequest request,
CancellationToken cancellationToken = default)
{
if (request == null)
{
throw new ArgumentNullException(nameof(request));
}

if (string.IsNullOrEmpty(request.AccessToken))
{
throw new InvalidOperationException($"{nameof(request.AccessToken)} is required");
}

if (string.IsNullOrEmpty(request.AuthenticatorId))
{
throw new InvalidOperationException($"{nameof(request.AuthenticatorId)} is required");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need to introduce this kind of validation here.Currently, we rely on the backend to tell us if something is missing, mainly because it isn't always clear what is and isnt required.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed this


return connection.SendAsync<object>(
HttpMethod.Delete,
BuildUri($"mfa/authenticators/{request.AuthenticatorId}"),
null,
headers: BuildHeaders(request.AccessToken),
cancellationToken: cancellationToken);
}

/// <inheritdoc/>
public Task<List<Authenticator>> ListAuthenticatorsAsync(string accessToken, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(accessToken))
{
throw new ArgumentNullException(nameof(accessToken));
}

return connection.SendAsync<List<Authenticator>>(
HttpMethod.Get,
BuildUri($"mfa/authenticators"),
null,
headers: BuildHeaders(accessToken),
cancellationToken: cancellationToken);
}

/// <summary>
/// Disposes of any owned disposable resources such as a <see cref="IAuthenticationConnection"/>.
/// </summary>
Expand Down
21 changes: 21 additions & 0 deletions src/Auth0.AuthenticationApi/IAuthenticationApiClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Auth0.AuthenticationApi.Models;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -180,5 +181,25 @@ public interface IAuthenticationApiClient : IDisposable
/// a <see cref="PushedAuthorizationRequestResponse" /> with the details of the response.</returns>
Task<PushedAuthorizationRequestResponse> PushedAuthorizationRequestAsync(PushedAuthorizationRequest request,
CancellationToken cancellationToken = default);

/// <summary>
/// Deletes an associated authenticator using its ID.
/// </summary>
/// <param name="request"><see cref="DeleteMfaAuthenticatorRequest"/> containing information to delete an associated authenticator</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns><see cref="Task"/> representing the async operation.</returns>
Task DeleteMfaAuthenticatorAsync(
DeleteMfaAuthenticatorRequest request,
CancellationToken cancellationToken = default);

/// <summary>
/// Lists authenticators associated with the access token
/// </summary>
/// <param name="accessToken"> Access token with scope: read:authenticators and audience: https://{yourDomain}/mfa/</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns><see cref="Task"/> representing the async operation containing
/// List of <see cref="Authenticator"/>
/// </returns>
Task<List<Authenticator>> ListAuthenticatorsAsync(string accessToken, CancellationToken cancellationToken = default);
}
}
22 changes: 22 additions & 0 deletions src/Auth0.AuthenticationApi/Models/Authenticator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Newtonsoft.Json;

namespace Auth0.AuthenticationApi.Models
{
public class Authenticator
{
[JsonProperty("id")]
public string Id { get; set; }

[JsonProperty("authenticator_type")]
public string AuthenticatorType { get; set; }

[JsonProperty("active")]
public bool Active { get; set; }

[JsonProperty("oob_channel")]
public string OobChannel { get; set; }

[JsonProperty("name")]
public string Name { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Auth0.AuthenticationApi.Models
{
public class DeleteMfaAuthenticatorRequest
{
/// <summary>
/// Access token with scope: remove:authenticators and audience: https://{yourDomain}/mfa/
/// </summary>
public string AccessToken { get; set; }

/// <summary>
/// The ID of the authenticator to delete.
/// </summary>
public string AuthenticatorId { get; set; }
}
}
45 changes: 45 additions & 0 deletions tests/Auth0.AuthenticationApi.IntegrationTests/MfaTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Linq;
using System.Threading.Tasks;
using Auth0.AuthenticationApi.Models;
using Auth0.Tests.Shared;
using FluentAssertions;
using Xunit;

namespace Auth0.AuthenticationApi.IntegrationTests
{
public class MfaTests : TestBase
{
public MfaTests()
{
_authenticationApiClient = new AuthenticationApiClient(GetVariable("AUTH0_AUTHENTICATION_API_URL"));
}

private readonly AuthenticationApiClient _authenticationApiClient;

[Fact(Skip = "Run manually")]
public async Task Invoking_Delete_ShouldNotThrow()
{
await _authenticationApiClient.Invoking(
x => x.DeleteMfaAuthenticatorAsync(
new DeleteMfaAuthenticatorRequest()
{
AccessToken = GetVariable("MFA_ACCESS_TOKEN"),
AuthenticatorId = GetVariable("AUTHENTICATOR_ID")
})).Should().NotThrowAsync();
}

[Fact(Skip = "Run manually")]
public async Task Should_Return_Authenticators()
{
var response = await _authenticationApiClient.ListAuthenticatorsAsync(
GetVariable("MFA_ACCESS_TOKEN")
);

response.Should().NotBeNullOrEmpty();
response.First().AuthenticatorType.Should().NotBeNullOrEmpty();
response.First().OobChannel.Should().NotBeNullOrEmpty();
response.First().Id.Should().NotBeNullOrEmpty();
response.First().Name.Should().NotBeNullOrEmpty();
}
}
}
Loading