Skip to content

Commit

Permalink
Adds support for managing SNS configuration - Push Notification - MFA…
Browse files Browse the repository at this point in the history
… policies (#775)
  • Loading branch information
kailash-b authored Jan 31, 2025
2 parents 3fe8993 + b303da0 commit 9162477
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 14 deletions.
85 changes: 78 additions & 7 deletions src/Auth0.ManagementApi/Clients/GuardianClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,7 @@ public Task<GuardianTwilioConfiguration> GetTwilioConfigurationAsync(
DefaultHeaders, cancellationToken: cancellationToken);
}

/// <summary>
/// Enable or Disable a Guardian factor.
/// </summary>
/// <param name="request">
/// The <see cref="UpdateGuardianFactorRequest" /> containing the details of the factor to update.</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>The <see cref="UpdateGuardianFactorResponse" /> indicating the status of the factor.</returns>
/// <inheritdoc />
public Task<UpdateGuardianFactorResponse> UpdateFactorAsync(
UpdateGuardianFactorRequest request, CancellationToken cancellationToken = default)
{
Expand Down Expand Up @@ -380,5 +374,82 @@ public Task<object> UpdatePushNotificationFcmV1ConfigurationAsync(FcmV1Configura
cancellationToken: cancellationToken
);
}

/// <inheritdoc />
public Task<GuardianSnsConfiguration> UpdatePushNotificationSnsConfigurationAsync(
GuardianSnsConfigurationPatchUpdateRequest request,
CancellationToken cancellationToken = default)
{
return Connection.SendAsync<GuardianSnsConfiguration>(
new HttpMethod("PATCH"),
BuildUri("guardian/factors/push-notification/providers/sns"),
request,
DefaultHeaders,
cancellationToken: cancellationToken
);
}

/// <inheritdoc />
public Task<GuardianSnsConfiguration> UpdatePushNotificationSnsConfigurationAsync(
GuardianSnsConfigurationPutUpdateRequest request,
CancellationToken cancellationToken = default)
{
return Connection.SendAsync<GuardianSnsConfiguration>(
HttpMethod.Put,
BuildUri("guardian/factors/push-notification/providers/sns"),
request,
DefaultHeaders,
cancellationToken: cancellationToken
);
}

/// <inheritdoc />
public Task<PushNotificationProviderConfiguration> GetPushNotificationProviderConfigurationAsync(
CancellationToken cancellationToken = default)
{
return Connection.GetAsync<PushNotificationProviderConfiguration>(
BuildUri("guardian/factors/push-notification/selected-provider"),
DefaultHeaders,
cancellationToken: cancellationToken
);
}

/// <inheritdoc />
public Task<PushNotificationProviderConfiguration> UpdatePushNotificationProviderConfigurationAsync(
PushNotificationProviderConfiguration pushNotificationProviderConfiguration,
CancellationToken cancellationToken = default)
{
return Connection.SendAsync<PushNotificationProviderConfiguration>(
HttpMethod.Put,
BuildUri("guardian/factors/push-notification/selected-provider"),
pushNotificationProviderConfiguration,
DefaultHeaders,
cancellationToken: cancellationToken
);
}

/// <inheritdoc />
public Task<string[]> GetMultifactorAuthenticationPolicies(CancellationToken cancellationToken = default)
{
return Connection.GetAsync<string[]>(
BuildUri("guardian/policies"),
DefaultHeaders,
cancellationToken: cancellationToken
);
}

