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

Adds support for Self-Service-Profile endpoints #747

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
98 changes: 98 additions & 0 deletions src/Auth0.ManagementApi/Clients/ISelfServiceProfilesClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System.Threading;
using System.Threading.Tasks;
using Auth0.ManagementApi.Models.SelfServiceProfiles;
using Auth0.ManagementApi.Paging;

namespace Auth0.ManagementApi.Clients
{
public interface ISelfServiceProfilesClient
{
/// <summary>
/// Retrieve self-service-profile information.
/// </summary>
/// <param name="pagination"><see cref="PaginationInfo"/></param>
/// <param name="cancellationToken"> <see cref="CancellationToken"/></param>
/// <returns><see cref="IPagedList{T}"/> of <see cref="SelfServiceProfile"/></returns>
Task<IPagedList<SelfServiceProfile>> GetAllAsync(PaginationInfo pagination = null, CancellationToken cancellationToken = default);

/// <summary>
/// Create self-service-profile.
/// </summary>
/// <param name="request"><see cref="SelfServiceProfileCreateRequest"/></param>
/// <param name="cancellationToken"> <see cref="CancellationToken"/></param>
/// <returns><see cref="SelfServiceProfile"/></returns>
Task<SelfServiceProfile> CreateAsync(SelfServiceProfileCreateRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieve self-service-profile by id.
/// </summary>
/// <param name="id">Self-Service-Profile ID</param>
/// <param name="cancellationToken"> <see cref="CancellationToken"/></param>
/// <returns><see cref="SelfServiceProfile"/></returns>
Task<SelfServiceProfile> GetAsync(string id, CancellationToken cancellationToken = default);

/// <summary>
/// Delete a self-service-profile by id.
/// </summary>
/// <param name="id">Self-Service-Profile ID</param>
/// <param name="cancellationToken"> <see cref="CancellationToken"/></param>
Task DeleteAsync(string id, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieve self-service-profile by id.
/// </summary>
/// <param name="id">Self-Service-Profile ID</param>
/// <param name="request"><see cref="SelfServiceProfileUpdateRequest"/></param>
/// <param name="cancellationToken"> <see cref="CancellationToken"/></param>
/// <returns><see cref="SelfServiceProfile"/></returns>
Task<SelfServiceProfile> UpdateAsync(string id, SelfServiceProfileUpdateRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Creates an sso-access ticket to initiate the Self Service SSO Flow using a self-service profile
/// </summary>
/// <param name="id">The id of the sso-profile to retrieve</param>
/// <param name="request"><see cref="SelfServiceSsoTicketCreateRequest"/></param>
/// <param name="cancellationToken"><see cref="CancellationToken"/></param>
/// <returns><see cref="SelfServiceSsoTicket"/></returns>
Task<SelfServiceSsoTicket> CreateSsoTicketAsync(string id, SelfServiceSsoTicketCreateRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Revokes an SSO access ticket and invalidates associated sessions.
/// The ticket will no longer be accepted to initiate a Self-Service SSO session.
/// If any users have already started a session through this ticket, their session will be terminated.
/// Clients should expect a 202 Accepted response upon successful processing, indicating that the request
/// has been acknowledged and that the revocation is underway but may not be fully completed at the time of response.
/// If the specified ticket does not exist, a 202 Accepted response is also returned,
/// signaling that no further action is required.
/// Clients should treat these 202 responses as an acknowledgment that the request has been accepted and
/// is in progress, even if the ticket was not found.
/// </summary>
/// <param name="ticketId">The id of the ticket to revoke</param>
/// <param name="profileId">The id of the self-service profile</param>
/// <param name="cancellationToken"> <see cref="CancellationToken"/> </param>
/// <returns><see cref="SelfServiceSsoTicket"/></returns>
Task RevokeSsoTicketAsync(string profileId, string ticketId, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieves text customizations for a given self-service profile, language and Self Service SSO Flow page
/// </summary>
/// <param name="id">The id of the self-service profile.</param>
/// <param name="language">The language of the custom text.</param>
/// <param name="page">The page where the custom text is shown.</param>
/// <param name="cancellationToken"> <see cref="CancellationToken"/> </param>
/// <returns>The list of custom text keys and values.</returns>
Task<object> GetCustomTextForSelfServiceProfileAsync(string id, string language, string page, CancellationToken cancellationToken = default);

/// <summary>
/// Updates text customizations for a given self-service profile, language and Self Service SSO Flow page.
/// </summary>
/// <param name="id">The id of the self-service profile.</param>
/// <param name="language">The language of the custom text.</param>
/// <param name="page">The page where the custom text is shown.</param>
/// <param name="body">The list of text keys and values to customize the self-service SSO page.
/// Values can be plain text or rich HTML content limited to basic styling tags and hyperlinks.</param>
/// <param name="cancellationToken"> <see cref="CancellationToken"/> </param>
/// <returns>The resulting list of custom text keys and values.</returns>
Task<object> SetCustomTextForSelfServiceProfileAsync(string id, string language, string page, object body, CancellationToken cancellationToken = default);
}
}
172 changes: 172 additions & 0 deletions src/Auth0.ManagementApi/Clients/SelfServiceProfilesClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Auth0.ManagementApi.Models.SelfServiceProfiles;
using Auth0.ManagementApi.Paging;
using Newtonsoft.Json;

namespace Auth0.ManagementApi.Clients
{
/// <summary>
/// Client to manage Self Service Profiles.
/// </summary>
public class SelfServiceProfilesClient : BaseClient, ISelfServiceProfilesClient
{
readonly JsonConverter[] converters = { new PagedListConverter<SelfServiceProfile>("self_service_profiles") };
public SelfServiceProfilesClient(
IManagementConnection connection,
Uri baseUri,
IDictionary<string, string> defaultHeaders) : base(connection, baseUri, defaultHeaders)
{
}

/// <inheritdoc cref="ISelfServiceProfilesClient.GetAllAsync"/>
public Task<IPagedList<SelfServiceProfile>> GetAllAsync(PaginationInfo pagination = null, CancellationToken cancellationToken = default)
{
var queryStrings = new Dictionary<string, string>();

if (pagination != null)
{
queryStrings["page"] = pagination.PageNo.ToString();
queryStrings["per_page"] = pagination.PerPage.ToString();
queryStrings["include_totals"] = pagination.IncludeTotals.ToString().ToLower();
}

return Connection.GetAsync<IPagedList<SelfServiceProfile>>(
BuildUri("self-service-profiles", queryStrings),
DefaultHeaders,
converters,
cancellationToken);
}

/// <inheritdoc cref="ISelfServiceProfilesClient.CreateAsync"/>
public Task<SelfServiceProfile> CreateAsync(SelfServiceProfileCreateRequest request, CancellationToken cancellationToken = default)
{
if (request == null)
throw new ArgumentNullException(nameof(request));

return Connection.SendAsync<SelfServiceProfile>(
HttpMethod.Post,
BuildUri("self-service-profiles"),
request,
DefaultHeaders,
cancellationToken: cancellationToken);
}

/// <inheritdoc cref="ISelfServiceProfilesClient.GetAsync"/>
public Task<SelfServiceProfile> GetAsync(string id, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(id))
throw new ArgumentNullException(nameof(id));

return Connection.GetAsync<SelfServiceProfile>(
BuildUri($"self-service-profiles/{EncodePath(id)}"),
DefaultHeaders,
null,
cancellationToken);
}

/// <inheritdoc cref="ISelfServiceProfilesClient.DeleteAsync"/>
public Task DeleteAsync(string id, CancellationToken cancellationToken = default)
{
return Connection.SendAsync<object>(
HttpMethod.Delete,
BuildUri($"self-service-profiles/{EncodePath(id)}"),
body: null,
headers: DefaultHeaders,
cancellationToken: cancellationToken);
}

/// <inheritdoc cref="ISelfServiceProfilesClient.UpdateAsync"/>
public Task<SelfServiceProfile> UpdateAsync(string id, SelfServiceProfileUpdateRequest request, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(id))
throw new ArgumentNullException(nameof(id));

return Connection.SendAsync<SelfServiceProfile>(
new HttpMethod("PATCH"),
BuildUri($"self-service-profiles/{EncodePath(id)}"),
request,
DefaultHeaders,
cancellationToken: cancellationToken);
}

/// <inheritdoc cref="ISelfServiceProfilesClient.CreateSsoTicketAsync"/>
public Task<SelfServiceSsoTicket> CreateSsoTicketAsync(string id, SelfServiceSsoTicketCreateRequest request, CancellationToken cancellationToken = default)
{
if (request == null)
throw new ArgumentNullException(nameof(request));

if (string.IsNullOrEmpty(id))
throw new ArgumentNullException(nameof(id));

return Connection.SendAsync<SelfServiceSsoTicket>(
HttpMethod.Post,
BuildUri($"self-service-profiles/{EncodePath(id)}/sso-ticket"),
request,
DefaultHeaders,
cancellationToken: cancellationToken);
}

/// <inheritdoc cref="ISelfServiceProfilesClient.RevokeSsoTicketAsync"/>
public Task RevokeSsoTicketAsync(string profileId, string ticketId, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(profileId))
throw new ArgumentNullException(nameof(profileId));

if (string.IsNullOrEmpty(ticketId))
throw new ArgumentNullException(nameof(ticketId));

return Connection.SendAsync<SelfServiceSsoTicket>(
HttpMethod.Post,
BuildUri($"self-service-profiles/{EncodePath(profileId)}/sso-ticket/{EncodePath(ticketId)}/revoke"),
null,
DefaultHeaders,
cancellationToken: cancellationToken);
}

/// <inheritdoc cref="ISelfServiceProfilesClient.GetCustomTextForSelfServiceProfileAsync"/>
public Task<object> GetCustomTextForSelfServiceProfileAsync(string id, string language, string page,
CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(id))
throw new ArgumentNullException(nameof(id));

if (string.IsNullOrEmpty(language))
throw new ArgumentNullException(nameof(language));

if (string.IsNullOrEmpty(page))
throw new ArgumentNullException(nameof(page));

return Connection.GetAsync<object>(
BuildUri($"self-service-profiles/{EncodePath(id)}/custom-text/{EncodePath(language)}/{EncodePath(page)}"),
DefaultHeaders,
null,
cancellationToken);
}

/// <inheritdoc cref="ISelfServiceProfilesClient.SetCustomTextForSelfServiceProfileAsync"/>
public Task<object> SetCustomTextForSelfServiceProfileAsync(string id, string language, string page, object body,
CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(id))
throw new ArgumentNullException(nameof(id));

if (string.IsNullOrEmpty(language))
throw new ArgumentNullException(nameof(language));

if (string.IsNullOrEmpty(page))
throw new ArgumentNullException(nameof(page));

return Connection
.SendAsync<object>(
HttpMethod.Put,
BuildUri($"self-service-profiles/{EncodePath(id)}/custom-text/{EncodePath(language)}/{EncodePath(page)}"),
body,
DefaultHeaders,
cancellationToken: cancellationToken);
}
}
}
5 changes: 5 additions & 0 deletions src/Auth0.ManagementApi/IManagementApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ public interface IManagementApiClient : IDisposable
/// Contains all the methods to call the /sessions endpoints.
/// </summary>
ISessionsClient Sessions { get; }

