Skip to content

Commit

Permalink
applied dotnet format
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasduft committed Mar 27, 2024
1 parent c7bedd0 commit c1de25a
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 113 deletions.
6 changes: 3 additions & 3 deletions samples/Server/ConfigureServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ string environmentName
.AddUIApis(options =>
{
// Tell the system about the allowed Permissions it is built/configured for.
options.Permissions = new List<string>
{
options.Permissions =
[
Permissions.Endpoints.Authorization,
Permissions.Endpoints.Logout,
Permissions.Endpoints.Token,
Expand All @@ -184,7 +184,7 @@ string environmentName
Permissions.Scopes.Roles,
Permissions.Prefixes.Scope + "server_scope",
Permissions.Prefixes.Scope + "api_scope"
};
];
})
// Register the EF based UI Store for the ASP.NET Identity related entities.
.AddUIIdentityStore<ApplicationUser>(options =>
Expand Down
56 changes: 28 additions & 28 deletions samples/Server/Controllers/AuthorizationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public async Task<IActionResult> Authorize()
properties: new AuthenticationProperties
{
RedirectUri = Request.PathBase + Request.Path + QueryString.Create(
Request.HasFormContentType ? Request.Form.ToList() : Request.Query.ToList())
Request.HasFormContentType ? Request.Form.ToList() : [.. Request.Query])
});
}

Expand All @@ -80,13 +80,13 @@ public async Task<IActionResult> Authorize()
var prompt = string.Join(" ", request.GetPrompts().Remove(Prompts.Login));

var parameters = Request.HasFormContentType ?
Request.Form.Where(parameter =>
{
return parameter.Key != Parameters.Prompt;
Request.Form.Where(parameter =>
{
return parameter.Key != Parameters.Prompt;
}).ToList() :
Request.Query.Where(parameter =>
{
return parameter.Key != Parameters.Prompt;
Request.Query.Where(parameter =>
{
return parameter.Key != Parameters.Prompt;
}).ToList();

parameters.Add(KeyValuePair.Create(Parameters.Prompt, new StringValues(prompt)));
Expand Down Expand Up @@ -120,7 +120,7 @@ public async Task<IActionResult> Authorize()
properties: new AuthenticationProperties
{
RedirectUri = Request.PathBase + Request.Path + QueryString.Create(
Request.HasFormContentType ? Request.Form.ToList() : Request.Query.ToList())
Request.HasFormContentType ? Request.Form.ToList() : [.. Request.Query])
});
}

Expand All @@ -144,7 +144,7 @@ public async Task<IActionResult> Authorize()
{
// If the consent is external (e.g when authorizations are granted by a sysadmin),
// immediately return an error if no authorization can be found in the database.
case ConsentTypes.External when !authorizations.Any():
case ConsentTypes.External when authorizations.Count == 0:
return Forbid(
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme,
properties: new AuthenticationProperties(new Dictionary<string, string>
Expand All @@ -157,8 +157,8 @@ public async Task<IActionResult> Authorize()
// If the consent is implicit or if an authorization was found,
// return an authorization response without displaying the consent form.
case ConsentTypes.Implicit:
case ConsentTypes.External when authorizations.Any():
case ConsentTypes.Explicit when authorizations.Any() && !request.HasPrompt(Prompts.Consent):
case ConsentTypes.External when authorizations.Count != 0:
case ConsentTypes.Explicit when authorizations.Count != 0 && !request.HasPrompt(Prompts.Consent):
var principal = await _signInManager.CreateUserPrincipalAsync(user);

// Note: in this sample, the granted scopes match the requested scope
Expand Down Expand Up @@ -241,7 +241,7 @@ public async Task<IActionResult> Accept()
// Note: the same check is already made in the other action but is repeated
// here to ensure a malicious user can't abuse this POST-only endpoint and
// force it to return a valid response without the external authorization.
if (!authorizations.Any() && await _applicationManager.HasConsentTypeAsync(application, ConsentTypes.External))
if (authorizations.Count == 0 && await _applicationManager.HasConsentTypeAsync(application, ConsentTypes.External))
{
return Forbid(
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme,
Expand Down Expand Up @@ -426,35 +426,35 @@ private static IEnumerable<string> GetDestinations(Claim claim, ClaimsPrincipal
case Claims.Name:
yield return Destinations.AccessToken;

if (principal.HasScope(Scopes.Profile))
{
yield return Destinations.IdentityToken;
}

if (principal.HasScope(Scopes.Profile))
{
yield return Destinations.IdentityToken;
}

yield break;

case Claims.Email:
yield return Destinations.AccessToken;

if (principal.HasScope(Scopes.Email))
{
yield return Destinations.IdentityToken;
}

if (principal.HasScope(Scopes.Email))
{
yield return Destinations.IdentityToken;
}

yield break;

case Claims.Role:
yield return Destinations.AccessToken;

if (principal.HasScope(Scopes.Roles))
{
yield return Destinations.IdentityToken;
}

if (principal.HasScope(Scopes.Roles))
{
yield return Destinations.IdentityToken;
}

yield break;

// Never include the security stamp in the access and identity tokens, as it's a secret value.
case "AspNet.Identity.SecurityStamp":
case "AspNet.Identity.SecurityStamp":
yield break;

default:
Expand Down
108 changes: 53 additions & 55 deletions samples/Server/Models/Data/UI/20231220090227_OpenIddict5Support.cs
Original file line number Diff line number Diff line change
@@ -1,59 +1,57 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Server.Models.Data.UI
namespace Server.Models.Data.UI;

/// <inheritdoc />
public partial class OpenIddict5Support : Migration
{
/// <inheritdoc />
public partial class OpenIddict5Support : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "Type",
table: "OpenIddictApplications",
newName: "ClientType");

migrationBuilder.AddColumn<string>(
name: "ApplicationType",
table: "OpenIddictApplications",
type: "TEXT",
maxLength: 50,
nullable: true);

migrationBuilder.AddColumn<string>(
name: "JsonWebKeySet",
table: "OpenIddictApplications",
type: "TEXT",
nullable: true);

migrationBuilder.AddColumn<string>(
name: "Settings",
table: "OpenIddictApplications",
type: "TEXT",
nullable: true);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ApplicationType",
table: "OpenIddictApplications");

migrationBuilder.DropColumn(
name: "JsonWebKeySet",
table: "OpenIddictApplications");

migrationBuilder.DropColumn(
name: "Settings",
table: "OpenIddictApplications");

migrationBuilder.RenameColumn(
name: "ClientType",
table: "OpenIddictApplications",
newName: "Type");
}
}
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "Type",
table: "OpenIddictApplications",
newName: "ClientType");

migrationBuilder.AddColumn<string>(
name: "ApplicationType",
table: "OpenIddictApplications",
type: "TEXT",
maxLength: 50,
nullable: true);

migrationBuilder.AddColumn<string>(
name: "JsonWebKeySet",
table: "OpenIddictApplications",
type: "TEXT",
nullable: true);

migrationBuilder.AddColumn<string>(
name: "Settings",
table: "OpenIddictApplications",
type: "TEXT",
nullable: true);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ApplicationType",
table: "OpenIddictApplications");

migrationBuilder.DropColumn(
name: "JsonWebKeySet",
table: "OpenIddictApplications");

migrationBuilder.DropColumn(
name: "Settings",
table: "OpenIddictApplications");

migrationBuilder.RenameColumn(
name: "ClientType",
table: "OpenIddictApplications",
newName: "Type");
}
}
10 changes: 3 additions & 7 deletions src/identity/OpenIddict.UI.Identity.Api/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,9 @@ private static IServiceCollection AddAuthorizationServices(
Action<AuthorizationPolicyBuilder> policy
)
{
services.AddAuthorization(options =>
{
options.AddPolicy(
Policies.OpenIddictUiIdentityApiPolicy,
policy
);
});
services.AddAuthorizationBuilder()
.AddPolicy(Policies.OpenIddictUiIdentityApiPolicy, policy
);

return services;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public async Task<UserInfo> GetUserAsync(string id)
Value = x.Value
};
})),
Roles = roles.ToList()
Roles = [.. roles]
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using tomware.OpenIddict.UI.Infrastructure;
using tomware.OpenIddict.UI.Suite.Core;

