-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99e38f8
commit ffc6ccf
Showing
7 changed files
with
525 additions
and
1 deletion.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
Descope.Test/IntegrationTests/Management/SsoApplicationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using Xunit; | ||
|
||
namespace Descope.Test.Integration | ||
{ | ||
public class SsoApplicationTests | ||
{ | ||
private readonly DescopeClient _descopeClient = IntegrationTestSetup.InitDescopeClient(); | ||
|
||
[Fact] | ||
public async Task SsoApplication_Saml() | ||
{ | ||
string? id = null; | ||
try | ||
{ | ||
var name = "name"; | ||
var url = "https://sometestidp.com"; | ||
// Create | ||
var options = new SamlApplicationOptions(name, url); | ||
id = await _descopeClient.Management.SsoApplication.CreateSAMLApplication(options); | ||
|
||
// Load | ||
var loadedApp = await _descopeClient.Management.SsoApplication.Load(id); | ||
Assert.Equal(name, loadedApp.Name); | ||
Assert.Equal(url, loadedApp.SamlSettings!.LoginPageUrl); | ||
|
||
// Update | ||
options = new SamlApplicationOptions(name, url) { Id = id }; | ||
await _descopeClient.Management.SsoApplication.UpdateSamlApplication(options); | ||
|
||
// Load All | ||
var apps = await _descopeClient.Management.SsoApplication.LoadAll(); | ||
loadedApp = apps.Find(a => a.Id == id); | ||
Assert.Equal(name, loadedApp!.Name); | ||
Assert.Equal(url, loadedApp.SamlSettings!.LoginPageUrl); | ||
|
||
// Delete | ||
await _descopeClient.Management.SsoApplication.Delete(id); | ||
id = null; | ||
} | ||
finally | ||
{ | ||
if (!string.IsNullOrEmpty(id)) | ||
{ | ||
try { await _descopeClient.Management.SsoApplication.Delete(id); } | ||
catch { } | ||
} | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task SsoApplication_Oidc() | ||
{ | ||
string? id = null; | ||
try | ||
{ | ||
var name = "name"; | ||
var url = "https://sometestidp.com"; | ||
// Create | ||
var options = new OidcApplicationOptions(name, url); | ||
id = await _descopeClient.Management.SsoApplication.CreateOidcApplication(options); | ||
|
||
// Load | ||
var loadedApp = await _descopeClient.Management.SsoApplication.Load(id); | ||
Assert.Equal(name, loadedApp.Name); | ||
Assert.Equal(url, loadedApp.OidcSettings!.LoginPageUrl); | ||
|
||
// Update | ||
options = new OidcApplicationOptions(name, url) { Id = id }; | ||
await _descopeClient.Management.SsoApplication.UpdateOidcApplication(options); | ||
|
||
// Load All | ||
var apps = await _descopeClient.Management.SsoApplication.LoadAll(); | ||
loadedApp = apps.Find(a => a.Id == id); | ||
Assert.Equal(name, loadedApp!.Name); | ||
Assert.Equal(url, loadedApp.OidcSettings!.LoginPageUrl); | ||
|
||
// Delete | ||
await _descopeClient.Management.SsoApplication.Delete(id); | ||
id = null; | ||
} | ||
finally | ||
{ | ||
if (!string.IsNullOrEmpty(id)) | ||
{ | ||
try { await _descopeClient.Management.SsoApplication.Delete(id); } | ||
catch { } | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
|
||
using System.Text.Json.Serialization; | ||
|
||
namespace Descope.Internal.Management | ||
{ | ||
internal class SsoApplication : ISsoApplication | ||
{ | ||
private readonly IHttpClient _httpClient; | ||
private readonly string _managementKey; | ||
|
||
internal SsoApplication(IHttpClient httpClient, string managementKey) | ||
{ | ||
_httpClient = httpClient; | ||
_managementKey = managementKey; | ||
} | ||
|
||
public async Task<string> CreateOidcApplication(OidcApplicationOptions options) | ||
{ | ||
var resp = await _httpClient.Post<SsoApplicationCreateResponse>(Routes.SsoApplicationOidcCreate, _managementKey, body: options); | ||
return resp.Id; | ||
} | ||
|
||
public async Task<string> CreateSAMLApplication(SamlApplicationOptions options) | ||
{ | ||
var resp = await _httpClient.Post<SsoApplicationCreateResponse>(Routes.SsoApplicationSamlCreate, _managementKey, body: options); | ||
return resp.Id; | ||
} | ||
|
||
public async Task UpdateOidcApplication(OidcApplicationOptions options) | ||
{ | ||
await _httpClient.Post<object>(Routes.SsoApplicationOidcUpdate, _managementKey, body: options); | ||
} | ||
|
||
public async Task UpdateSamlApplication(SamlApplicationOptions options) | ||
{ | ||
await _httpClient.Post<object>(Routes.SsoApplicationSamlUpdate, _managementKey, body: options); | ||
} | ||
|
||
public async Task Delete(string id) | ||
{ | ||
var body = new { id }; | ||
await _httpClient.Post<object>(Routes.SsoApplicationDelete, _managementKey, body: body); | ||
} | ||
|
||
public async Task<SsoApplicationResponse> Load(string id) | ||
{ | ||
return await _httpClient.Get<SsoApplicationResponse>(Routes.SsoApplicationLoad, _managementKey, queryParams: new Dictionary<string, string?> { { "id", id } }); | ||
} | ||
|
||
public async Task<List<SsoApplicationResponse>> LoadAll() | ||
{ | ||
var resp = await _httpClient.Get<SsoLoadAllResponse>(Routes.SsoApplicationLoadAll, _managementKey); | ||
return resp.Apps; | ||
} | ||
|
||
} | ||
|
||
internal class SsoApplicationCreateResponse | ||
{ | ||
[JsonPropertyName("id")] | ||
public string Id { get; set; } | ||
|
||
public SsoApplicationCreateResponse(string id) | ||
{ | ||
Id = id; | ||
} | ||
} | ||
|
||
internal class SsoLoadAllResponse | ||
{ | ||
[JsonPropertyName("apps")] | ||
public List<SsoApplicationResponse> Apps { get; set; } | ||
|
||
public SsoLoadAllResponse(List<SsoApplicationResponse> apps) | ||
{ | ||
Apps = apps; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.