Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,27 @@ public OpenIddictApplicationDescriptor AddAudiencePermissions(params string[] au
return this;
}

/// <summary>
/// Adds grant type permissions for all the specified <paramref name="types"/>.
/// </summary>
/// <param name="types">The grant types for which grant types permissions will be added.</param>
/// <returns>The <see cref="OpenIddictApplicationDescriptor"/> instance.</returns>
/// <exception cref="ArgumentNullException"><paramref name="types"/> is <see langword="null"/>.</exception>
public OpenIddictApplicationDescriptor AddGrantTypePermissions(params string[] types)
{
if (types is null)
{
throw new ArgumentNullException(nameof(types));
}

foreach (var type in types)
{
Permissions.Add(OpenIddictConstants.Permissions.Prefixes.GrantType + type);
}

return this;
}

/// <summary>
/// Adds resource permissions for all the specified <paramref name="resources"/>.
/// </summary>
Expand Down Expand Up @@ -333,6 +354,27 @@ public OpenIddictApplicationDescriptor RemoveAudiencePermissions(params string[]
return this;
}

/// <summary>
/// Removes all the grant type permissions corresponding to the specified <paramref name="types"/>.
/// </summary>
/// <param name="types">The grant types for which grant types permissions will be removed.</param>
/// <returns>The <see cref="OpenIddictApplicationDescriptor"/> instance.</returns>
/// <exception cref="ArgumentNullException"><paramref name="types"/> is <see langword="null"/>.</exception>
public OpenIddictApplicationDescriptor RemoveGrantTypePermissions(params string[] types)
{
if (types is null)
{
throw new ArgumentNullException(nameof(types));
}

foreach (var type in types)
{
Permissions.Remove(OpenIddictConstants.Permissions.Prefixes.GrantType + type);
}

return this;
}

/// <summary>
/// Removes all the resource permissions corresponding to the specified <paramref name="resources"/>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,30 @@ public void AddAudiencePermissions_ThrowsAnExceptionForNullAudiences()
Assert.Throws<ArgumentNullException>(() => descriptor.AddAudiencePermissions(null!));
}

[Fact]
public void AddGrantTypePermissions_AddsPermissions()
{
// Arrange
var descriptor = new OpenIddictApplicationDescriptor();

// Act
descriptor.AddGrantTypePermissions(GrantTypes.Implicit, "custom_grant_type");

// Assert
Assert.Contains(OpenIddictConstants.Permissions.Prefixes.GrantType + GrantTypes.Implicit, descriptor.Permissions);
Assert.Contains(OpenIddictConstants.Permissions.Prefixes.GrantType + "custom_grant_type", descriptor.Permissions);
}

[Fact]
public void AddGrantTypePermissions_ThrowsAnExceptionForNullGrantTypes()
{
// Arrange
var descriptor = new OpenIddictApplicationDescriptor();

// Act and assert
Assert.Throws<ArgumentNullException>(() => descriptor.AddGrantTypePermissions(null!));
}

[Fact]
public void AddResourcePermissions_AddsPermissions()
{
Expand Down Expand Up @@ -270,6 +294,31 @@ public void RemoveAudiencePermissions_ThrowsAnExceptionForNullAudiences()
Assert.Throws<ArgumentNullException>(() => descriptor.RemoveAudiencePermissions(null!));
}

[Fact]
public void RemoveGrantTypePermissions_RemovesPermissions()
{
// Arrange
var descriptor = new OpenIddictApplicationDescriptor();
descriptor.AddGrantTypePermissions(GrantTypes.Implicit, "custom_grant_type");

// Act
descriptor.RemoveGrantTypePermissions(GrantTypes.Implicit);

// Assert
Assert.DoesNotContain(GrantTypes.Implicit, descriptor.Permissions);
Assert.Contains(OpenIddictConstants.Permissions.Prefixes.GrantType + "custom_grant_type", descriptor.Permissions);
}

[Fact]
public void RemoveGrantTypePermissions_ThrowsAnExceptionForNullGrantTypes()
{
// Arrange
var descriptor = new OpenIddictApplicationDescriptor();

// Act and assert
Assert.Throws<ArgumentNullException>(() => descriptor.RemoveGrantTypePermissions(null!));
}

[Fact]
public void RemoveResourcePermissions_RemovesPermissions()
{
Expand Down
Loading