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

feat: OpenIdConnect supports PostgreSQL #744

Merged
merged 1 commit into from
Dec 5, 2024
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
11 changes: 11 additions & 0 deletions Masa.Framework.sln
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Utils.DynamicsCrm.Core
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Utils.DynamicsCrm.EntityFrameworkCore", "src\Utils\DynamicsCrm\Masa.Utils.DynamicsCrm.EntityFrameworkCore\Masa.Utils.DynamicsCrm.EntityFrameworkCore.csproj", "{8A51A2A9-FBF4-40DC-AD89-AD3B9D3A50DC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql", "src\Contrib\Authentication\OpenIdConnect\Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql\Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql.csproj", "{F100414F-CD8D-49D4-BFE0-88D94E53E628}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -2185,6 +2187,14 @@ Global
{8A51A2A9-FBF4-40DC-AD89-AD3B9D3A50DC}.Release|Any CPU.Build.0 = Release|Any CPU
{8A51A2A9-FBF4-40DC-AD89-AD3B9D3A50DC}.Release|x64.ActiveCfg = Release|Any CPU
{8A51A2A9-FBF4-40DC-AD89-AD3B9D3A50DC}.Release|x64.Build.0 = Release|Any CPU
{F100414F-CD8D-49D4-BFE0-88D94E53E628}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F100414F-CD8D-49D4-BFE0-88D94E53E628}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F100414F-CD8D-49D4-BFE0-88D94E53E628}.Debug|x64.ActiveCfg = Debug|Any CPU
{F100414F-CD8D-49D4-BFE0-88D94E53E628}.Debug|x64.Build.0 = Debug|Any CPU
{F100414F-CD8D-49D4-BFE0-88D94E53E628}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F100414F-CD8D-49D4-BFE0-88D94E53E628}.Release|Any CPU.Build.0 = Release|Any CPU
{F100414F-CD8D-49D4-BFE0-88D94E53E628}.Release|x64.ActiveCfg = Release|Any CPU
{F100414F-CD8D-49D4-BFE0-88D94E53E628}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -2493,6 +2503,7 @@ Global
{64B54122-44F1-4379-9422-953EF706A3A6} = {5944A182-13B8-4DA6-AEE2-0A01E64A9648}
{83310F46-E1C7-4438-B32A-9F6F7EA13FCF} = {64B54122-44F1-4379-9422-953EF706A3A6}
{8A51A2A9-FBF4-40DC-AD89-AD3B9D3A50DC} = {64B54122-44F1-4379-9422-953EF706A3A6}
{F100414F-CD8D-49D4-BFE0-88D94E53E628} = {41769FBF-91A8-48D1-B3BB-CAE4C814E7CD}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {40383055-CC50-4600-AD9A-53C14F620D03}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql.EntityConfigurations;

