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

[SDK-2438] Add support for Organizations in Management API #489

Merged
merged 24 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
25116aa
Organization CRUD
frederikprijck Mar 28, 2021
bb99025
Add extra organization endpoints
frederikprijck Mar 30, 2021
3f38d4c
Add tests
frederikprijck Mar 30, 2021
8b8bc30
Add organization to clients
frederikprijck Mar 31, 2021
0f40092
Add organization to Jobs
frederikprijck Mar 31, 2021
26faeff
Add organization to tickets
frederikprijck Mar 31, 2021
3bdb023
Add GetOrganizationByName
frederikprijck Mar 31, 2021
3216d1d
Update Organization Tests
frederikprijck Mar 31, 2021
89c7e23
Change logo_uri to logo_url
frederikprijck Mar 31, 2021
4f3c042
Ensure organization_require_behavior is sent as string
frederikprijck Mar 31, 2021
714c810
Update client tests to include organizations
frederikprijck Mar 31, 2021
bd0c794
Update Jobs tests to include organization
frederikprijck Mar 31, 2021
be0c52b
Update tickets tests to include organization
frederikprijck Mar 31, 2021
9570810
Update users tests to include organization
frederikprijck Mar 31, 2021
72a6bd6
Add cleanup controller
frederikprijck Mar 31, 2021
a5e9169
Refactors
frederikprijck Mar 31, 2021
4752142
More refactors
frederikprijck Mar 31, 2021
2a717a9
Make metadata dynamic
frederikprijck Mar 31, 2021
f9b79ff
Refactors
frederikprijck Mar 31, 2021
cf7ed72
Remove controllers
frederikprijck Mar 31, 2021
285ce9b
Merge branch 'master' into freder/sdk-2438
frederikprijck Mar 31, 2021
43c1c36
Fix tests
frederikprijck Mar 31, 2021
34707d7
Add extra documentation
frederikprijck Apr 1, 2021
e0fe2be
Update tests
frederikprijck Apr 1, 2021
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
7 changes: 5 additions & 2 deletions playground/Auth0.NET5/Auth0.NET5.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Auth0.AuthenticationApi" Version="7.5.1" />
<PackageReference Include="Auth0.ManagementApi" Version="7.5.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Auth0.AuthenticationApi\Auth0.AuthenticationApi.csproj" />
<ProjectReference Include="..\..\src\Auth0.ManagementApi\Auth0.ManagementApi.csproj" />
</ItemGroup>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed our Playground app to not use Nuget but use our source project directly


</Project>
318 changes: 318 additions & 0 deletions src/Auth0.ManagementApi/Clients/OrganizationsClient.cs

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions src/Auth0.ManagementApi/Clients/UsersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class UsersClient : BaseClient
readonly JsonConverter[] logsConverters = new JsonConverter[] { new PagedListConverter<LogEntry>("logs", true) };
readonly JsonConverter[] rolesConverters = new JsonConverter[] { new PagedListConverter<Role>("roles") };
readonly JsonConverter[] permissionsConverters = new JsonConverter[] { new PagedListConverter<UserPermission>("permissions") };
readonly JsonConverter[] organizationsConverters = new JsonConverter[] { new PagedListConverter<Organization>("organizations") };

/// <summary>
/// Initializes a new instance of <see cref="UsersClient"/>.
Expand Down Expand Up @@ -322,5 +323,25 @@ public Task RemovePermissionsAsync(string id, AssignPermissionsRequest request)
{
return Connection.SendAsync<object>(HttpMethod.Delete, BuildUri($"users/{EncodePath(id)}/permissions"), request, DefaultHeaders);
}

/// <summary>
/// Lists organizations for a user.
/// </summary>
/// <param name="userId">The ID of the user for which you want to retrieve the organizations.</param>
/// <param name="pagination">Specifies pagination info to use when requesting paged results.</param>
/// <returns>An <see cref="IPagedList{Organization}"/> containing the list of organizations.</returns>
public Task<IPagedList<Organization>> GetAllOrganizationsAsync(string userId, PaginationInfo pagination)
{
if (pagination == null)
throw new ArgumentNullException(nameof(pagination));

return Connection.GetAsync<IPagedList<Organization>>(BuildUri($"users/{EncodePath(userId)}/organizations",
new Dictionary<string, string>
{
{"page", pagination.PageNo.ToString()},
{"per_page", pagination.PerPage.ToString()},
{"include_totals", pagination.IncludeTotals.ToString().ToLower()},
}), DefaultHeaders, organizationsConverters);
}
}
}
6 changes: 6 additions & 0 deletions src/Auth0.ManagementApi/ManagementApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public class ManagementApiClient : IDisposable
/// </summary>
public LogStreamsClient LogStreams { get; }