namespace tomware.OpenIddict.UI.Api;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ namespace tomware.OpenIddict.UI.Api;

public class ApplicationOptionsViewModel
{
public List<string> Permissions { get; set; } = new List<string>();
public List<string> Permissions { get; set; } = [];

public List<string> Requirements { get; set; } = new List<string>();
public List<string> Requirements { get; set; } = [];

public List<string> Types { get; set; } = new List<string>{
public List<string> Types { get; set; } = [
ClientTypes.Public,
ClientTypes.Confidential
};
];
}
10 changes: 3 additions & 7 deletions src/openiddict/OpenIddict.UI.Api/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,9 @@ private static IServiceCollection AddAuthorizationServices(
Action<AuthorizationPolicyBuilder> policy
)
{
services.AddAuthorization(options =>
{
options.AddPolicy(
Policies.OpenIddictUiApiPolicy,
policy
);
});
services.AddAuthorizationBuilder()
.AddPolicy(Policies.OpenIddictUiApiPolicy, policy
);

return services;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class OpenIddictUIApiOptions
/// <summary>
/// Tell the system about the allowed Permissions it is built/configured for.
/// </summary>
public List<string> Permissions { get; set; } = new List<string>();
public List<string> Permissions { get; set; } = [];

/// <summary>
/// Registers a conventional route prefix for the API controllers. Defaults to "api/".
Expand Down
2 changes: 1 addition & 1 deletion src/openiddict/OpenIddict.UI.Api/Scope/ScopeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public class ScopeViewModel

public string Description { get; set; }

public List<string> Resources { get; set; } = new List<string>();
public List<string> Resources { get; set; } = [];
}
2 changes: 1 addition & 1 deletion tests/Helpers/IntegrationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected IntegrationContext(IntegrationApplicationFactory<Testing> factory)
_accessToken = _factory.AccessToken;
}

protected static T Deserialize<T>(string responseBody)
protected static T Deserialize<T>(string responseBody)
=> JsonSerializer.Deserialize<T>(responseBody, JsonSerializerOptions);

protected async Task<HttpResponseMessage> GetAsync(
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/ApplicationApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public async Task UpdateConfidentialApplicationApplicationIsNotUpdated()
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
}

[Fact(Skip = "There seems to be a bug when using InMemoryDatabase.")]
[Fact]
public async Task DeleteAsyncApplicationDeleted()
{
// Arrange
Expand Down
6 changes: 3 additions & 3 deletions tests/Integration/ScopeApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ public async Task GetAsyncRoleReceived()
Name = TEST_SCOPE,
DisplayName = "displayname",
Description = "description",
Resources = new List<string>
{
Resources =
[
"resource1",
"resource2"
}
]
});
var id = await createResponse.Content.ReadAsJsonAsync<string>();

Expand Down

0 comments on commit c1de25a

Please sign in to comment.