/// <summary>
/// Contains all the methods to call the /self-service-profile endpoints.
/// </summary>
ISelfServiceProfilesClient SelfServiceProfilesClient { get; }

/// <summary>
/// Update the Access Token used with every request.
Expand Down
5 changes: 5 additions & 0 deletions src/Auth0.ManagementApi/ManagementApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using Auth0.ManagementApi.Models.SelfServiceProfiles;

namespace Auth0.ManagementApi
{
Expand Down Expand Up @@ -168,6 +169,9 @@ public class ManagementApiClient : IManagementApiClient

/// <inheritdoc cref="Auth0.ManagementApi.IManagementApiClient.Sessions"/>
public ISessionsClient Sessions { get; }

/// <inheritdoc cref="Auth0.ManagementApi.IManagementApiClient.SelfServiceProfilesClient"/>
public ISelfServiceProfilesClient SelfServiceProfilesClient { get; }

private Dictionary<string, string> DefaultHeaders { get; set; }

Expand Down Expand Up @@ -221,6 +225,7 @@ public ManagementApiClient(string token, Uri baseUri, IManagementConnection mana
Users = new UsersClient(managementConnection, baseUri, DefaultHeaders);
RefreshTokens = new RefreshTokenClient(managementConnection, baseUri, DefaultHeaders);
Sessions = new SessionsClient(managementConnection, baseUri, DefaultHeaders);
SelfServiceProfilesClient = new SelfServiceProfilesClient(managementConnection, baseUri, DefaultHeaders);
}

/// <summary>
Expand Down
25 changes: 25 additions & 0 deletions src/Auth0.ManagementApi/Models/SelfServiceProfiles/Branding.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Newtonsoft.Json;

namespace Auth0.ManagementApi.Models.SelfServiceProfiles
{
public class Branding
{
/// <summary>
/// Logo Url
/// </summary>
[JsonProperty("logo_url")]
public string LogoUrl { get; set; }

/// <summary>
/// Branding Colors
/// </summary>
[JsonProperty("colors")]
public Color Color { get; set; }
}

public class Color
{
[JsonProperty("primary")]
public string Primary { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Newtonsoft.Json;

namespace Auth0.ManagementApi.Models.SelfServiceProfiles
{
/// <summary>
/// List of organizations that the connection will be enabled for.
/// </summary>
public class EnabledOrganization
{
/// <summary>
/// Organization identifier
/// </summary>
[JsonProperty("organization_id")]
public string OrganizationId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using Newtonsoft.Json;

namespace Auth0.ManagementApi.Models.SelfServiceProfiles
{
public class SelfServiceProfile : SelfServiceProfileBase
{
/// <summary>
/// The unique ID of the self-service profile.
/// </summary>
[JsonProperty("id")]
public string Id { get; set; }

/// <summary>
/// The time when this self-service Profile was created.
/// </summary>
[JsonProperty("created_at")]
public DateTime CreatedAt { get; set; }

/// <summary>
/// The time when this self-service Profile was updated.
/// </summary>
[JsonProperty("updated_at")]
public DateTime UpdatedAt { get; set; }
}
}
Loading
Loading