Skip to content

Commit

Permalink
requested changes from PR
Browse files Browse the repository at this point in the history
  • Loading branch information
czf committed Jan 11, 2024
1 parent 39ef913 commit 841b2b2
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 50 deletions.
11 changes: 1 addition & 10 deletions src/Auth0.AuthenticationApi/AuthenticationApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -520,21 +520,12 @@ public Task<PushedAuthorizationRequestResponse> PushedAuthorizationRequestAsync(
}

/// <inheritdoc/>
public Task<AssociateNewAuthenticatorResponse> AssociateNewAuthenticatorAsync(AssociateNewAuthenticatorRequest request, CancellationToken cancellationToken = default)
public Task<AssociateNewAuthenticatorResponse> AssociateNewAuthenticatorAsync(AssociateMfaAuthenticatorRequest request, CancellationToken cancellationToken = default)
{
if (request == null)
{
throw new ArgumentNullException(nameof(request));
}
if (!request.IsValid(out List<string> validationErrors))
{
if (validationErrors.Count == 1)
{
throw new InvalidOperationException(validationErrors.First());
}

throw new InvalidOperationException(validationErrors.Aggregate((x, y) => x + "\n" + y));
}

return connection.SendAsync<AssociateNewAuthenticatorResponse>(
HttpMethod.Post,
Expand Down
4 changes: 2 additions & 2 deletions src/Auth0.AuthenticationApi/IAuthenticationApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ Task<PushedAuthorizationRequestResponse> PushedAuthorizationRequestAsync(PushedA
/// <summary>
/// Sends a Mfa enrollment request
/// </summary>
/// <param name="request"><see cref="AssociateNewAuthenticatorRequest"/>containing information to enroll a new Authenticator.</param>
/// <param name="request"><see cref="AssociateMfaAuthenticatorRequest"/>containing information to enroll a new Authenticator.</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns><see cref="Task"/> representing the async operation containing
/// a <see cref="AssociateNewAuthenticatorResponse" /> with the details of the response.</returns>
/// <returns></returns>
Task<AssociateNewAuthenticatorResponse> AssociateNewAuthenticatorAsync(
AssociateNewAuthenticatorRequest request,
AssociateMfaAuthenticatorRequest request,
CancellationToken cancellationToken = default);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Auth0.AuthenticationApi.Models
{
public class AssociateNewAuthenticatorRequest
public class AssociateMfaAuthenticatorRequest
{
[JsonIgnore]
public string Token { get; set; }
Expand Down Expand Up @@ -48,41 +48,5 @@ public class AssociateNewAuthenticatorRequest
/// <summary>The phone number to use for SMS or Voice. Required if oob_channels includes sms or voice.</summary>
[JsonProperty("phone_number")]
public string PhoneNumber { get; set; }

internal bool IsValid(out List<string> validationErrors)
{
validationErrors = new List<string>();
if (string.IsNullOrEmpty(Token))
{
validationErrors.Add($"{nameof(Token)} is required");
}

if (string.IsNullOrEmpty(ClientId))
{
validationErrors.Add($"{nameof(ClientId)} is required");
}

if (AuthenticatorTypes == null || AuthenticatorTypes.Count == 0)
{
validationErrors.Add($"{nameof(AuthenticatorTypes)} is required");
}
else if (AuthenticatorTypes.Contains("oob"))
{
if (OobChannels == null || OobChannels.Count == 0)
{
validationErrors.Add($"{nameof(OobChannels)} is required when {nameof(AuthenticatorTypes)} includes 'oob'");
}
else if (OobChannels.Any(x => x != "auth0" && x != "sms" && x != "voice"))
{
validationErrors.Add($"{nameof(OobChannels)} can only include 'auth0', 'sms', 'voice'");
}
else if (OobChannels.Any(x => x == "sms" || x == "voice") && string.IsNullOrEmpty(PhoneNumber))
{
validationErrors.Add($"{nameof(PhoneNumber)} is Required when {nameof(OobChannels)} includes 'sms' or 'voice'");
}
}

return validationErrors.Count == 0;
}
}
}
2 changes: 1 addition & 1 deletion tests/Auth0.AuthenticationApi.IntegrationTests/MfaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public MfaTests()
public async Task Should_Receive_Associate_Response_For_Sms_Mfa_Enrollment()
{
var request =
new AssociateNewAuthenticatorRequest()
new AssociateMfaAuthenticatorRequest()
{
Token = TestBaseUtils.GetVariable("AUTH0_AUTHENTICATOR_ENROLL_TOKEN"),
ClientId = TestBaseUtils.GetVariable("AUTH0_CLIENT_ID"),
Expand Down

0 comments on commit 841b2b2

Please sign in to comment.