From 4116f3879f38b2c912acfba6e197b7917c78b459 Mon Sep 17 00:00:00 2001 From: kailash-b Date: Wed, 22 Jan 2025 10:12:02 +0530 Subject: [PATCH] Add support for /guardian end-points --- .../Clients/GuardianClient.cs | 264 +++++++++++++++--- .../Clients/IGuardianClient.cs | 155 +++++++++- .../CreateGuardianEnrollmentTicketRequest.cs | 6 + .../Models/Guardian/DuoConfiguration.cs | 16 ++ .../Guardian/DuoConfigurationUpdateRequest.cs | 12 + .../Models/Guardian/FcmConfiguration.cs | 18 ++ .../Models/Guardian/FcmV1Configuration.cs | 18 ++ .../Models/Guardian/GuardianFactor.cs | 4 +- .../GuardianPhoneEnrollmentTemplate.cs | 19 ++ .../Guardian/PhoneProviderConfiguration.cs | 25 ++ .../PushNotificationApnsConfiguration.cs | 25 ++ ...ationApnsConfigurationUpdateRequestBase.cs | 28 ++ .../GuardianTests.cs | 192 ++++++++++++- 13 files changed, 717 insertions(+), 65 deletions(-) create mode 100644 src/Auth0.ManagementApi/Models/Guardian/DuoConfiguration.cs create mode 100644 src/Auth0.ManagementApi/Models/Guardian/DuoConfigurationUpdateRequest.cs create mode 100644 src/Auth0.ManagementApi/Models/Guardian/FcmConfiguration.cs create mode 100644 src/Auth0.ManagementApi/Models/Guardian/FcmV1Configuration.cs create mode 100644 src/Auth0.ManagementApi/Models/Guardian/GuardianPhoneEnrollmentTemplate.cs create mode 100644 src/Auth0.ManagementApi/Models/Guardian/PhoneProviderConfiguration.cs create mode 100644 src/Auth0.ManagementApi/Models/Guardian/PushNotificationApnsConfiguration.cs create mode 100644 src/Auth0.ManagementApi/Models/Guardian/PushNotificationApnsConfigurationUpdateRequestBase.cs diff --git a/src/Auth0.ManagementApi/Clients/GuardianClient.cs b/src/Auth0.ManagementApi/Clients/GuardianClient.cs index 828d59fac..f35b97b21 100644 --- a/src/Auth0.ManagementApi/Clients/GuardianClient.cs +++ b/src/Auth0.ManagementApi/Clients/GuardianClient.cs @@ -1,10 +1,10 @@ -using Auth0.ManagementApi.Models; -using System; +using System; using System.Collections.Generic; using System.Net.Http; using System.Threading; using System.Threading.Tasks; -using Auth0.Core.Http; + +using Auth0.ManagementApi.Models; namespace Auth0.ManagementApi.Clients { @@ -25,14 +25,20 @@ public GuardianClient(IManagementConnection connection, Uri baseUri, IDictionary } /// - /// Generate an email with a link to start the Guardian enrollment process. + /// Create a + /// + /// multi-factor authentication (MFA) enrollment ticket , and optionally send an email with the created + /// ticket, to a given user. /// /// - /// The containing the information about the user who should be enrolled. + /// The containing the information about the user + /// who should be enrolled. /// /// The cancellation token to cancel operation. - /// A with the details of the ticket that was created. - public Task CreateEnrollmentTicketAsync(CreateGuardianEnrollmentTicketRequest request, CancellationToken cancellationToken = default) + /// A with the details of the ticket that + /// was created. + public Task CreateEnrollmentTicketAsync( + CreateGuardianEnrollmentTicketRequest request, CancellationToken cancellationToken = default) { return Connection .SendAsync( @@ -43,7 +49,10 @@ public Task CreateEnrollmentTicketAsync( } /// - /// Deletes an enrollment. + /// Remove a specific multi-factor authentication (MFA) enrollment from a user's account. + /// This allows the user to re-enroll with MFA. For more information, + /// review + /// Reset User Multi-Factor Authentication and Recovery Codes. /// /// The ID of the enrollment to delete. /// The cancellation token to cancel operation. @@ -55,11 +64,13 @@ public Task DeleteEnrollmentAsync(string id, CancellationToken cancellationToken HttpMethod.Delete, BuildUri($"guardian/enrollments/{EncodePath(id)}"), null, - DefaultHeaders, cancellationToken: cancellationToken); + DefaultHeaders, + cancellationToken: cancellationToken); } /// - /// Retrieves an enrollment. + /// Retrieve details, such as status and type, for a specific multi-factor authentication enrollment + /// registered to a user account. /// /// The ID of the enrollment to retrieve. /// The cancellation token to cancel operation. @@ -71,11 +82,8 @@ public Task GetEnrollmentAsync(string id, CancellationToken BuildUri($"guardian/enrollments/{EncodePath(id)}"), DefaultHeaders, cancellationToken: cancellationToken); } - - /// - /// Retrieves all factors. Useful to check factor enablement and trial status. - /// - /// List of instances with the available factors. + + /// public Task> GetFactorsAsync(CancellationToken cancellationToken = default) { return Connection @@ -108,11 +116,9 @@ public Task GetSnsConfigurationAsync(CancellationToken DefaultHeaders, cancellationToken: cancellationToken); } - /// - /// Returns configuration for the Guardian Twilio provider. - /// - /// with the Twilio configuration. - public Task GetTwilioConfigurationAsync(CancellationToken cancellationToken = default) + /// + public Task GetTwilioConfigurationAsync( + CancellationToken cancellationToken = default) { return Connection .GetAsync( @@ -123,10 +129,12 @@ public Task GetTwilioConfigurationAsync(Cancellatio /// /// Enable or Disable a Guardian factor. /// - /// The containing the details of the factor to update. + /// + /// The containing the details of the factor to update. /// The cancellation token to cancel operation. /// The indicating the status of the factor. - public Task UpdateFactorAsync(UpdateGuardianFactorRequest request, CancellationToken cancellationToken = default) + public Task UpdateFactorAsync( + UpdateGuardianFactorRequest request, CancellationToken cancellationToken = default) { var name = request.Factor.ToEnumString(); @@ -144,7 +152,8 @@ public Task UpdateFactorAsync(UpdateGuardianFactor /// A containing the updated templates. /// The cancellation token to cancel operation. /// A containing the templates. - public Task UpdateSmsTemplatesAsync(GuardianSmsEnrollmentTemplates templates, CancellationToken cancellationToken = default) + public Task UpdateSmsTemplatesAsync( + GuardianSmsEnrollmentTemplates templates, CancellationToken cancellationToken = default) { return Connection .SendAsync( @@ -154,15 +163,9 @@ public Task UpdateSmsTemplatesAsync(GuardianSmsE DefaultHeaders, cancellationToken: cancellationToken); } - /// - /// Configure the Guardian Twilio provider. - /// - /// - /// The containing the configuration settings. - /// - /// The cancellation token to cancel operation. - /// The containing the updated configuration settings. - public Task UpdateTwilioConfigurationAsync(UpdateGuardianTwilioConfigurationRequest request, CancellationToken cancellationToken = default) + /// + public Task UpdateTwilioConfigurationAsync( + UpdateGuardianTwilioConfigurationRequest request, CancellationToken cancellationToken = default) { return Connection .SendAsync( @@ -172,11 +175,7 @@ public Task UpdateTwilioConfigurationAsync(UpdateGu DefaultHeaders, cancellationToken: cancellationToken); } - /// - /// Retrieve the enabled phone factors for multi-factor authentication - /// - /// The cancellation token to cancel operation. - /// A containing the message types. + /// public Task GetPhoneMessageTypesAsync(CancellationToken cancellationToken = default) { return Connection @@ -187,13 +186,9 @@ public Task GetPhoneMessageTypesAsync(CancellationTok ); } - /// - /// Update enabled phone factors for multi-factor authentication - /// - /// A containing the list of phone factors to enable on the tenan. - /// The cancellation token to cancel operation. - /// A containing the message types. - public Task UpdatePhoneMessageTypesAsync(GuardianPhoneMessageTypes messageTypes, CancellationToken cancellationToken = default) + /// + public Task UpdatePhoneMessageTypesAsync( + GuardianPhoneMessageTypes messageTypes, CancellationToken cancellationToken = default) { return Connection .SendAsync( @@ -204,5 +199,186 @@ public Task UpdatePhoneMessageTypesAsync(GuardianPhon cancellationToken: cancellationToken ); } + + /// + public Task GetDuoConfigurationAsync(CancellationToken cancellationToken = default) + { + return Connection.GetAsync( + BuildUri("guardian/factors/duo/settings"), + DefaultHeaders, + cancellationToken: cancellationToken + ); + } + + /// + public Task UpdateDuoConfigurationAsync( + DuoConfigurationPatchRequest configuration, + CancellationToken cancellationToken = default) + { + return Connection + .SendAsync( + new HttpMethod("PATCH"), + BuildUri("guardian/factors/duo/settings"), + configuration, + DefaultHeaders, + cancellationToken: cancellationToken); + } + + /// + public Task UpdateDuoConfigurationAsync( + DuoConfigurationPutRequest configuration, + CancellationToken cancellationToken = default) + { + return Connection.SendAsync( + HttpMethod.Put, + BuildUri("guardian/factors/duo/settings"), + configuration, + DefaultHeaders, + cancellationToken: cancellationToken + ); + } + + /// + public Task GetPhoneProviderConfigurationAsync( + CancellationToken cancellationToken = default) + { + return Connection.GetAsync( + BuildUri("guardian/factors/phone/selected-provider"), + DefaultHeaders, + cancellationToken: cancellationToken + ); + } + + /// + public Task UpdatePhoneProviderConfigurationAsync( + PhoneProviderConfiguration phoneProviderConfiguraiton, + CancellationToken cancellationToken = default) + { + return Connection.SendAsync( + HttpMethod.Put, + BuildUri("guardian/factors/phone/selected-provider"), + phoneProviderConfiguraiton, + DefaultHeaders, + cancellationToken: cancellationToken + ); + } + + /// + public Task GetPhoneEnrollmentTemplateAsync( + CancellationToken cancellationToken = default) + { + return Connection.GetAsync( + BuildUri("guardian/factors/phone/templates"), + DefaultHeaders, + cancellationToken: cancellationToken + ); + } + + /// + public Task UpdatePhoneEnrollmentTemplateAsync( + GuardianPhoneEnrollmentTemplate phoneEnrollmentTemplate, + CancellationToken cancellationToken = default) + { + return Connection.SendAsync( + HttpMethod.Put, + BuildUri("guardian/factors/phone/templates"), + phoneEnrollmentTemplate, + DefaultHeaders, + cancellationToken: cancellationToken + ); + } + + /// + public Task GetPushNotificationApnsProviderConfigurationAsync( + CancellationToken cancellationToken = default) + { + return Connection.GetAsync( + BuildUri("guardian/factors/push-notification/providers/apns"), + DefaultHeaders, + cancellationToken: cancellationToken + ); + } + + /// + public Task UpdatePushNotificationApnsProviderConfigurationAsync( + PushNotificationApnsConfigurationPutUpdateRequest request, + CancellationToken cancellationToken = default) + { + return Connection.SendAsync( + HttpMethod.Put, + BuildUri("guardian/factors/push-notification/providers/apns"), + request, + DefaultHeaders, + cancellationToken: cancellationToken + ); + } + + /// + public Task UpdatePushNotificationApnsProviderConfigurationAsync( + PushNotificationApnsConfigurationPatchUpdateRequest request, + CancellationToken cancellationToken = default) + { + return Connection.SendAsync( + new HttpMethod("PATCH"), + BuildUri("guardian/factors/push-notification/providers/apns"), + request, + DefaultHeaders, + cancellationToken: cancellationToken + ); + } + + /// + public Task UpdatePushNotificationFcmConfigurationAsync( + FcmConfigurationPatchUpdateRequest request, + CancellationToken cancellationToken = default) + { + return Connection.SendAsync( + new HttpMethod("PATCH"), + BuildUri("guardian/factors/push-notification/providers/fcm"), + request, + DefaultHeaders, + cancellationToken: cancellationToken + ); + } + + /// + public Task UpdatePushNotificationFcmConfigurationAsync( + FcmConfigurationPutUpdateRequest request, + CancellationToken cancellationToken = default) + { + return Connection.SendAsync( + HttpMethod.Put, + BuildUri("guardian/factors/push-notification/providers/fcm"), + request, + DefaultHeaders, + cancellationToken: cancellationToken + ); + } + + /// + public Task UpdatePushNotificationFcmV1ConfigurationAsync(FcmV1ConfigurationPatchUpdateRequest request, + CancellationToken cancellationToken = default) + { + return Connection.SendAsync( + new HttpMethod("PATCH"), + BuildUri("guardian/factors/push-notification/providers/fcmv1"), + request, + DefaultHeaders, + cancellationToken: cancellationToken + ); + } + + /// + public Task UpdatePushNotificationFcmV1ConfigurationAsync(FcmV1ConfigurationPutUpdateRequest request, + CancellationToken cancellationToken = default) + { + return Connection.SendAsync( + HttpMethod.Put, + BuildUri("guardian/factors/push-notification/providers/fcmv1"), + request, + DefaultHeaders, + cancellationToken: cancellationToken + ); + } } } diff --git a/src/Auth0.ManagementApi/Clients/IGuardianClient.cs b/src/Auth0.ManagementApi/Clients/IGuardianClient.cs index 85e9d681f..39b9ed5e7 100644 --- a/src/Auth0.ManagementApi/Clients/IGuardianClient.cs +++ b/src/Auth0.ManagementApi/Clients/IGuardianClient.cs @@ -34,7 +34,9 @@ public interface IGuardianClient Task GetEnrollmentAsync(string id, CancellationToken cancellationToken = default); /// - /// Retrieves all factors. Useful to check factor enablement and trial status. + /// Retrieve details of all + /// + /// multi-factor authentication factors associated with your tenant . /// /// List of instances with the available factors. Task> GetFactorsAsync(CancellationToken cancellationToken = default); @@ -52,7 +54,10 @@ public interface IGuardianClient Task GetSnsConfigurationAsync(CancellationToken cancellationToken = default); /// - /// Returns configuration for the Guardian Twilio provider. + /// Retrieve configuration details for a Twilio phone provider that has been set up in your tenant. + /// To learn more, review + /// + /// Configure SMS and Voice Notifications for MFA. /// /// with the Twilio configuration. Task GetTwilioConfigurationAsync(CancellationToken cancellationToken = default); @@ -74,28 +79,162 @@ public interface IGuardianClient Task UpdateSmsTemplatesAsync(GuardianSmsEnrollmentTemplates templates, CancellationToken cancellationToken = default); /// - /// Configure the Guardian Twilio provider. + /// Update the configuration of a Twilio phone provider that has been set up in your tenant. + /// To learn more, review + /// + /// Configure SMS and Voice Notifications for MFA. /// /// /// The containing the configuration settings. /// - /// The cancellation token to cancel operation. + /// - The cancellation token to cancel operation. /// The containing the updated configuration settings. Task UpdateTwilioConfigurationAsync(UpdateGuardianTwilioConfigurationRequest request, CancellationToken cancellationToken = default); /// - /// Retrieve the enabled phone factors for multi-factor authentication + /// Retrieve list of + /// + /// phone-type MFA factors (i.e., sms and voice) that are enabled for your tenant. /// /// The cancellation token to cancel operation. /// A containing the message types. Task GetPhoneMessageTypesAsync(CancellationToken cancellationToken = default); /// - /// Update enabled phone factors for multi-factor authentication + /// Replace the list of + /// + /// phone-type MFA factors (i.e., sms and voice) that are enabled for your tenant. /// - /// A containing the list of phone factors to enable on the tenan. - /// The cancellation token to cancel operation. + /// A containing the list of phone factors to enable on the tenant. + /// The cancellation token to cancel operation. /// A containing the message types. Task UpdatePhoneMessageTypesAsync(GuardianPhoneMessageTypes messageTypes, CancellationToken cancellationToken = default); + + /// + /// Retrieves the DUO account and factor configuration. + /// + /// + /// The cancellation token to cancel operation. + /// A containing the Duo configuration + Task GetDuoConfigurationAsync(CancellationToken cancellationToken = default); + + /// + /// Update the DUO Configuration using PATCH + /// + /// + /// + /// The cancellation token to cancel operation. + /// containing the updated configuration + Task UpdateDuoConfigurationAsync( + DuoConfigurationPatchRequest configuration, CancellationToken cancellationToken = default); + + /// + /// Update the DUO Configuration using PUT + /// + /// + /// + /// The cancellation token to cancel operation. + /// containing the updated configuration + Task UpdateDuoConfigurationAsync( + DuoConfigurationPutRequest configuration, CancellationToken cancellationToken = default); + + /// + /// Retrieve details of the multi-factor authentication phone provider configured for your tenant. + /// + /// + /// The cancellation token to cancel operation. + /// + Task GetPhoneProviderConfigurationAsync(CancellationToken cancellationToken = default); + + /// + /// Update Phone provider configuration. + /// + /// - Containing the configuration information to be updated + /// + /// The cancellation token to cancel operation. + /// + Task UpdatePhoneProviderConfigurationAsync(PhoneProviderConfiguration phoneProviderConfiguraiton, CancellationToken cancellationToken = default); + + /// + /// Retrieve details of the multi-factor authentication enrollment and verification templates for + /// phone-type factors available in your tenant. + /// + /// + /// The cancellation token to cancel operation. + /// A containing the templates. + Task GetPhoneEnrollmentTemplateAsync(CancellationToken cancellationToken = default); + + /// + /// Customize the messages sent to complete phone enrollment and verification (subscription required). + /// + /// A containing the template to be udpated. + /// + /// The cancellation token to cancel operation. + /// A containing the templates. + Task UpdatePhoneEnrollmentTemplateAsync(GuardianPhoneEnrollmentTemplate phoneEnrollmentTemplate, CancellationToken cancellationToken = default); + + /// + /// Retrieve configuration details for the multi-factor authentication APNS provider associated with your tenant. + /// + /// + /// The cancellation token to cancel operation. + /// A containing the details regarding APNS Push Notification Provider configuration. + Task GetPushNotificationApnsProviderConfigurationAsync(CancellationToken cancellationToken = default); + + /// + /// Overwrite all configuration details of the multi-factor authentication APNS provider associated with your tenant. + /// + /// + /// + /// The cancellation token to cancel operation. + /// A + Task UpdatePushNotificationApnsProviderConfigurationAsync( + PushNotificationApnsConfigurationPutUpdateRequest request, CancellationToken cancellationToken = default); + + /// + /// Modify configuration details of the multi-factor authentication APNS provider associated with your tenant. + /// + /// + /// + /// The cancellation token to cancel operation. + /// A + Task UpdatePushNotificationApnsProviderConfigurationAsync( + PushNotificationApnsConfigurationPatchUpdateRequest request, CancellationToken cancellationToken = default); + + /// + /// Modify configuration details of the multi-factor authentication FCM provider associated with your tenant. + /// + /// + /// + /// The cancellation token to cancel operation. + /// An containing information about the FCM configuration + Task UpdatePushNotificationFcmConfigurationAsync(FcmConfigurationPatchUpdateRequest request, CancellationToken cancellationToken = default); + + /// + /// Overwrite all configuration details of the multi-factor authentication FCM provider associated with your tenant. + /// + /// + /// + /// The cancellation token to cancel operation. + /// + Task UpdatePushNotificationFcmConfigurationAsync(FcmConfigurationPutUpdateRequest request, CancellationToken cancellationToken = default); + + /// + /// Modify configuration details of the multi-factor authentication FCMV1 provider associated with your tenant. + /// + /// + /// + /// The cancellation token to cancel operation. + /// An containing information about the FCMV1 configuration + Task UpdatePushNotificationFcmV1ConfigurationAsync(FcmV1ConfigurationPatchUpdateRequest request, CancellationToken cancellationToken = default); + + /// + /// Overwrite all configuration details of the multi-factor authentication FCMV1 provider associated with your tenant. + /// + /// + /// + /// The cancellation token to cancel operation. + /// An containing information about the FCMV1 configuration + Task UpdatePushNotificationFcmV1ConfigurationAsync(FcmV1ConfigurationPutUpdateRequest request, CancellationToken cancellationToken = default); } } diff --git a/src/Auth0.ManagementApi/Models/Guardian/CreateGuardianEnrollmentTicketRequest.cs b/src/Auth0.ManagementApi/Models/Guardian/CreateGuardianEnrollmentTicketRequest.cs index a9c83b693..1b73099d1 100644 --- a/src/Auth0.ManagementApi/Models/Guardian/CreateGuardianEnrollmentTicketRequest.cs +++ b/src/Auth0.ManagementApi/Models/Guardian/CreateGuardianEnrollmentTicketRequest.cs @@ -22,5 +22,11 @@ public class CreateGuardianEnrollmentTicketRequest /// [JsonProperty("user_id")] public string UserId { get; set; } + + /// + /// Optional. Specify the locale of the enrollment email. Used with send_email. + /// + [JsonProperty("email_locale")] + public string EmailLocale { get; set; } } } \ No newline at end of file diff --git a/src/Auth0.ManagementApi/Models/Guardian/DuoConfiguration.cs b/src/Auth0.ManagementApi/Models/Guardian/DuoConfiguration.cs new file mode 100644 index 000000000..545971c77 --- /dev/null +++ b/src/Auth0.ManagementApi/Models/Guardian/DuoConfiguration.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Auth0.ManagementApi.Models +{ + public class DuoConfiguration + { + [JsonProperty("ikey")] + public string Ikey { get; set; } + + [JsonProperty("skey")] + public string Skey { get; set; } + + [JsonProperty("host")] + public string Host { get; set; } + } +} \ No newline at end of file diff --git a/src/Auth0.ManagementApi/Models/Guardian/DuoConfigurationUpdateRequest.cs b/src/Auth0.ManagementApi/Models/Guardian/DuoConfigurationUpdateRequest.cs new file mode 100644 index 000000000..0365cbca8 --- /dev/null +++ b/src/Auth0.ManagementApi/Models/Guardian/DuoConfigurationUpdateRequest.cs @@ -0,0 +1,12 @@ +namespace Auth0.ManagementApi.Models +{ + public class DuoConfigurationPatchRequest : DuoConfiguration + { + + } + + public class DuoConfigurationPutRequest : DuoConfiguration + { + + } +} \ No newline at end of file diff --git a/src/Auth0.ManagementApi/Models/Guardian/FcmConfiguration.cs b/src/Auth0.ManagementApi/Models/Guardian/FcmConfiguration.cs new file mode 100644 index 000000000..906c954dc --- /dev/null +++ b/src/Auth0.ManagementApi/Models/Guardian/FcmConfiguration.cs @@ -0,0 +1,18 @@ +using Newtonsoft.Json; + +namespace Auth0.ManagementApi.Models +{ + public class FcmConfigurationUpdateRequestBase + { + [JsonProperty("server_key")] + public string ServerKey { get; set; } + } + + public class FcmConfigurationPatchUpdateRequest : FcmConfigurationUpdateRequestBase + { + } + + public class FcmConfigurationPutUpdateRequest : FcmConfigurationUpdateRequestBase + { + } +} \ No newline at end of file diff --git a/src/Auth0.ManagementApi/Models/Guardian/FcmV1Configuration.cs b/src/Auth0.ManagementApi/Models/Guardian/FcmV1Configuration.cs new file mode 100644 index 000000000..766680ef0 --- /dev/null +++ b/src/Auth0.ManagementApi/Models/Guardian/FcmV1Configuration.cs @@ -0,0 +1,18 @@ +using Newtonsoft.Json; + +namespace Auth0.ManagementApi.Models +{ + public class FcmV1ConfigurationUpdateRequestBase + { + [JsonProperty("server_credentials")] + public string ServerCredentials { get; set; } + } + + public class FcmV1ConfigurationPatchUpdateRequest : FcmV1ConfigurationUpdateRequestBase + { + } + + public class FcmV1ConfigurationPutUpdateRequest : FcmV1ConfigurationUpdateRequestBase + { + } +} \ No newline at end of file diff --git a/src/Auth0.ManagementApi/Models/Guardian/GuardianFactor.cs b/src/Auth0.ManagementApi/Models/Guardian/GuardianFactor.cs index 8a1011dc7..a887d146e 100644 --- a/src/Auth0.ManagementApi/Models/Guardian/GuardianFactor.cs +++ b/src/Auth0.ManagementApi/Models/Guardian/GuardianFactor.cs @@ -8,7 +8,7 @@ namespace Auth0.ManagementApi.Models public class GuardianFactor { /// - /// States if this factor is enabled. + /// Whether this factor is enabled (true) or disabled (false). /// [JsonProperty("enabled")] public bool Enabled { get; set; } @@ -21,7 +21,7 @@ public class GuardianFactor public GuardianFactorName? Name { get; set; } /// - /// For factors with trial limits (e.g. SMS) states if those limits have been exceeded. + /// Whether trial limits have been exceeded. /// [JsonProperty("trial_expired")] public bool? IsTrialExpired { get; set; } diff --git a/src/Auth0.ManagementApi/Models/Guardian/GuardianPhoneEnrollmentTemplate.cs b/src/Auth0.ManagementApi/Models/Guardian/GuardianPhoneEnrollmentTemplate.cs new file mode 100644 index 000000000..e09303c56 --- /dev/null +++ b/src/Auth0.ManagementApi/Models/Guardian/GuardianPhoneEnrollmentTemplate.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; + +namespace Auth0.ManagementApi.Models +{ + public class GuardianPhoneEnrollmentTemplate + { + /// + /// Message sent to the user when they are invited to enroll with a phone number. + /// + [JsonProperty("enrollment_message")] + public string EnrollmentMessage { get; set; } + + /// + /// Message sent to the user when they are prompted to verify their account. + /// + [JsonProperty("verification_message")] + public string VerificationMessage { get; set; } + } +} \ No newline at end of file diff --git a/src/Auth0.ManagementApi/Models/Guardian/PhoneProviderConfiguration.cs b/src/Auth0.ManagementApi/Models/Guardian/PhoneProviderConfiguration.cs new file mode 100644 index 000000000..b88a592c4 --- /dev/null +++ b/src/Auth0.ManagementApi/Models/Guardian/PhoneProviderConfiguration.cs @@ -0,0 +1,25 @@ +using System.Runtime.Serialization; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Auth0.ManagementApi.Models +{ + public class PhoneProviderConfiguration + { + [JsonProperty("provider")] + [JsonConverter(typeof(StringEnumConverter))] + public Provider Provider { get; set; } + } + + public enum Provider + { + [EnumMember(Value = "auth0")] + Auth0, + + [EnumMember(Value = "twilio")] + Twilio, + + [EnumMember(Value = "phone-message-hook")] + PhoneMessageHook, + } +} \ No newline at end of file diff --git a/src/Auth0.ManagementApi/Models/Guardian/PushNotificationApnsConfiguration.cs b/src/Auth0.ManagementApi/Models/Guardian/PushNotificationApnsConfiguration.cs new file mode 100644 index 000000000..7214d1847 --- /dev/null +++ b/src/Auth0.ManagementApi/Models/Guardian/PushNotificationApnsConfiguration.cs @@ -0,0 +1,25 @@ +using Newtonsoft.Json; + +namespace Auth0.ManagementApi.Models +{ + public class PushNotificationApnsConfiguration + { + [JsonProperty("bundle_id")] + public string BundleId { get; set; } + + [JsonProperty("sandbox")] + public bool? Sandbox { get; set; } + + [JsonProperty("enabled")] + public bool? Enabled { get; set; } + } + + public class PushNotificationApnsConfigurationUpdateResponse + { + [JsonProperty("bundle_id")] + public string BundleId { get; set; } + + [JsonProperty("sandbox")] + public bool? Sandbox { get; set; } + } +} \ No newline at end of file diff --git a/src/Auth0.ManagementApi/Models/Guardian/PushNotificationApnsConfigurationUpdateRequestBase.cs b/src/Auth0.ManagementApi/Models/Guardian/PushNotificationApnsConfigurationUpdateRequestBase.cs new file mode 100644 index 000000000..3fc77b009 --- /dev/null +++ b/src/Auth0.ManagementApi/Models/Guardian/PushNotificationApnsConfigurationUpdateRequestBase.cs @@ -0,0 +1,28 @@ +using Newtonsoft.Json; + +namespace Auth0.ManagementApi.Models +{ + public class PushNotificationApnsConfigurationUpdateRequestBase + { + [JsonProperty("bundle_id")] + public string BundleId { get; set; } + + [JsonProperty("sandbox")] + public bool? Sandbox { get; set; } + + [JsonProperty("p12")] + public string P12 { get; set; } + } + + public class + PushNotificationApnsConfigurationPatchUpdateRequest : PushNotificationApnsConfigurationUpdateRequestBase + { + + } + + public class + PushNotificationApnsConfigurationPutUpdateRequest : PushNotificationApnsConfigurationUpdateRequestBase + { + + } +} \ No newline at end of file diff --git a/tests/Auth0.ManagementApi.IntegrationTests/GuardianTests.cs b/tests/Auth0.ManagementApi.IntegrationTests/GuardianTests.cs index d93543932..adf244b91 100644 --- a/tests/Auth0.ManagementApi.IntegrationTests/GuardianTests.cs +++ b/tests/Auth0.ManagementApi.IntegrationTests/GuardianTests.cs @@ -119,7 +119,9 @@ public async Task Can_create_enrollment_ticket() var request = new CreateGuardianEnrollmentTicketRequest { UserId = user.UserId, - MustSendMail = false + MustSendMail = false, + EmailAddress = user.Email, + EmailLocale = "en-US" }; var response = await fixture.ApiClient.Guardian.CreateEnrollmentTicketAsync(request); response.TicketId.Should().NotBeNull(); @@ -206,22 +208,190 @@ public async Task Can_update_twilio_provider_configuration() [Fact] public async Task Can_update_phone_messagetypes() { - GuardianPhoneMessageTypes response; - - response = await fixture.ApiClient.Guardian.UpdatePhoneMessageTypesAsync(new GuardianPhoneMessageTypes - { - MessageTypes = new List { "sms" } - }); + var response = + await fixture.ApiClient.Guardian.UpdatePhoneMessageTypesAsync( + new GuardianPhoneMessageTypes + { + MessageTypes = new List { "sms" } + }); + response.MessageTypes.Count.Should().Be(1); - response = await fixture.ApiClient.Guardian.UpdatePhoneMessageTypesAsync(new GuardianPhoneMessageTypes - { - MessageTypes = new List { "sms", "voice" } - }); + response = await fixture.ApiClient.Guardian.UpdatePhoneMessageTypesAsync( + new GuardianPhoneMessageTypes + { + MessageTypes = new List { "sms", "voice" } + }); + response.MessageTypes.Count.Should().Be(2); response = await fixture.ApiClient.Guardian.GetPhoneMessageTypesAsync(); response.MessageTypes.Count.Should().Be(2); } + + [Fact] + public async Task Update_Get_duo_configuration_successfully() + { + var configurationPatchRequestRequest = new DuoConfigurationPatchRequest() + { + Host = "api-hostname", + Ikey = "someKey", + Skey = "someSecret" + }; + var configurationPutRequestRequest = new DuoConfigurationPutRequest() + { + Host = "api-hostname", + Ikey = "someKey", + Skey = "someSecret" + }; + + // Update using PATCH + var updatedDuoConfiguration = + await fixture.ApiClient.Guardian.UpdateDuoConfigurationAsync(configurationPatchRequestRequest); + updatedDuoConfiguration.Should().NotBeNull(); + updatedDuoConfiguration.Ikey.Should().Be("someKey"); + updatedDuoConfiguration.Skey.Should().Be("someSecret"); + updatedDuoConfiguration.Host.Should().Be("api-hostname"); + + // Update using PUT + updatedDuoConfiguration = + await fixture.ApiClient.Guardian.UpdateDuoConfigurationAsync(configurationPutRequestRequest); + updatedDuoConfiguration.Should().NotBeNull(); + updatedDuoConfiguration.Ikey.Should().Be("someKey"); + updatedDuoConfiguration.Skey.Should().Be("someSecret"); + updatedDuoConfiguration.Host.Should().Be("api-hostname"); + + // Get DUO configuration + var duoConfiguration = await fixture.ApiClient.Guardian.GetDuoConfigurationAsync(); + duoConfiguration.Should().NotBeNull(); + duoConfiguration.Ikey.Should().Be("someKey"); + duoConfiguration.Skey.Should().Be("someSecret"); + duoConfiguration.Host.Should().Be("api-hostname"); + } + + [Fact] + public async void Update_Get_PhoneProviderConfiguration_successfully() + { + var phoneProviderConfiguration = new PhoneProviderConfiguration() + { + Provider = Provider.Auth0, + }; + + // update phone provider configuration + var updatedProviderConfiguration = + await fixture.ApiClient.Guardian.UpdatePhoneProviderConfigurationAsync(phoneProviderConfiguration); + updatedProviderConfiguration.Should().NotBeNull(); + updatedProviderConfiguration.Provider.Should().Be(Provider.Auth0); + + // Get the Phone provider configuration explicitly + phoneProviderConfiguration = await fixture.ApiClient.Guardian.GetPhoneProviderConfigurationAsync(); + phoneProviderConfiguration.Should().NotBeNull(); + phoneProviderConfiguration.Provider.Should().Be(Provider.Auth0); + } + + [Fact] + public async void Update_Get_GuardianPhoneEnrollmentTemplate_successfully() + { + var phoneEnrollmentTemplate = new GuardianPhoneEnrollmentTemplate() + { + EnrollmentMessage = "Enrollment message", + VerificationMessage = "Verification message" + }; + + // update phone enrollment template + var updatedPhoneEnrollmentTemplate = + await fixture.ApiClient.Guardian.UpdatePhoneEnrollmentTemplateAsync(phoneEnrollmentTemplate); + updatedPhoneEnrollmentTemplate.Should().NotBeNull(); + updatedPhoneEnrollmentTemplate.Should().BeEquivalentTo(phoneEnrollmentTemplate); + + // Get the phone enrollment template configuration explicitly + var fetchedPhoneEnrollmentTemplate = await fixture.ApiClient.Guardian.GetPhoneEnrollmentTemplateAsync(); + fetchedPhoneEnrollmentTemplate.Should().NotBeNull(); + fetchedPhoneEnrollmentTemplate.Should().BeEquivalentTo(phoneEnrollmentTemplate); + } + + [Fact(Skip = "Run Manually - Requires certificate setup.")] + public async void Update_Get_PushNotificationApnsProviderConfiguration_successfully() + { + var apnsConfigurationPutUpdateRequest = new PushNotificationApnsConfigurationPutUpdateRequest() + { + BundleId = "com.auth0.test", + Sandbox = true, + P12 = "random_string" + }; + + var apnsConfigurationPatchUpdateRequest = new PushNotificationApnsConfigurationPatchUpdateRequest() + { + BundleId = "com.auth0.test", + Sandbox = false, + P12 = "random_string" + }; + + // update Push notification APNS provider configuration using PUT + var apnsConfigurationUpdateResponse = + await fixture.ApiClient.Guardian.UpdatePushNotificationApnsProviderConfigurationAsync(apnsConfigurationPutUpdateRequest); + apnsConfigurationUpdateResponse.Should().NotBeNull(); + + apnsConfigurationUpdateResponse.Sandbox.Should().Be(apnsConfigurationPutUpdateRequest.Sandbox); + apnsConfigurationUpdateResponse.BundleId.Should().Be(apnsConfigurationPutUpdateRequest.BundleId); + + // update Push notification APNS provider configuration using PATCH + apnsConfigurationUpdateResponse = + await fixture.ApiClient.Guardian.UpdatePushNotificationApnsProviderConfigurationAsync(apnsConfigurationPutUpdateRequest); + apnsConfigurationUpdateResponse.Should().NotBeNull(); + + apnsConfigurationUpdateResponse.Sandbox.Should().Be(apnsConfigurationPutUpdateRequest.Sandbox); + apnsConfigurationUpdateResponse.BundleId.Should().Be(apnsConfigurationPutUpdateRequest.BundleId); + + // Get the phone enrollment template configuration explicitly + var fetchedApnsProviderConfiguration = await fixture.ApiClient.Guardian.GetPushNotificationApnsProviderConfigurationAsync(); + fetchedApnsProviderConfiguration.Should().NotBeNull(); + fetchedApnsProviderConfiguration.Sandbox.Should().Be(apnsConfigurationPatchUpdateRequest.Sandbox); + fetchedApnsProviderConfiguration.BundleId.Should().Be(apnsConfigurationPatchUpdateRequest.BundleId); + } + + [Fact(Skip = "Run Manually - Requires FCM setup")] + public async void Test_Update_Fcm_configuration_successfully() + { + var fcmConfigurationPatchUpdateRequest = new FcmConfigurationPatchUpdateRequest() + { + ServerKey = "server_key" + }; + + var fcmConfigurationPutUpdateRequest = new FcmConfigurationPutUpdateRequest() + { + ServerKey = "server_key" + }; + + var fcmV1ConfigurationPatchUpdateRequest = new FcmV1ConfigurationPatchUpdateRequest() + { + ServerCredentials = "server_credentials" + }; + + var fcmV1ConfigurationPutUpdateRequest = new FcmV1ConfigurationPatchUpdateRequest() + { + ServerCredentials = "server_credentials" + }; + + // Update FCM configuration with Patch + var response = + await fixture.ApiClient.Guardian.UpdatePushNotificationFcmConfigurationAsync(fcmConfigurationPatchUpdateRequest); + response.Should().NotBeNull(); + + // Update FCM configuration with Put + response = + await fixture.ApiClient.Guardian.UpdatePushNotificationFcmConfigurationAsync(fcmConfigurationPutUpdateRequest); + response.Should().NotBeNull(); + + // Update FCMV1 configuration with Patch + response = + await fixture.ApiClient.Guardian.UpdatePushNotificationFcmV1ConfigurationAsync(fcmV1ConfigurationPatchUpdateRequest); + response.Should().NotBeNull(); + + // Update FCMV1 configuration with Put + response = + await fixture.ApiClient.Guardian.UpdatePushNotificationFcmV1ConfigurationAsync(fcmV1ConfigurationPutUpdateRequest); + response.Should().NotBeNull(); + } } }