Skip to content

Commit

Permalink
Final touches and README
Browse files Browse the repository at this point in the history
  • Loading branch information
itaihanski committed Mar 4, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent f20b092 commit 11f4612
Showing 11 changed files with 537 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Descope.Test/IntegrationTests/Management/TenantTests.cs
Original file line number Diff line number Diff line change
@@ -105,7 +105,7 @@ public async Task Tenant_DeleteAndLoadAll()

// Load all and make sure it's gone
var tenants = await _descopeClient.Management.Tenant.LoadAll();
foreach (TenantResponse tenant in tenants)
foreach (var tenant in tenants)
{
Assert.NotEqual(id, tenant.Id);
}
2 changes: 1 addition & 1 deletion Descope.Test/packages.lock.json
Original file line number Diff line number Diff line change
@@ -1237,4 +1237,4 @@
}
}
}
}
}
1 change: 0 additions & 1 deletion Descope/DescopeClient.cs
Original file line number Diff line number Diff line change
@@ -22,6 +22,5 @@ public static class SdkInfo
{
public static string Name { get; } = "dotnet";
public static string Version { get; } = "0.1.0";
public static string DotNetVersion { get; } = Environment.Version.ToString();
}
}
2 changes: 1 addition & 1 deletion Descope/Internal/Authentication/Authentication.cs
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ public async Task<Token> ValidateAndRefreshSession(string sessionJwt, string ref
return await RefreshSession(refreshJwt);
}

public async Task<Token> ExchangeAccessKey(string accessKey, LoginOptions? loginOptions = null)
public async Task<Token> ExchangeAccessKey(string accessKey, AccessKeyLoginOptions? loginOptions = null)
{
if (string.IsNullOrEmpty(accessKey)) throw new DescopeException("access key missing");
var response = await _httpClient.Post<AccessKeyExchangeResponse>(Routes.AuthAccessKeyExchange, accessKey, new { loginOptions });
2 changes: 1 addition & 1 deletion Descope/Internal/Http/HttpClient.cs
Original file line number Diff line number Diff line change
@@ -33,9 +33,9 @@ public HttpClient(DescopeConfig descopeConfig)
_client = new RestClient(options);
_client.AddDefaultHeader("Accept", "application/json");
_client.AddDefaultHeader("Content-Type", "application/json");
_client.AddDefaultHeader("x-descope-sdk-dotnet-version", SdkInfo.DotNetVersion);
_client.AddDefaultHeader("x-descope-sdk-name", SdkInfo.Name);
_client.AddDefaultHeader("x-descope-sdk-version", SdkInfo.Version);
_client.AddDefaultHeader("x-descope-sdk-dotnet-version", Environment.Version.ToString());
}

public async Task<TResponse> Get<TResponse>(string resource, string? pswd = null)
20 changes: 9 additions & 11 deletions Descope/Internal/Management/User.cs
Original file line number Diff line number Diff line change
@@ -15,18 +15,18 @@ internal User(IHttpClient httpClient, string managementKey)

#region IUser Implementation

public async Task<UserResponse> Create(string loginId, UserRequest? request, bool sendInvite, InviteOptions? options, bool testUser)
public async Task<UserResponse> Create(string loginId, UserRequest? request, bool sendInvite, InviteOptions? inviteOptions, bool testUser)
{
request ??= new UserRequest();
var body = MakeCreateUserRequestBody(loginId, request, sendInvite, options, testUser);
var body = MakeCreateUserRequestBody(loginId, request, sendInvite, inviteOptions, testUser);
var result = await _httpClient.Post<WrappedUserResponse>(Routes.UserCreate, _managementKey, body);
return result.User;
}

public async Task<BatchCreateUserResponse> CreateBatch(List<BatchUser> batchUsers, bool sendInvite, InviteOptions? options)
public async Task<BatchCreateUserResponse> CreateBatch(List<BatchUser> batchUsers, bool sendInvite, InviteOptions? inviteOptions)
{
batchUsers ??= new List<BatchUser>();
var body = MakeCreateBatchUsersRequestBody(batchUsers, sendInvite, options);
var body = MakeCreateBatchUsersRequestBody(batchUsers, sendInvite, inviteOptions);
return await _httpClient.Post<BatchCreateUserResponse>(Routes.UserCreateBatch, _managementKey, body);
}