/// <inheritdoc />
public Task<string[]> UpdateMultifactorAuthenticationPolicies(
string[] mfaPolicies,
CancellationToken cancellationToken = default)
{
return Connection.SendAsync<string[]>(
HttpMethod.Put,
BuildUri("guardian/policies"),
mfaPolicies,
DefaultHeaders,
cancellationToken: cancellationToken
);
}
}
}
62 changes: 61 additions & 1 deletion src/Auth0.ManagementApi/Clients/IGuardianClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public interface IGuardianClient
Task<GuardianTwilioConfiguration> GetTwilioConfigurationAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Enable or Disable a Guardian factor.
/// Update the status (i.e., enabled or disabled) of a specific multi-factor authentication factor.
/// </summary>
/// <param name="request">The <see cref="UpdateGuardianFactorRequest" /> containing the details of the factor to update.</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
Expand Down Expand Up @@ -236,5 +236,65 @@ Task<PushNotificationApnsConfigurationUpdateResponse> UpdatePushNotificationApns
/// <see cref="CancellationToken"/> The cancellation token to cancel operation.</param>
/// <returns>An <see cref="object"/> containing information about the FCMV1 configuration</returns>
Task<object> UpdatePushNotificationFcmV1ConfigurationAsync(FcmV1ConfigurationPutUpdateRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Configure the
/// <a href="https://auth0.com/docs/multifactor-authentication/developer/sns-configuration">
/// AWS SNS push notification provider configuration </a> (subscription required).
/// </summary>
/// <param name="request"><see cref="GuardianSnsConfigurationPatchUpdateRequest"/></param>
/// <param name="cancellationToken">
/// <see cref="CancellationToken"/> The cancellation token to cancel operation.</param>
/// <returns>A <see cref="GuardianSnsConfiguration"/> containing information about the SNS configuration</returns>
Task<GuardianSnsConfiguration> UpdatePushNotificationSnsConfigurationAsync(GuardianSnsConfigurationPatchUpdateRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Configure the
/// <a href="https://auth0.com/docs/multifactor-authentication/developer/sns-configuration">
/// AWS SNS push notification provider configuration </a> (subscription required).
/// </summary>
/// <param name="request"><see cref="GuardianSnsConfigurationPutUpdateRequest"/></param>
/// <param name="cancellationToken">
/// <see cref="CancellationToken"/> The cancellation token to cancel operation.</param>
/// <returns>A <see cref="GuardianSnsConfiguration"/> containing information about the SNS configuration</returns>
Task<GuardianSnsConfiguration> UpdatePushNotificationSnsConfigurationAsync(GuardianSnsConfigurationPutUpdateRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieve details of the push-notification providers configured for your tenant.
/// </summary>
/// <param name="cancellationToken">
/// <see cref="CancellationToken"/> The cancellation token to cancel operation.</param>
/// <returns><see cref="PushNotificationProviderConfiguration"/></returns>
Task<PushNotificationProviderConfiguration> GetPushNotificationProviderConfigurationAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Modify the push notification provider configured for your tenant. For more information, review
/// <a href="https://auth0.com/docs/secure/multi-factor-authentication/multi-factor-authentication-factors/configure-push-notifications-for-mfa">
/// Configure Push Notifications for MFA. </a>
/// </summary>
/// <param name="pushNotificationProviderConfiguration"><see cref="PushNotificationProviderConfiguration"/> - Containing the configuration information to be updated</param>
/// <param name="cancellationToken">
/// <see cref="CancellationToken"/> The cancellation token to cancel operation.</param>
/// <returns><see cref="PushNotificationProviderConfiguration"/></returns>
Task<PushNotificationProviderConfiguration> UpdatePushNotificationProviderConfigurationAsync(PushNotificationProviderConfiguration pushNotificationProviderConfiguration, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieve the
///<a href="https://auth0.com/docs/secure/multi-factor-authentication/enable-mfa">
/// multi-factor authentication (MFA) policies </a> configured for your tenant.
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns>MFA authentication policies configured for your tenant</returns>
Task<string[]> GetMultifactorAuthenticationPolicies(CancellationToken cancellationToken = default);

/// <summary>
/// Set the
/// <a href="https://auth0.com/docs/secure/multi-factor-authentication/enable-mfa">
/// multi-factor authentication (MFA) policies </a> for your tenant.
/// </summary>
/// <param name="mfaPolicies">MFA policies to update</param>
/// <param name="cancellationToken"></param>
/// <returns>MFA policies configured for your tenant</returns>
Task<string[]> UpdateMultifactorAuthenticationPolicies(string[] mfaPolicies, CancellationToken cancellationToken = default);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@ namespace Auth0.ManagementApi.Models
public class GuardianSnsConfiguration : GuardianSnsConfigurationBase
{
}

public class GuardianSnsConfigurationPutUpdateRequest : GuardianSnsConfigurationBase
{
}

public class GuardianSnsConfigurationPatchUpdateRequest : GuardianSnsConfigurationBase
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ public class PhoneProviderConfiguration
{
[JsonProperty("provider")]
[JsonConverter(typeof(StringEnumConverter))]
public Provider Provider { get; set; }
public PhoneProvider PhoneProvider { get; set; }
}

public enum Provider
public enum PhoneProvider
{
[EnumMember(Value = "auth0")]
Auth0,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Auth0.ManagementApi.Models
{
public class PushNotificationProviderConfiguration
{
[JsonProperty("provider")]
[JsonConverter(typeof(StringEnumConverter))]
public PushNotificationProvider PushNotificationProvider { get; set; }
}

public enum PushNotificationProvider
{
[EnumMember(Value = "guardian")]
Guardian,

[EnumMember(Value = "sns")]
Sns,

[EnumMember(Value = "direct")]
Direct,
}
}
55 changes: 51 additions & 4 deletions tests/Auth0.ManagementApi.IntegrationTests/GuardianTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,19 +274,19 @@ public async void Update_Get_PhoneProviderConfiguration_successfully()
{
var phoneProviderConfiguration = new PhoneProviderConfiguration()
{
Provider = Provider.Auth0,
PhoneProvider = PhoneProvider.Auth0,
};

// update phone provider configuration
var updatedProviderConfiguration =
await fixture.ApiClient.Guardian.UpdatePhoneProviderConfigurationAsync(phoneProviderConfiguration);
updatedProviderConfiguration.Should().NotBeNull();
updatedProviderConfiguration.Provider.Should().Be(Provider.Auth0);
updatedProviderConfiguration.PhoneProvider.Should().Be(PhoneProvider.Auth0);

// Get the Phone provider configuration explicitly
phoneProviderConfiguration = await fixture.ApiClient.Guardian.GetPhoneProviderConfigurationAsync();
phoneProviderConfiguration.Should().NotBeNull();
phoneProviderConfiguration.Provider.Should().Be(Provider.Auth0);
phoneProviderConfiguration.PhoneProvider.Should().Be(PhoneProvider.Auth0);
}

[Fact]
Expand Down Expand Up @@ -368,7 +368,7 @@ public async void Test_Update_Fcm_configuration_successfully()
ServerCredentials = "server_credentials"
};

var fcmV1ConfigurationPutUpdateRequest = new FcmV1ConfigurationPatchUpdateRequest()
var fcmV1ConfigurationPutUpdateRequest = new FcmV1ConfigurationPutUpdateRequest()
{
ServerCredentials = "server_credentials"
};
Expand All @@ -393,5 +393,52 @@ public async void Test_Update_Fcm_configuration_successfully()
await fixture.ApiClient.Guardian.UpdatePushNotificationFcmV1ConfigurationAsync(fcmV1ConfigurationPutUpdateRequest);
response.Should().NotBeNull();
}

[Fact]
public async void Update_Get_PushNotificationProviderConfiguration_successfully()
{
var pushNotificationProviderConfiguration = new PushNotificationProviderConfiguration()
{
PushNotificationProvider = PushNotificationProvider.Direct,
};

// update push notification provider configuration
var updatedProviderConfiguration =
await fixture.ApiClient.Guardian.UpdatePushNotificationProviderConfigurationAsync(
pushNotificationProviderConfiguration);

updatedProviderConfiguration.Should().NotBeNull();
updatedProviderConfiguration.PushNotificationProvider.Should().Be(PushNotificationProvider.Direct);

// Get the Push Notification provider configuration explicitly
pushNotificationProviderConfiguration =
await fixture.ApiClient.Guardian.GetPushNotificationProviderConfigurationAsync();
pushNotificationProviderConfiguration.Should().NotBeNull();
updatedProviderConfiguration.PushNotificationProvider.Should().Be(PushNotificationProvider.Direct);
}

[Fact]
public async void Update_Get_MultifactorAuthenticationPolicies_successfully()
{
try
{
// update MFA policy
var updatedMfaPolicy =
await fixture.ApiClient.Guardian.UpdateMultifactorAuthenticationPolicies(["all-applications"]);

updatedMfaPolicy.Should().NotBeNull();
updatedMfaPolicy.Should().BeEquivalentTo(["all-applications"]);

// Get the Push Notification provider configuration explicitly
var mfaPolicy =
await fixture.ApiClient.Guardian.GetMultifactorAuthenticationPolicies();
mfaPolicy.Should().NotBeNull();
mfaPolicy.Should().BeEquivalentTo(["all-applications"]);
}
finally
{
await fixture.ApiClient.Guardian.UpdateMultifactorAuthenticationPolicies([]);
}
}
}
}

0 comments on commit 9162477

Please sign in to comment.