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

OKTA-295706 add usertypes #378

Merged
merged 7 commits into from May 18, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/Okta.Sdk.IntegrationTests/ApplicationScenarios.cs
Expand Up @@ -372,11 +372,12 @@ public async Task AddOpenIdConnectApp()
{
var client = TestClient.Create();
var guid = Guid.NewGuid();
var testClientId = $"{nameof(AddOpenIdConnectApp)}_TestClientId";

var createdApp = await client.Applications.CreateApplicationAsync(new CreateOpenIdConnectApplication
{
Label = $"dotnet-sdk: AddOpenIdConnectApp {guid}",
ClientId = "0oae8mnt9tZcGcMXG0h3",
ClientId = testClientId,
bryanapellanes-okta marked this conversation as resolved.
Show resolved Hide resolved
TokenEndpointAuthMethod = OAuthEndpointAuthenticationMethod.ClientSecretPost,
AutoKeyRotation = true,
ClientUri = "https://example.com/client",
Expand Down Expand Up @@ -413,7 +414,7 @@ public async Task AddOpenIdConnectApp()
retrieved.Name.Should().Be("oidc_client");
retrieved.Label.Should().Be($"dotnet-sdk: AddOpenIdConnectApp {guid}");
retrieved.SignOnMode.Should().Be(ApplicationSignOnMode.OpenIdConnect);
retrieved.Credentials.OauthClient.ClientId.Should().Be("0oae8mnt9tZcGcMXG0h3");
retrieved.Credentials.OauthClient.ClientId.Should().Be(testClientId);
retrieved.Credentials.OauthClient.AutoKeyRotation.Should().BeTrue();
retrieved.Credentials.OauthClient.TokenEndpointAuthMethod.Should().Be(OAuthEndpointAuthenticationMethod.ClientSecretPost);

Expand Down Expand Up @@ -1626,11 +1627,12 @@ public async Task GrantConsentToScope()
{
var client = TestClient.Create();
var guid = Guid.NewGuid();
var testClientId = $"{nameof(GrantConsentToScope)}_TestClientId";

var createdApp = await client.Applications.CreateApplicationAsync(new CreateOpenIdConnectApplication
{
Label = $"dotnet-sdk: GrantConsentToScope {guid}",
ClientId = "0oae8mnt9tZcGcMXG0h3",
ClientId = testClientId,
TokenEndpointAuthMethod = OAuthEndpointAuthenticationMethod.ClientSecretPost,
AutoKeyRotation = true,
ClientUri = "https://example.com/client",
Expand Down Expand Up @@ -1689,11 +1691,12 @@ public async Task GetConsentGrant()
{
var client = TestClient.Create();
var guid = Guid.NewGuid();
var testClientId = $"{nameof(GetConsentGrant)}_TestClientId";

var createdApp = await client.Applications.CreateApplicationAsync(new CreateOpenIdConnectApplication
{
Label = $"dotnet-sdk: GetConsentGrant {guid}",
ClientId = "0oae8mnt9tZcGcMXG0h3",
ClientId = testClientId,
TokenEndpointAuthMethod = OAuthEndpointAuthenticationMethod.ClientSecretPost,
AutoKeyRotation = true,
ClientUri = "https://example.com/client",
Expand Down Expand Up @@ -1751,11 +1754,12 @@ public async Task RevokeConsentGrant()
{
var client = TestClient.Create();
var guid = Guid.NewGuid();
var testClientId = $"{nameof(RevokeConsentGrant)}_TestClientId";

var createdApp = await client.Applications.CreateApplicationAsync(new CreateOpenIdConnectApplication
{
Label = $"dotnet-sdk: RevokeConsentGrant {guid}",
ClientId = "0oae8mnt9tZcGcMXG0h3",
ClientId = testClientId,
TokenEndpointAuthMethod = OAuthEndpointAuthenticationMethod.ClientSecretPost,
AutoKeyRotation = true,
ClientUri = "https://example.com/client",
Expand Down
269 changes: 269 additions & 0 deletions src/Okta.Sdk.IntegrationTests/UserTypesClientShould.cs
@@ -0,0 +1,269 @@
// <copyright file="UserTypesClientShould.cs" company="Okta, Inc">
// Copyright (c) 2014 - present Okta, Inc. All rights reserved.
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.
// </copyright>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using FluentAssertions;
using Xunit;

namespace Okta.Sdk.IntegrationTests
{
public class UserTypesClientShould
{
private const string SdkPrefix = "dotnet_sdk";

public UserTypesClientShould()
{
DeleteAllUserTypes().Wait();
}

[Fact]
public async Task CreateUserType()
{
var testClient = TestClient.Create();

var testDescription = $"{SdkPrefix}:{nameof(CreateUserType)} Test Description";
var testDisplayName = $"{SdkPrefix}:{nameof(CreateUserType)} Test DisplayName";
var testName = $"{SdkPrefix}_{nameof(CreateUserType)}_TestUserType";

var createdUserType = await testClient.UserTypes.CreateUserTypeAsync(new UserType
{
Description = testDescription,
DisplayName = testDisplayName,
Name = testName,
});

try
{
createdUserType.Id.Should().NotBeNullOrEmpty();
createdUserType.Description.Should().Be(testDescription);
createdUserType.DisplayName.Should().Be(testDisplayName);
createdUserType.Name.Should().Be(testName);
}
finally
{
await DeleteAllUserTypes();
}
}

[Fact]
public async Task RetrieveUserTypeById()
{
var testClient = TestClient.Create();

var testDescription = $"{SdkPrefix}:{nameof(RetrieveUserTypeById)} Test Description";
var testDisplayName = $"{SdkPrefix}:{nameof(RetrieveUserTypeById)} Test DisplayName";
var testName = $"{SdkPrefix}{nameof(RetrieveUserTypeById)}_TestUserType";

var createdUserType = await testClient.UserTypes.CreateUserTypeAsync(new UserType
{
Description = testDescription,
DisplayName = testDisplayName,
Name = testName,
});

try
{
createdUserType.Id.Should().NotBeNullOrEmpty();

var retrievedUserType = await testClient.UserTypes.GetUserTypeAsync(createdUserType.Id);
retrievedUserType.Should().NotBeNull();
retrievedUserType.Id.Should().Be(createdUserType.Id);
retrievedUserType.Description.Should().Be(testDescription);
retrievedUserType.DisplayName.Should().Be(testDisplayName);
}
finally
{
await DeleteAllUserTypes();
}
}

[Fact]
public async Task UpdateUserType()
{
var testClient = TestClient.Create();

var testDescription = $"{SdkPrefix}:{nameof(UpdateUserType)} Test Description";
var testDisplayName = $"{SdkPrefix}:{nameof(UpdateUserType)} Test DisplayName";
var testName = $"{SdkPrefix}_{nameof(UpdateUserType)}_TestUserType";

var createdUserType = await testClient.UserTypes.CreateUserTypeAsync(new UserType
{
Description = testDescription,
DisplayName = testDisplayName,
Name = testName,
});

try
{
createdUserType.Id.Should().NotBeNullOrEmpty();

var updatedDescription = $"{createdUserType.Description} Updated";
var updatedDisplayName = $"{createdUserType.Description} Updated";

var updatesToUserType = new UserType
{
Description = updatedDescription,
DisplayName = updatedDisplayName,
};

var updatedUserType = await testClient.UserTypes.UpdateUserTypeAsync(updatesToUserType, createdUserType.Id);
updatedUserType.Id.Should().Be(createdUserType.Id);
updatedUserType.Description.Should().Be(updatedDescription);
updatedUserType.DisplayName.Should().Be(updatedDisplayName);

var retrievedUserTypeForValidation = await testClient.UserTypes.GetUserTypeAsync(createdUserType.Id);
retrievedUserTypeForValidation.Id.Should().Be(createdUserType.Id);
retrievedUserTypeForValidation.Description.Should().Be(updatedDescription);
retrievedUserTypeForValidation.DisplayName.Should().Be(updatedDisplayName);
}
finally
{
await DeleteAllUserTypes();
}
}

[Fact]
public async Task ReplaceUserType()
{
var testClient = TestClient.Create();
var testDescription = $"{SdkPrefix}:{nameof(ReplaceUserType)} Test Description";
var testDisplayName = $"{SdkPrefix}:{nameof(ReplaceUserType)} Test DisplayName";
var testName = $"{SdkPrefix}_{nameof(ReplaceUserType)}_TestUserType";

var createdUserType = await testClient.UserTypes.CreateUserTypeAsync(new UserType()
{
Description = testDescription,
DisplayName = testDisplayName,
Name = testName,
});

try
{
createdUserType.Id.Should().NotBeNullOrEmpty();

var replacedDescription = $"{createdUserType.Description} Repl"; // maximum length is 50
var replacedDisplayName = $"{createdUserType.DisplayName} Repl";

var replacedUserType = await testClient.UserTypes.ReplaceUserTypeAsync(
new UserType()
{
Description = replacedDescription,
DisplayName = replacedDisplayName,
Name = testName,
}, createdUserType.Id);

replacedUserType.Id.Should().Be(createdUserType.Id);
replacedUserType.Description.Should().Be(replacedDescription);
replacedUserType.DisplayName.Should().Be(replacedDisplayName);
replacedUserType.Name.Should().Be(testName);

var retrievedUserTypeForValidation = await testClient.UserTypes.GetUserTypeAsync(createdUserType.Id);
retrievedUserTypeForValidation.Id.Should().Be(createdUserType.Id);
retrievedUserTypeForValidation.Description.Should().Be(replacedDescription);
retrievedUserTypeForValidation.DisplayName.Should().Be(replacedDisplayName);
}
finally
{
await DeleteAllUserTypes();
}
}


[Fact]
public async Task DeleteUserTypeById()
{
var testClient = TestClient.Create();
var testDescription = $"{SdkPrefix}:{nameof(DeleteUserTypeById)} Test Description";
var testDisplayName = $"{SdkPrefix}:{nameof(DeleteUserTypeById)} Test DisplayName";
var testName = $"{SdkPrefix}_{nameof(DeleteUserTypeById)}_TestUserType";

var createdUserType = await testClient.UserTypes.CreateUserTypeAsync(new UserType
{
Description = testDescription,
DisplayName = testDisplayName,
Name = testName,
});

try
{
createdUserType.Id.Should().NotBeNullOrEmpty();

var retrievedUserType = await testClient.UserTypes.GetUserTypeAsync(createdUserType.Id);
retrievedUserType.Id.Should().Be(createdUserType.Id);

await testClient.UserTypes.DeleteUserTypeAsync(createdUserType.Id);

var ex = await Assert.ThrowsAsync<OktaApiException>(() =>
testClient.UserTypes.GetUserTypeAsync(createdUserType.Id));
ex.StatusCode.Should().Be(404);
}
finally
{
await DeleteAllUserTypes();
}
}

[Fact]
public async Task ListAllUserTypes()
{
var testClient = TestClient.Create();
var existingUserTypeIds = new HashSet<string>();
await foreach (IUserType existingUserType in testClient.UserTypes.ListUserTypes())
{
existingUserTypeIds.Add(existingUserType.Id);
}

var testUserTypeIds = new HashSet<string>();
for (int i = 0; i < 5; i++)
{
var createdUserType = await testClient.UserTypes.CreateUserTypeAsync(new UserType()
{
Description = $"{nameof(ListAllUserTypes)} Test Description ({i})",
DisplayName = $"{nameof(ListAllUserTypes)} Test DisplayName ({i})",
Name = $"{nameof(ListAllUserTypes)}_TestUserType_{i}",
});
testUserTypeIds.Add(createdUserType.Id);
}

try
{
var allUserTypeIds = new HashSet<string>();
var allUserTypes = testClient.UserTypes.ListUserTypes();
int allUserTypesCount = await allUserTypes.CountAsync();
allUserTypesCount.Should().BeGreaterThan(0);
allUserTypesCount.Should().Be(existingUserTypeIds.Count + testUserTypeIds.Count);

await foreach (IUserType userType in allUserTypes)
{
allUserTypeIds.Add(userType.Id);
}

foreach (string testUserTypeId in testUserTypeIds)
{
Assert.Contains(testUserTypeId, allUserTypeIds);
}
}
finally
{
await DeleteAllUserTypes();
}
}

private async Task DeleteAllUserTypes()
{
var testClient = TestClient.Create();
await foreach (IUserType userType in testClient.UserTypes.ListUserTypes())
{
if (userType.Default != null && !userType.Default.Value)
{
await testClient.UserTypes.DeleteUserTypeAsync(userType.Id);
}
}
}
}
}
5 changes: 4 additions & 1 deletion src/Okta.Sdk/Generated/IIdentityProvider.Generated.cs
Expand Up @@ -54,6 +54,9 @@ public partial interface IIdentityProvider : IResource
Task<IJsonWebKey> GetSigningKeyAsync(
string keyId, CancellationToken cancellationToken = default(CancellationToken));

Task DeleteSigningKeyAsync(
string keyId, CancellationToken cancellationToken = default(CancellationToken));

Task<IJsonWebKey> CloneKeyAsync(
string keyId, string targetIdpId, CancellationToken cancellationToken = default(CancellationToken));

Expand All @@ -70,7 +73,7 @@ public partial interface IIdentityProvider : IResource
string userId, CancellationToken cancellationToken = default(CancellationToken));

Task<IIdentityProviderApplicationUser> GetUserAsync(
string idpId, string userId, CancellationToken cancellationToken = default(CancellationToken));
string userId, CancellationToken cancellationToken = default(CancellationToken));

Task<IIdentityProviderApplicationUser> LinkUserAsync(IUserIdentityProviderLinkRequest userIdentityProviderLinkRequest,
string userId, CancellationToken cancellationToken = default(CancellationToken));
Expand Down
8 changes: 0 additions & 8 deletions src/Okta.Sdk/Generated/IUsersClient.Generated.cs
Expand Up @@ -39,14 +39,6 @@ public partial interface IUsersClient
/// <returns>The <see cref="IUser"/> response.</returns>
Task<IUser> CreateUserAsync(ICreateUserRequest body, bool? activate = true, bool? provider = false, UserNextLogin nextLogin = null, CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// Clears Okta sessions for the currently logged in user. By default, the current session remains active. Use this method in a browser-based application.
/// </summary>
/// <param name="keepCurrent"></param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A Task that represents the asynchronous operation.</returns>
Task ClearCurrentUserSessionsAsync(bool? keepCurrent = true, CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
///
/// </summary>
Expand Down
9 changes: 7 additions & 2 deletions src/Okta.Sdk/Generated/IdentityProvider.Generated.cs
Expand Up @@ -102,6 +102,11 @@ public string Type
string keyId, CancellationToken cancellationToken = default(CancellationToken))
=> GetClient().IdentityProviders.GetIdentityProviderSigningKeyAsync(Id, keyId, cancellationToken);

/// <inheritdoc />
public Task DeleteSigningKeyAsync(
string keyId, CancellationToken cancellationToken = default(CancellationToken))
=> GetClient().IdentityProviders.DeleteIdentityProviderKeyAsync(keyId, cancellationToken);

/// <inheritdoc />
public Task<IJsonWebKey> CloneKeyAsync(
string keyId, string targetIdpId, CancellationToken cancellationToken = default(CancellationToken))
Expand Down Expand Up @@ -129,8 +134,8 @@ public string Type

/// <inheritdoc />
public Task<IIdentityProviderApplicationUser> GetUserAsync(
string idpId, string userId, CancellationToken cancellationToken = default(CancellationToken))
=> GetClient().IdentityProviders.GetIdentityProviderApplicationUserAsync(idpId, userId, cancellationToken);
string userId, CancellationToken cancellationToken = default(CancellationToken))
=> GetClient().IdentityProviders.GetIdentityProviderApplicationUserAsync(Id, userId, cancellationToken);

/// <inheritdoc />
public Task<IIdentityProviderApplicationUser> LinkUserAsync(IUserIdentityProviderLinkRequest userIdentityProviderLinkRequest,
Expand Down