public class ApiResourceClaimEntityTypeConfiguration : IEntityTypeConfiguration<ApiResourceClaim>
{
public void Configure(EntityTypeBuilder<ApiResourceClaim> builder)
{
builder.HasKey(x => x.Id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql.EntityConfigurations;

public class ApiResourceEntityTypeConfiguration : IEntityTypeConfiguration<ApiResource>
{
public void Configure(EntityTypeBuilder<ApiResource> builder)
{
builder.Property(x => x.Name).HasMaxLength(200).IsRequired();
builder.Property(x => x.DisplayName).HasMaxLength(200);
builder.Property(x => x.Description).HasMaxLength(1000);
builder.Property(x => x.AllowedAccessTokenSigningAlgorithms).HasMaxLength(100);
builder.HasIndex(x => x.Name).IsUnique().HasFilter("NOT \"IsDeleted\"");
builder.HasMany(x => x.Secrets).WithOne(x => x.ApiResource).HasForeignKey(x => x.ApiResourceId).OnDelete(DeleteBehavior.Cascade);
builder.HasMany(x => x.ApiScopes).WithOne(x => x.ApiResource).HasForeignKey(x => x.ApiResourceId).IsRequired().OnDelete(DeleteBehavior.Cascade);
builder.HasMany(x => x.UserClaims).WithOne(x => x.ApiResource).HasForeignKey(x => x.ApiResourceId).OnDelete(DeleteBehavior.Cascade);
builder.HasMany(x => x.Properties).WithOne(x => x.ApiResource).HasForeignKey(x => x.ApiResourceId).OnDelete(DeleteBehavior.Cascade);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql.EntityConfigurations;

public class ApiResourcePropertyEntityTypeConfiguration : IEntityTypeConfiguration<ApiResourceProperty>
{
public void Configure(EntityTypeBuilder<ApiResourceProperty> builder)
{
builder.Property(x => x.Key).HasMaxLength(250).IsRequired();
builder.Property(x => x.Value).HasMaxLength(2000).IsRequired();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql.EntityConfigurations;

public class ApiResourceScopeEntityTypeConfiguration : IEntityTypeConfiguration<ApiResourceScope>
{
public void Configure(EntityTypeBuilder<ApiResourceScope> builder)
{
builder.HasKey(apiResourceScope => apiResourceScope.Id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql.EntityConfigurations;

public class ApiResourceSecretEntityTypeConfiguration : IEntityTypeConfiguration<ApiResourceSecret>
{
public void Configure(EntityTypeBuilder<ApiResourceSecret> builder)
{
builder.Property(x => x.Description).HasMaxLength(1000);
builder.Property(x => x.Value).HasMaxLength(4000).IsRequired();
builder.Property(x => x.Type).HasMaxLength(250).IsRequired();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql.EntityConfigurations;

public class ApiScopeClaimEntityTypeConfiguration : IEntityTypeConfiguration<ApiScopeClaim>
{
public void Configure(EntityTypeBuilder<ApiScopeClaim> builder)
{
builder.HasKey(apiScopeClaim => apiScopeClaim.Id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql.EntityConfigurations;

public class ApiScopeEntityTypeConfiguration : IEntityTypeConfiguration<ApiScope>
{
public void Configure(EntityTypeBuilder<ApiScope> builder)
{
builder.HasIndex(apiScope => apiScope.Name).IsUnique();

builder.Property(apiScope => apiScope.Name).HasMaxLength(200).IsRequired();
builder.Property(apiScope => apiScope.DisplayName).HasMaxLength(200);
builder.Property(apiScope => apiScope.Description).HasMaxLength(1000);

builder.HasMany(apiScope => apiScope.UserClaims).WithOne(apiScope => apiScope.ApiScope).HasForeignKey(apiScope => apiScope.ApiScopeId).IsRequired().OnDelete(DeleteBehavior.Cascade);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql.EntityConfigurations;

public class ApiScopePropertyEntityTypeConfiguration : IEntityTypeConfiguration<ApiScopeProperty>
{
public void Configure(EntityTypeBuilder<ApiScopeProperty> builder)
{
builder.Property(x => x.Key).HasMaxLength(250).IsRequired();
builder.Property(x => x.Value).HasMaxLength(2000).IsRequired();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql.EntityConfigurations;

public class ClientClaimEntityTypeConfiguration : IEntityTypeConfiguration<ClientClaim>
{
public void Configure(EntityTypeBuilder<ClientClaim> builder)
{
builder.Property(x => x.Type).HasMaxLength(250).IsRequired();
builder.Property(x => x.Value).HasMaxLength(250).IsRequired();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql.EntityConfigurations;

public class ClientCorsOriginEntityTypeConfiguration : IEntityTypeConfiguration<ClientCorsOrigin>
{
public void Configure(EntityTypeBuilder<ClientCorsOrigin> builder)
{
builder.Property(x => x.Origin).HasMaxLength(150).IsRequired();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql.EntityConfigurations;

public class ClientEntityTypeConfiguration : IEntityTypeConfiguration<Client>
{
public void Configure(EntityTypeBuilder<Client> builder)
{
builder.Property(x => x.ClientId).HasMaxLength(200).IsRequired();
builder.Property(x => x.ProtocolType).HasMaxLength(200).IsRequired();
builder.Property(x => x.ClientName).HasMaxLength(200);
builder.Property(x => x.ClientUri).HasMaxLength(2000);
builder.Property(x => x.LogoUri).HasMaxLength(2000);
builder.Property(x => x.Description).HasMaxLength(1000);
builder.Property(x => x.FrontChannelLogoutUri).HasMaxLength(2000);
builder.Property(x => x.BackChannelLogoutUri).HasMaxLength(2000);
builder.Property(x => x.ClientClaimsPrefix).HasMaxLength(200);
builder.Property(x => x.PairWiseSubjectSalt).HasMaxLength(200);
builder.Property(x => x.UserCodeType).HasMaxLength(100);
builder.Property(x => x.AllowedIdentityTokenSigningAlgorithms).HasMaxLength(100);
builder.HasIndex(x => x.ClientId);
builder.HasIndex(x => x.ClientId).IsUnique().HasFilter("NOT \"IsDeleted\"");

builder.HasMany(x => x.AllowedGrantTypes).WithOne(x => x.Client);
builder.HasMany(x => x.RedirectUris).WithOne(x => x.Client);
builder.HasMany(x => x.PostLogoutRedirectUris).WithOne(x => x.Client);
builder.HasMany(x => x.AllowedScopes).WithOne(x => x.Client);
builder.HasMany(x => x.ClientSecrets).WithOne(x => x.Client);
builder.HasMany(x => x.Claims).WithOne(x => x.Client);
builder.HasMany(x => x.IdentityProviderRestrictions).WithOne(x => x.Client);
builder.HasMany(x => x.AllowedCorsOrigins).WithOne(x => x.Client);
builder.HasMany(x => x.Properties).WithOne(x => x.Client);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql.EntityConfigurations;

public class ClientGrantTypeEntityTypeConfiguration : IEntityTypeConfiguration<ClientGrantType>
{
public void Configure(EntityTypeBuilder<ClientGrantType> builder)
{
builder.Property(x => x.GrantType).HasMaxLength(250).IsRequired();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql.EntityConfigurations;

public class ClientIdPRestrictionEntityTypeConfiguration : IEntityTypeConfiguration<ClientIdPRestriction>
{
public void Configure(EntityTypeBuilder<ClientIdPRestriction> builder)
{
builder.Property(x => x.Provider).HasMaxLength(200).IsRequired();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql.EntityConfigurations;

public class ClientPostLogoutRedirectUriEntityTypeConfiguration : IEntityTypeConfiguration<ClientPostLogoutRedirectUri>
{
public void Configure(EntityTypeBuilder<ClientPostLogoutRedirectUri> builder)
{
builder.HasKey(x => x.Id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql.EntityConfigurations;

public class ClientPropertyEntityTypeConfiguration : IEntityTypeConfiguration<ClientProperty>
{
public void Configure(EntityTypeBuilder<ClientProperty> builder)
{
builder.Property(x => x.Key).HasMaxLength(250).IsRequired();
builder.Property(x => x.Value).HasMaxLength(2000).IsRequired();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql.EntityConfigurations;

public class ClientRedirectUriEntityTypeConfiguration : IEntityTypeConfiguration<ClientRedirectUri>
{
public void Configure(EntityTypeBuilder<ClientRedirectUri> builder)
{
builder.Property(x => x.RedirectUri).HasMaxLength(2000).IsRequired();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql.EntityConfigurations;

public class ClientScopeEntityTypeConfiguration : IEntityTypeConfiguration<ClientScope>
{
public void Configure(EntityTypeBuilder<ClientScope> builder)
{
builder.Property(x => x.Scope).HasMaxLength(200).IsRequired();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql.EntityConfigurations;

public class ClientSecretEntityTypeConfiguration : IEntityTypeConfiguration<ClientSecret>
{
public void Configure(EntityTypeBuilder<ClientSecret> builder)
{
builder.Property(x => x.Value).HasMaxLength(4000).IsRequired();
builder.Property(x => x.Type).HasMaxLength(250).IsRequired();
builder.Property(x => x.Description).HasMaxLength(2000);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql.EntityConfigurations;

public class DeviceFlowCodesEntityTypeConfiguration : IEntityTypeConfiguration<DeviceFlowCodes>
{
public void Configure(EntityTypeBuilder<DeviceFlowCodes> builder)
{
builder.Property(x => x.DeviceCode).HasMaxLength(200).IsRequired();
builder.Property(x => x.UserCode).HasMaxLength(200).IsRequired();
builder.Property(x => x.SubjectId).HasMaxLength(200);
builder.Property(x => x.SessionId).HasMaxLength(100);
builder.Property(x => x.ClientId).HasMaxLength(200).IsRequired();
builder.Property(x => x.Description).HasMaxLength(200);
builder.Property(x => x.CreationTime).IsRequired();
builder.Property(x => x.Expiration).IsRequired();
// 50000 chosen to be explicit to allow enough size to avoid truncation, yet stay beneath the MySql row size limit of ~65K
// apparently anything over 4K converts to nvarchar(max) on SqlServer
builder.Property(x => x.Data).HasMaxLength(50000).IsRequired();

builder.HasKey(x => new { x.UserCode });

builder.HasIndex(x => x.DeviceCode).IsUnique().HasFilter("NOT \"IsDeleted\"");
builder.HasIndex(x => x.Expiration);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql.EntityConfigurations;

public class IdentityResourceClaimEntityTypeConfiguration : IEntityTypeConfiguration<IdentityResourceClaim>
{
public void Configure(EntityTypeBuilder<IdentityResourceClaim> builder)
{
builder.HasKey(identityResourceClaim => identityResourceClaim.Id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql.EntityConfigurations;

public class IdentityResourceEntityTypeConfiguration : IEntityTypeConfiguration<IdentityResource>
{
public void Configure(EntityTypeBuilder<IdentityResource> builder)
{
builder.Property(x => x.Name).HasMaxLength(200).IsRequired();
builder.Property(x => x.DisplayName).HasMaxLength(200);
builder.Property(x => x.Description).HasMaxLength(1000);
builder.HasIndex(x => x.Name).IsUnique().HasFilter("NOT \"IsDeleted\"");

builder.HasMany(x => x.UserClaims).WithOne(x => x.IdentityResource).HasForeignKey(x => x.IdentityResourceId).IsRequired().OnDelete(DeleteBehavior.Cascade);
builder.HasMany(x => x.Properties).WithOne(x => x.IdentityResource).HasForeignKey(x => x.IdentityResourceId).IsRequired().OnDelete(DeleteBehavior.Cascade);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Authentication.OpenIdConnect.EFCore.PostgreSql.EntityConfigurations;

public class IdentityResourcePropertyEntityTypeConfiguration : IEntityTypeConfiguration<IdentityResourceProperty>
{
public void Configure(EntityTypeBuilder<IdentityResourceProperty> builder)
{
builder.Property(x => x.Key).HasMaxLength(250).IsRequired();
builder.Property(x => x.Value).HasMaxLength(2000).IsRequired();
}
}
Loading
Loading