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

Add support for Managing SCIM configuration #726

Merged
merged 3 commits into from
Sep 18, 2024
Merged
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
95 changes: 93 additions & 2 deletions src/Auth0.ManagementApi/Clients/ConnectionsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ namespace Auth0.ManagementApi.Clients
/// </summary>
public class ConnectionsClient : BaseClient, IConnectionsClient
{
readonly JsonConverter[] converters = new JsonConverter[] { new PagedListConverter<Connection>("connections") };
private readonly JsonConverter[] _converters = { new PagedListConverter<Connection>("connections") };
private readonly JsonConverter[] _defaultMappingsConverter = { new ListConverter<ScimMapping>("mapping") };

/// <summary>
/// Initializes a new instance of the <see cref="ConnectionsClient"/>.
Expand Down Expand Up @@ -118,7 +119,7 @@ public Task<IPagedList<Connection>> GetAllAsync(GetConnectionsRequest request, P
}
}

return Connection.GetAsync<IPagedList<Connection>>(BuildUri("connections", queryStrings), DefaultHeaders, converters, cancellationToken);
return Connection.GetAsync<IPagedList<Connection>>(BuildUri("connections", queryStrings), DefaultHeaders, _converters, cancellationToken);
}

/// <summary>
Expand All @@ -143,5 +144,95 @@ public Task CheckStatusAsync(string id, CancellationToken cancellationToken = de
{
return Connection.GetAsync<object>(BuildUri($"connections/{EncodePath(id)}/status"), DefaultHeaders, cancellationToken: cancellationToken);
}

/// <summary>
/// Creates an <see cref="ScimConfiguration"/>.
/// </summary>
/// <param name="id">The id of the connection to create an <see cref="ScimConfiguration"/></param>
/// <param name="request"> <see cref="ScimConfigurationCreateRequest"/> containing information required for creating an <see cref="ScimConfiguration"/></param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>A <see cref="ScimConfiguration"/>.</returns>
public Task<ScimConfiguration> CreateScimConfigurationAsync(string id, ScimConfigurationCreateRequest request, CancellationToken cancellationToken = default)
{
return Connection.SendAsync<ScimConfiguration>(HttpMethod.Post, BuildUri($"connections/{EncodePath(id)}/scim-configuration"), request, DefaultHeaders, cancellationToken: cancellationToken);
}

/// <summary>
/// Retrieves an <see cref="ScimConfiguration"/>.
/// </summary>
/// <param name="id">The id of the connection to retrieve its <see cref="ScimConfiguration"/></param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>A <see cref="ScimConfiguration"/>.</returns>
public Task<ScimConfiguration> GetScimConfigurationAsync(string id, CancellationToken cancellationToken = default)
{
return Connection.GetAsync<ScimConfiguration>(BuildUri($"connections/{EncodePath(id)}/scim-configuration"), DefaultHeaders, cancellationToken: cancellationToken);
}

/// <summary>
/// Updates an <see cref="ScimConfiguration"/>n.
/// </summary>
/// <param name="id">The id of the connection to update its SCIM configuration</param>
/// <param name="request"> <see cref="ScimConfigurationUpdateRequest"/> containing information required for updating an <see cref="ScimConfiguration"/></param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>A <see cref="ScimConfiguration"/>.</returns>
public Task<ScimConfiguration> UpdateScimConfigurationAsync(string id, ScimConfigurationUpdateRequest request, CancellationToken cancellationToken = default)
{
return Connection.SendAsync<ScimConfiguration>(new HttpMethod("PATCH"), BuildUri($"connections/{EncodePath(id)}/scim-configuration"), request, DefaultHeaders, cancellationToken: cancellationToken);
}

/// <summary>
/// Deletes an <see cref="ScimConfiguration"/>.
/// </summary>
/// <param name="id">The id of the connection to delete its SCIM configuration</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
public Task DeleteScimConfigurationAsync(string id, CancellationToken cancellationToken = default)
{
return Connection.SendAsync<object>(HttpMethod.Delete, BuildUri($"connections/{EncodePath(id)}/scim-configuration"), null, DefaultHeaders, cancellationToken: cancellationToken);
}

/// <summary>
/// Retrieves the default <see cref="ScimMapping"/>.
/// </summary>
/// <param name="id">The id of the connection to retrieve its default <see cref="ScimMapping"/></param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>An IList of <see cref="ScimMapping"/>.</returns>
public Task<IList<ScimMapping>> GetDefaultScimMappingAsync(string id, CancellationToken cancellationToken = default)
{
return Connection.GetAsync<IList<ScimMapping>>(BuildUri($"connections/{EncodePath(id)}/scim-configuration/default-mapping"), DefaultHeaders, _defaultMappingsConverter, cancellationToken: cancellationToken);
}

/// <summary>
/// Creates an <see cref="ScimToken"/>.
/// </summary>
/// <param name="id">The id of the connection to create an <see cref="ScimToken"/></param>
/// <param name="request"> <see cref="ScimTokenCreateRequest"/> containing information required for creating an <see cref="ScimToken"/></param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>An <see cref="ScimTokenCreateResponse"/>.</returns>
public Task<ScimTokenCreateResponse> CreateScimTokenAsync(string id, ScimTokenCreateRequest request, CancellationToken cancellationToken = default)
{
return Connection.SendAsync<ScimTokenCreateResponse>(HttpMethod.Post, BuildUri($"connections/{EncodePath(id)}/scim-configuration/tokens"), request, DefaultHeaders, cancellationToken: cancellationToken);
}

/// <summary>
/// Retrieves all <see cref="ScimToken"/> for the given connection.
/// </summary>
/// <param name="id">The id of the connection to retrieve its <see cref="ScimToken"/></param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>An <see cref="ScimToken"/>.</returns>
public Task<IList<ScimToken>> GetScimTokenAsync(string id, CancellationToken cancellationToken = default)
{
return Connection.GetAsync<IList<ScimToken>>(BuildUri($"connections/{EncodePath(id)}/scim-configuration/tokens"), DefaultHeaders, cancellationToken: cancellationToken);
}

/// <summary>
/// Deletes an SCIM token.
/// </summary>
/// <param name="id">The ID of the connection that owns the <see cref="ScimToken"/> to be deleted</param>
/// <param name="tokenId">The ID of the <see cref="ScimToken"/> to delete</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
public Task DeleteScimTokenAsync(string id, string tokenId, CancellationToken cancellationToken = default)
{
return Connection.SendAsync<object>(HttpMethod.Delete, BuildUri($"connections/{EncodePath(id)}/scim-configuration/tokens/{EncodePath(tokenId)}"), null, DefaultHeaders, cancellationToken: cancellationToken);
}
}
}
69 changes: 69 additions & 0 deletions src/Auth0.ManagementApi/Clients/IConnectionsClient.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@