/// <summary>
/// Contains all the methods to call the /organizations endpoints.
/// </summary>
public OrganizationsClient Organizations { get; }

/// <summary>
/// Contains all the methods to call the /resource-servers endpoints.
/// </summary>
Expand Down Expand Up @@ -160,6 +165,7 @@ public ManagementApiClient(string token, Uri baseUri, IManagementConnection mana
Jobs = new JobsClient(managementConnection, baseUri, defaultHeaders);
Logs = new LogsClient(managementConnection, baseUri, defaultHeaders);
LogStreams = new LogStreamsClient(managementConnection, baseUri, defaultHeaders);
Organizations = new OrganizationsClient(managementConnection, baseUri, defaultHeaders);
ResourceServers = new ResourceServersClient(managementConnection, baseUri, defaultHeaders);
Roles = new RolesClient(managementConnection, baseUri, defaultHeaders);
Rules = new RulesClient(managementConnection, baseUri, defaultHeaders);
Expand Down
16 changes: 16 additions & 0 deletions src/Auth0.ManagementApi/Models/ClientBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Auth0.ManagementApi.Models
{
Expand Down Expand Up @@ -169,6 +170,21 @@ public abstract class ClientBase
/// </summary>
[JsonProperty("refresh_token")]
public RefreshToken RefreshToken { get; set; }

/// <summary>
/// Organization usage for a client
/// </summary>
[JsonProperty("organization_usage")]
[JsonConverter(typeof(StringEnumConverter))]
public OrganizationUsage? OrganizationUsage { get; set; }

/// <summary>
/// Defines how to proceed during an authentication transaction when organization usage is required.
/// </summary>
[JsonProperty("organization_require_behavior")]
[JsonConverter(typeof(StringEnumConverter))]
public OrganizationRequireBehavior? OrganizationRequireBehavior { get; set; }
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ public class EmailVerificationTicketRequest
/// </summary>
[JsonProperty("identity")]
public EmailVerificationIdentity Identity { get; set; }

/// <summary>
/// The organization ID.
/// </summary>
/// <summary>
/// If provided the organization_id and organization_name will be included in the redirection URL querystring
/// </summary>
[JsonProperty("organization_id")]
public string OrganizationId { get; set; }
}

}
11 changes: 11 additions & 0 deletions src/Auth0.ManagementApi/Models/Organization.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Auth0.ManagementApi.Models
{
public class Organization : OrganizationBase
{
[JsonProperty("id")]
public string Id { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Auth0.ManagementApi.Models
{
public class OrganizationAddMemberRolesRequest
{
/// <summary>
/// List of role IDs to associated with the user.
/// </summary>
[JsonProperty("roles")]
public IList<string> Roles { get; set; }
}
}
14 changes: 14 additions & 0 deletions src/Auth0.ManagementApi/Models/OrganizationAddMembersRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Auth0.ManagementApi.Models
{
public class OrganizationAddMembersRequest
{
/// <summary>
/// List of user IDs to add to the organization as members.
/// </summary>
[JsonProperty("members")]
public IList<string> Members { get; set; }
}
}
28 changes: 28 additions & 0 deletions src/Auth0.ManagementApi/Models/OrganizationBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Newtonsoft.Json;

namespace Auth0.ManagementApi.Models
{
public class OrganizationBase
{
/// <summary>
/// The name of the organization
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// The display name of the organization
/// </summary>
[JsonProperty("display_name")]
public string DisplayName { get; set; }
/// <summary>
/// Organization specific branding settings
/// </summary>
[JsonProperty("branding")]
public OrganizationBranding Branding { get; set; }
/// <summary>
/// Organization specific metadata
/// </summary>
[JsonProperty("metadata")]
public dynamic Metadata { get; set; }
}
}
19 changes: 19 additions & 0 deletions src/Auth0.ManagementApi/Models/OrganizationBranding.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Newtonsoft.Json;

namespace Auth0.ManagementApi.Models
{
public class OrganizationBranding
{
/// <summary>
/// URL for the logo. Must use HTTPS.
/// </summary>
[JsonProperty("logo_url")]
public string LogoUrl { get; set; }

/// <summary>
/// Custom color settings.
/// </summary>
[JsonProperty("colors")]
public BrandingColors Colors { get; set; }
}
}
20 changes: 20 additions & 0 deletions src/Auth0.ManagementApi/Models/OrganizationConnection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Newtonsoft.Json;

namespace Auth0.ManagementApi.Models
{
public class OrganizationConnection
{
/// <summary>
/// ID of the connection.
/// </summary>
[JsonProperty("connection_id")]
public string ConnectionId { get; set; }

/// <summary>
/// Whether or not users that login will automatically be granted membership to the organization.
/// </summary>
[JsonProperty("assign_membership_on_login")]
public bool AssignMembershipOnLogin { get; set; }

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Auth0.ManagementApi.Models
{
public class OrganizationConnectionCreateRequest
{
/// <summary>
/// ID of the connection.
/// </summary>
[JsonProperty("connection_id")]
public string ConnectionId { get; set; }

/// <summary>
/// Whether or not users that login will automatically be granted membership to the organization.
/// </summary>
[JsonProperty("assign_membership_on_login")]
public bool AssignMembershipOnLogin { get; set; }

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Newtonsoft.Json;

namespace Auth0.ManagementApi.Models
{
public class OrganizationConnectionUpdateRequest
{
/// <summary>
/// Whether or not users that login will automatically be granted membership to the organization.
/// </summary>
[JsonProperty("assign_membership_on_login")]
public bool AssignMembershipOnLogin { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Auth0.ManagementApi.Models
{
/// <summary>
/// Requests structure for creating a new organization invitation.
/// </summary>
public class OrganizationCreateInvitationRequest
{
/// <summary>
/// Information about the person that is creating the invitation
/// </summary>
[JsonProperty("inviter")]
public OrganizationInvitationInviter Inviter { get; set; }

/// <summary>
/// Information about the person being invited
/// </summary>
[JsonProperty("invitee")]
public OrganizationInvitationInvitee Invitee { get; set; }

/// <summary>
/// The id of the connection to force invitee to authenticate with.
/// </summary>
[JsonProperty("connection_id")]
public string ConnectionId { get; set; }

/// <summary>
/// Auth0 client ID. Used to resolve the application's login initiation endpoint.
/// </summary>
[JsonProperty("client_id")]
public string ClientId { get; set; }

/// <summary>
/// Contains app meta data. The user has read/write access to this.
/// </summary>
[JsonProperty("app_metadata")]
public dynamic AppMetadata { get; set; }

/// <summary>
/// Contains user meta data. The user has read/write access to this.
/// </summary>
[JsonProperty("user_metadata")]
public dynamic UserMetadata { get; set; }

/// <summary>
/// Number of seconds for which the invitation is valid before expiration.
/// </summary>
/// <remarks>
/// If unspecified or set to 0, this value defaults to 604800 seconds (7 days). Max value: 2592000 seconds (30 days).
/// </remarks>
[JsonProperty("ttl_sec")]
public int TimeToLive { get; set; }

/// <summary>
/// Whether the user will receive an invitation email (true) or no email (false), true by default
/// </summary>
[JsonProperty("send_invitation_email")]
public bool SendInvitationEmail { get; set; }

/// <summary>
/// List of role IDs to associated with the user.
/// </summary>
[JsonProperty("roles")]
public IList<string> Roles { get; set; }
}
}
16 changes: 16 additions & 0 deletions src/Auth0.ManagementApi/Models/OrganizationCreateRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;

namespace Auth0.ManagementApi.Models
{
/// <summary>
/// Requests structure for creating a new organization.
/// </summary>
public class OrganizationCreateRequest : OrganizationBase
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Auth0.ManagementApi.Models
{
public class OrganizationDeleteMemberRolesRequest
{
/// <summary>
/// List of role IDs to remove from the user.
/// </summary>
[JsonProperty("roles")]
public IList<string> Roles { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Auth0.ManagementApi.Models
{
public class OrganizationDeleteMembersRequest
{
/// <summary>
/// List of user IDs to remove from the organization as members.
/// </summary>
[JsonProperty("members")]
public IList<string> Members { get; set; }
}
}
14 changes: 14 additions & 0 deletions src/Auth0.ManagementApi/Models/OrganizationGetAllRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Auth0.ManagementApi.Models
{
public class OrganizationGetAllRequest : OrganizationGetRequest
{
/// <summary>
/// Field to sort by.
/// </summary>
/// <remarks>
/// Use field:order where order is 1 for ascending and -1 for descending Defaults to created_at:-1.
/// </remarks>
public string Sort { get; set; } = null;

}
}
Loading