@@ -329,16 +329,14 @@ private static Dictionary<string, object> MakeUpdateUserRequestBody(string login
private static List<Dictionary<string, object>> MakeAssociatedTenantList(List<AssociatedTenant> tenants)
{
tenants ??= new List<AssociatedTenant>();
var dict = new List<Dictionary<string, object>>();
var list = new List<Dictionary<string, object>>();
foreach (var tenant in tenants)
{
dict.Add(new Dictionary<string, object>
{
{"tenantId", tenant.TenantId},
{"roleNames", tenant.RoleNames},
});
var dict = new Dictionary<string, object> { { "tenantId", tenant.TenantId } };
if (tenant.RoleNames != null) dict["roleNames"] = tenant.RoleNames;
list.Add(dict);
};
return dict;
return list;
}

#endregion Internal
2 changes: 1 addition & 1 deletion Descope/Sdk/Authentication.cs
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@ public interface IAuthentication
/// <param name="accessKey">The accessKey cleartext to exchange</param>
/// <param name="loginOptions">Optional login options for the exchange</param>
/// <returns>A valid session token if successful</returns>
Task<Token> ExchangeAccessKey(string accessKey, LoginOptions? loginOptions = null);
Task<Token> ExchangeAccessKey(string accessKey, AccessKeyLoginOptions? loginOptions = null);

/// <summary>
/// Ensure a validated session token has been granted the specified permissions.
8 changes: 4 additions & 4 deletions Descope/Sdk/Managment.cs
Original file line number Diff line number Diff line change
@@ -89,10 +89,10 @@ public interface IUser
/// <param name="loginId">A login ID to identify the created user</param>
/// <param name="request">Optional information about the user being created</param>
/// <param name="sendInvite">Whether or not to send an invitation to the user</param>
/// <param name="options">Optional invite options used to send an invitation to the created user</param>
/// <param name="inviteOptions">Optional invite options used to send an invitation to the created user</param>
/// <param name="testUser">Optionally create a test user</param>
/// <returns>The created user</returns>
Task<UserResponse> Create(string loginId, UserRequest? request = null, bool sendInvite = false, InviteOptions? options = null, bool testUser = false);
Task<UserResponse> Create(string loginId, UserRequest? request = null, bool sendInvite = false, InviteOptions? inviteOptions = null, bool testUser = false);

/// <summary>
/// Create users in batch.
@@ -109,9 +109,9 @@ public interface IUser
/// </summary>
/// <param name="batchUsers">The list of users to create</param>
/// <param name="sendInvite">Whether or not to send an invitation to the users</param>
/// <param name="options">Optional invite options used to send an invitation to the created users</param>
/// <param name="inviteOptions">Optional invite options used to send an invitation to the created users</param>
/// <returns>A list of created users and a list of failures if occurred</returns>
Task<BatchCreateUserResponse> CreateBatch(List<BatchUser> batchUsers, bool sendInvite = false, InviteOptions? options = null);
Task<BatchCreateUserResponse> CreateBatch(List<BatchUser> batchUsers, bool sendInvite = false, InviteOptions? inviteOptions = null);

/// <summary>
/// Update an existing user.
23 changes: 11 additions & 12 deletions Descope/Types/Types.cs
Original file line number Diff line number Diff line change
@@ -279,14 +279,8 @@ public BatchUser(string loginId)

public class BatchUserPassword
{
public string Cleartext { get; set; }
public BatchUserPasswordHashed Hashed { get; set; }

public BatchUserPassword(string cleartext, BatchUserPasswordHashed hashed)
{
this.Cleartext = cleartext;
this.Hashed = hashed;
}
public string? Cleartext { get; set; }
public BatchUserPasswordHashed? Hashed { get; set; }
}

public class BatchUserPasswordHashed
@@ -389,7 +383,7 @@ public class SearchUserOptions
[JsonPropertyName("roles")]
public List<string>? Roles { get; set; }
[JsonPropertyName("tenantIds")]
public List<string>? TenantIDs { get; set; }
public List<string>? TenantIds { get; set; }
[JsonPropertyName("ssoAppIDs")]
public List<string>? SsoAppIds { get; set; }
[JsonPropertyName("customAttributes")]
@@ -470,13 +464,12 @@ public class AssociatedTenant
[JsonPropertyName("tenantId")]
public string TenantId { get; set; }
[JsonPropertyName("tenantName")]
public string TenantName { get; set; }
public string? TenantName { get; set; }
[JsonPropertyName("roleNames")]
public List<string>? RoleNames { get; set; }
public AssociatedTenant(string tenantId, string tenantName)
public AssociatedTenant(string tenantId)
{
TenantId = tenantId;
TenantName = tenantName;
}
}

@@ -595,6 +588,12 @@ public AccessKeyResponse(string id, string name, List<string> roleNames, List<As
}
}

public class AccessKeyLoginOptions
{
[JsonPropertyName("customClaims")]
public Dictionary<string, object>? CustomClaims { get; set; }
}

public class ProjectCloneResponse
{
[JsonPropertyName("projectId")]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Descope

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit 11f4612

Please sign in to comment.