namespace Auth0.ManagementApi.Clients
{
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using Models;
using Paging;

Expand Down Expand Up @@ -70,5 +73,71 @@ public interface IConnectionsClient
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous check operation. Will throw if the status check fails.</returns>
Task CheckStatusAsync(string id, CancellationToken cancellationToken = default);

/// <summary>
/// Creates an <see cref="ScimConfiguration"/>.
/// </summary>
/// <param name="id">The id of the connection to create an <see cref="ScimConfiguration"/></param>
/// <param name="request"> <see cref="ScimConfigurationCreateRequest"/> containing information required for creating an <see cref="ScimConfiguration"/></param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>A <see cref="ScimConfiguration"/>.</returns>
Task<ScimConfiguration> CreateScimConfigurationAsync(string id, ScimConfigurationCreateRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieves an <see cref="ScimConfiguration"/>.
/// </summary>
/// <param name="id">The id of the connection to retrieve its <see cref="ScimConfiguration"/></param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>A <see cref="ScimConfiguration"/>.</returns>
Task<ScimConfiguration> GetScimConfigurationAsync(string id, CancellationToken cancellationToken = default);

/// <summary>
/// Updates an <see cref="ScimConfiguration"/>.
/// </summary>
/// <param name="id">The id of the connection to update <see cref="ScimConfiguration"/></param>
/// <param name="request"> <see cref="ScimConfigurationUpdateRequest"/> containing information required for updating an <see cref="ScimConfiguration"/></param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>A <see cref="ScimConfiguration"/>.</returns>
Task<ScimConfiguration> UpdateScimConfigurationAsync(string id, ScimConfigurationUpdateRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Deletes an <see cref="ScimConfiguration"/>.
/// </summary>
/// <param name="id">The id of the connection to delete <see cref="ScimConfiguration"/></param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
Task DeleteScimConfigurationAsync(string id, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieves the default <see cref="ScimMapping"/>.
/// </summary>
/// <param name="id">The id of the connection to retrieve its default <see cref="ScimMapping"/></param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>An IList of <see cref="ScimMapping"/>.</returns>
Task<IList<ScimMapping>> GetDefaultScimMappingAsync(string id, CancellationToken cancellationToken = default);

/// <summary>
/// Creates an <see cref="ScimToken"/>.
/// </summary>
/// <param name="id">The id of the connection to create an <see cref="ScimToken"/></param>
/// <param name="request"> <see cref="ScimTokenCreateRequest"/> containing information required for creating an <see cref="ScimToken"/></param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>An <see cref="ScimTokenCreateResponse"/>.</returns>
Task<ScimTokenCreateResponse> CreateScimTokenAsync(string id, ScimTokenCreateRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieves all <see cref="ScimToken"/> for the given connection.
/// </summary>
/// <param name="id">The id of the connection to retrieve its <see cref="ScimToken"/></param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>An <see cref="ScimToken"/>.</returns>
Task<IList<ScimToken>> GetScimTokenAsync(string id, CancellationToken cancellationToken = default);

/// <summary>
/// Deletes an SCIM token.
/// </summary>
/// <param name="id">The ID of the connection that owns the <see cref="ScimToken"/> to be deleted</param>
/// <param name="tokenId">The ID of the <see cref="ScimToken"/> to delete</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
Task DeleteScimTokenAsync(string id, string tokenId, CancellationToken cancellationToken = default);
}
}
60 changes: 60 additions & 0 deletions src/Auth0.ManagementApi/Models/Scim/ScimConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace Auth0.ManagementApi.Models
{
/// <summary>
/// Represents an SCIM Configuration
/// </summary>
public class ScimConfiguration
{
/// <summary>
/// The connection's identifier
/// </summary>
[JsonProperty("connection_id")]
public string ConnectionId { get; set; }

/// <summary>
/// The connection's identifier
/// </summary>
[JsonProperty("connection_name")]
public string ConnectionName { get; set; }

/// <summary>
/// The connection's strategy
/// </summary>
[JsonProperty("strategy")]
public string Strategy { get; set; }

/// <summary>
/// The tenant's name
/// </summary>
[JsonProperty("tenant_name")]
public string TenantName { get; set; }

/// <summary>
/// User ID attribute for generating unique user ids
/// </summary>
[JsonProperty("user_id_attribute")]
public string UserIdAttribute { get; set; }

/// <summary>
/// The mapping between auth0 and SCIM
/// </summary>
[JsonProperty("mapping")]
public List<ScimMapping> Mapping { get; set; }

/// <summary>
/// The Date Time SCIM Configuration was created
/// </summary>
[JsonProperty("created_at")]
public string CreatedAt { get; set; }

/// <summary>
/// The Date Time SCIM Configuration was last updated
/// </summary>
[JsonProperty("updated_on")]
public string UpdatedOn { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Auth0.ManagementApi.Models
{
public class ScimConfigurationCreateRequest
{
/// <summary>
/// User ID attribute for generating unique user ids
/// </summary>
[JsonProperty("user_id_attribute")]
public string UserIdAttribute { get; set; }

/// <summary>
/// The mapping between auth0 and SCIM
/// </summary>
[JsonProperty("mapping")]
public List<ScimMapping> Mapping { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Auth0.ManagementApi.Models
{
public class ScimConfigurationUpdateRequest
{
/// <summary>
/// User ID attribute for generating unique user ids
/// </summary>
[JsonProperty("user_id_attribute")]
public string UserIdAttribute { get; set; }

/// <summary>
/// The mapping between auth0 and SCIM
/// </summary>
[JsonProperty("mapping")]
public List<ScimMapping> Mapping { get; set; }
}
}
22 changes: 22 additions & 0 deletions src/Auth0.ManagementApi/Models/Scim/ScimMapping.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Newtonsoft.Json;

namespace Auth0.ManagementApi.Models
{
/// <summary>
/// Represents the mapping between SCIM and Auth0
/// </summary>
public class ScimMapping
{
/// <summary>
/// The field location in the auth0 schema
/// </summary>
[JsonProperty("auth0")]
public string Auth0 { get; set; }

/// <summary>
/// The field location in the SCIM schema
/// </summary>
[JsonProperty("scim")]
public string Scim { get; set; }
}
}
13 changes: 13 additions & 0 deletions src/Auth0.ManagementApi/Models/Scim/ScimToken.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Newtonsoft.Json;

namespace Auth0.ManagementApi.Models
{
public class ScimToken : ScimTokenBase
{
/// <summary>
/// The token's last used at timestamp
/// </summary>
[JsonProperty("last_used_at")]
public string LastUsedAt { get; set; }
}
}
35 changes: 35 additions & 0 deletions src/Auth0.ManagementApi/Models/Scim/ScimTokenBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace Auth0.ManagementApi.Models
{
/// <summary>
/// Represents an SCIM token for an SCIM client.
/// </summary>
public class ScimTokenBase
{
/// <summary>
/// The token's identifier
/// </summary>
[JsonProperty("token_id")]
public string TokenId { get; set; }

/// <summary>
/// The scopes of the scim token
/// </summary>
[JsonProperty("scopes")]
public string[] Scopes { get; set; }

/// <summary>
/// The token's created at timestamp
/// </summary>
[JsonProperty("created_at")]
public string CreatedAt { get; set; }

/// <summary>
/// The token's valid until at timestamp
/// </summary>
[JsonProperty("valid_until")]
public string ValidUntil { get; set; }
}
}
Loading
Loading