Skip to content
Open
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
15 changes: 13 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,26 @@
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/<target-framework>/<project-name.dll>",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"console": "internalConsole"
},
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/src/Host/IdentityServer.Dapper.Test/bin/Debug/netcoreapp2.1/IdentityServer.Dapper.Test.dll",
"program": "${workspaceFolder}/src/Host/IdentityServer4.Dapper.Host/bin/Debug/netcoreapp3.1/IdentityServer4.Dapper.Host.dll",
"args": [],
"cwd": "${workspaceFolder}/src/Host/IdentityServer.Dapper.Test",
"cwd": "${workspaceFolder}/src/Host/IdentityServer4.Dapper.Host",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"launchBrowser": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<IsPackable>false</IsPackable>
Expand All @@ -10,8 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.1.8" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.7.0" />
<PackageReference Include="OneSmart.Core" Version="1.1.4" />
Expand All @@ -26,6 +25,7 @@

<ItemGroup>
<ProjectReference Include="..\..\IdentityServer4.Dapper.Mysql\IdentityServer4.Dapper.MySql.csproj" />
<ProjectReference Include="..\..\IdentityServer4.Dapper.PostgreSQL\IdentityServer4.Dapper.PostgreSQL.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
21 changes: 13 additions & 8 deletions src/Host/IdentityServer4.Dapper.Host/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.SpaServices;
using Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer;
using IdentityServer4.Dapper.Extensions.MySql;
using IdentityServer4.Dapper.Extensions.PostgreSQL;
using IdentityServer4.Dapper.Extensions;

namespace IdentityServer4.Dapper.Host
Expand Down Expand Up @@ -33,9 +35,10 @@ public void ConfigureServices(IServiceCollection services)
});
services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddMySQLProvider(option =>
.AddPostgreSQLProvider(option =>
{
option.ConnectionString = "server=.;uid=darinhan;pwd=darinhan;database=identityserver4;SslMode=None;";
//option.ConnectionString = "server=.;uid=darinhan;pwd=darinhan;database=identityserver4;SslMode=None;";
option.ConnectionString = "Host=localhost;Port=32676;Username=postgresadmin;Password=admin123;Database=postgresdb;Minimum Pool Size=5;Search Path=identityserver";
})
.AddConfigurationStore()
.AddOperationalStore(option =>
Expand All @@ -44,7 +47,9 @@ public void ConfigureServices(IServiceCollection services)
option.TokenCleanupInterval = 10;
});

services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddMvc(options => {
options.EnableEndpointRouting = false;
});

// In production, the React files will be served from this directory
services.AddSpaStaticFiles(configuration =>
Expand All @@ -54,9 +59,9 @@ public void ConfigureServices(IServiceCollection services)
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
if (env.EnvironmentName.Equals("Development"))
{
app.UseDeveloperExceptionPage();
}
Expand All @@ -81,10 +86,10 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
spa.Options.SourcePath = "ClientApp";

spa.UseProxyToSpaDevelopmentServer("http://localhost:7012");
//spa.UseProxyToSpaDevelopmentServer("http://localhost:7012");
//if (env.IsDevelopment())
//{
// spa.UseReactDevelopmentServer(npmScript: "start");
spa.UseReactDevelopmentServer(npmScript: "start");
//}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
2020-09-23 16:07:10.0701 Info Message Template Auto Format enabled
2020-09-23 16:07:10.0917 Info Loading assembly: NLog.Web.AspNetCore
2020-09-23 16:07:10.1533 Info Adding target File Target[allfile]
2020-09-23 16:07:10.1686 Info Adding target File Target[ownFile-web]
2020-09-23 16:07:10.1741 Info Configured from an XML element in /Users/henry/Develop/IdentityServer4.Dapper/src/Host/IdentityServer4.Dapper.Host/bin/Debug/netcoreapp3.1/nlog.config...
2020-09-23 16:07:10.1870 Info Found 47 configuration items
2020-09-23 16:07:49.6776 Info Message Template Auto Format enabled
2020-09-23 16:07:49.6988 Info Loading assembly: NLog.Web.AspNetCore
2020-09-23 16:07:49.7595 Info Adding target File Target[allfile]
2020-09-23 16:07:49.7691 Info Adding target File Target[ownFile-web]
2020-09-23 16:07:49.7747 Info Configured from an XML element in /Users/henry/Develop/IdentityServer4.Dapper/src/Host/IdentityServer4.Dapper.Host/bin/Debug/netcoreapp3.1/nlog.config...
2020-09-23 16:07:49.7860 Info Found 47 configuration items
2020-09-23 16:15:27.0388 Info Message Template Auto Format enabled
2020-09-23 16:15:27.0683 Info Loading assembly: NLog.Web.AspNetCore
2020-09-23 16:15:27.1527 Info Adding target File Target[allfile]
2020-09-23 16:15:27.1661 Info Adding target File Target[ownFile-web]
2020-09-23 16:15:27.1728 Info Configured from an XML element in /Users/henry/Develop/IdentityServer4.Dapper/src/Host/IdentityServer4.Dapper.Host/bin/Debug/netcoreapp3.1/nlog.config...
2020-09-23 16:15:27.1870 Info Found 47 configuration items
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="MySql.Data" Version="8.0.13" />
<PackageReference Include="MySql.Data" Version="8.0.21" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\IdentityServer4.Dapper.MSSql\IdentityServer4.Dapper.MSSql.csproj" />
<ProjectReference Include="..\IdentityServer4.Dapper.Mysql\IdentityServer4.Dapper.MySql.csproj" />
<ProjectReference Include="..\IdentityServer4.Dapper.PostgreSQL\IdentityServer4.Dapper.PostgreSQL.csproj" />
<ProjectReference Include="..\IdentityServer4.Dapper\IdentityServer4.Dapper.csproj" />
</ItemGroup>

Expand Down
13 changes: 11 additions & 2 deletions src/IdentityServer.Dapper.xUnitTest/xTestBase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using MySqlN = IdentityServer4.Dapper.Extensions.MySql;
using MSSqlN = IdentityServer4.Dapper.Extensions.MSSql;
using PostgreSqlN = IdentityServer4.Dapper.Extensions.PostgreSQL;
using IdentityServer4.Dapper.Options;
using System;
using System.Collections.Generic;
Expand All @@ -14,19 +15,27 @@ class xTestBase
{
public const string MSSQL = "MSSQL";
public const string MySQL = "MySQL";
public const string PostgreSQL = "PostgreSQL";

public static DBProviderOptions GetDBProviderOptions(string type)
{
DBProviderOptions options = null;
if (type == MySQL)
{
options = MySqlN.IdentityServerDapperDBExtensions.GetDefaultOptions();
options.ConnectionString = "server=10.40.0.190;uid=changyin.han;pwd=fjfhhan07;database=identityserver4dev;SslMode=None;";
//options.ConnectionString = "server=10.40.0.190;uid=changyin.han;pwd=fjfhhan07;database=identityserver4dev;SslMode=None;";
options.ConnectionString = "server=localhost;uid=idadmin;pwd=admin123;database=identityserver;SslMode=None;";
}
else if (type == MSSQL)
{
options = MSSqlN.IdentityServerDapperDBExtensions.GetDefaultOptions();
options.ConnectionString = "server=10.40.0.190;uid=sa;pwd=Onesmart190;database=identityserver4;";
//options.ConnectionString = "server=10.40.0.190;uid=sa;pwd=Onesmart190;database=identityserver4;";
options.ConnectionString = "server=localhost;uid=sa;pwd=Saiahcsep2020@;database=identityserver;";
}
else if (type == PostgreSQL)
{
options = PostgreSqlN.IdentityServerDapperDBExtensions.GetDefaultOptions();
options.ConnectionString = "Host=localhost;Port=32676;Username=postgresadmin;Password=admin123;Database=postgresdb;Minimum Pool Size=5;Search Path=identityserver";
}

return options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ private DefaultApiResourceProvider GetDefaultApiResourceProvider(string sqltype)
[Theory]
[InlineData(xTestBase.MSSQL)]
[InlineData(xTestBase.MySQL)]
[InlineData(xTestBase.PostgreSQL)]
public void TestAddFind(string sqltype)
{
var provider = GetDefaultApiResourceProvider(sqltype);
Expand All @@ -47,6 +48,7 @@ public void TestAddFind(string sqltype)
[Theory]
[InlineData(xTestBase.MSSQL)]
[InlineData(xTestBase.MySQL)]
[InlineData(xTestBase.PostgreSQL)]
public void TestRemove(string sqltype)
{
var provider = GetDefaultApiResourceProvider(sqltype);
Expand Down Expand Up @@ -99,6 +101,7 @@ public void TestRemove(string sqltype)
[Theory]
[InlineData(xTestBase.MSSQL)]
[InlineData(xTestBase.MySQL)]
[InlineData(xTestBase.PostgreSQL)]
public void TestUpdate(string sqltype)
{
var provider = GetDefaultApiResourceProvider(sqltype);
Expand Down Expand Up @@ -187,6 +190,7 @@ public void TestUpdate(string sqltype)
[Theory]
[InlineData(xTestBase.MSSQL)]
[InlineData(xTestBase.MySQL)]
[InlineData(xTestBase.PostgreSQL)]
public void TestFindAll(string sqltype)
{
var provider = GetDefaultApiResourceProvider(sqltype);
Expand All @@ -209,6 +213,7 @@ public void TestFindAll(string sqltype)
[Theory]
[InlineData(xTestBase.MSSQL)]
[InlineData(xTestBase.MySQL)]
[InlineData(xTestBase.PostgreSQL)]
public void TestFindApiResourcesByScope(string sqltype)
{
var provider = GetDefaultApiResourceProvider(sqltype);
Expand Down Expand Up @@ -240,6 +245,7 @@ public void TestFindApiResourcesByScope(string sqltype)
[Theory]
[InlineData(xTestBase.MSSQL)]
[InlineData(xTestBase.MySQL)]
[InlineData(xTestBase.PostgreSQL)]
public void TestSearch(string sqltype)
{
var provider = GetDefaultApiResourceProvider(sqltype);
Expand Down
27 changes: 27 additions & 0 deletions src/IdentityServer.Dapper.xUnitTest/xTestPostgreSQL.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Text;
using Xunit;
using Dapper;

namespace IdentityServer.Dapper.xUnitTest
{
public class xTestPostgreSQL
{
[Fact]
public void TestGetPageQuerySQL()
{
var options = xTestBase.GetDBProviderOptions(xTestBase.PostgreSQL);
int pageIndex = 1;
int pageSize = 10;
int totalCount = 499;
string orderby = "order by id";
DynamicParameters dynamicParameters = new DynamicParameters();

string pagedsql = options.GetPageQuerySQL("select * from ApiResources where 1 = 1", pageIndex, pageSize, totalCount, orderby, dynamicParameters);

Assert.False(string.IsNullOrEmpty(pagedsql));
Assert.Equal("select * from ApiResources where 1 = 1 order by id limit @size offset @start", pagedsql);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public static DBProviderOptions GetDefaultOptions()
options.ColumnProtect = new System.Collections.Generic.Dictionary<string, string>();
options.ColumnProtect.Add("left", "[");
options.ColumnProtect.Add("right", "]");
options.GetInArray = " in ";

options.GetPageQuerySQL = (input, pageindex, pagesize, totalcount, orderby, pairs) =>
{
int pagestart = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MySql.Data" Version="8.0.12" />
<PackageReference Include="MySql.Data" Version="8.0.21" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static DBProviderOptions GetDefaultOptions()
options.ColumnProtect = new System.Collections.Generic.Dictionary<string, string>();
options.ColumnProtect.Add("left", "`");
options.ColumnProtect.Add("right", "`");
options.GetInArray = " in ";
//add singgleton
options.GetPageQuerySQL = (input, pageindex, pagesize, totalcount, orderby, pairs) =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>Darin.IdentityServer4.Dapper.PostgreSQL</PackageId>
<Authors>Darin Han</Authors>
<Product>IdentityServer4.Dapper.PostgreSQL</Product>
<Version>1.0.5</Version>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\IdentityServer4.Dapper\IdentityServer4.Dapper.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Npgsql" Version="4.1.4" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using IdentityServer4.Dapper.Options;
using Microsoft.Extensions.DependencyInjection;
using System;
using Npgsql;
using System.Linq;

namespace IdentityServer4.Dapper.Extensions.PostgreSQL
{
public static class IdentityServerDapperDBExtensions
{
public static IIdentityServerBuilder AddPostgreSQLProvider(this IIdentityServerBuilder builder, Action<DBProviderOptions> dbProviderOptionsAction = null)
{
var options = GetDefaultOptions();
dbProviderOptionsAction?.Invoke(options);
builder.Services.AddSingleton(options);
return builder;
}

public static DBProviderOptions GetDefaultOptions()
{
//config mysql
var options = new DBProviderOptions();
options.DbProviderFactory = NpgsqlFactory.Instance;
//get last insert id for insert actions
options.GetLastInsertID = "select LASTVAL();";
//config the ColumnName protect string, postgresql using ""
options.ColumnProtect = new System.Collections.Generic.Dictionary<string, string>();
options.ColumnProtect.Add("left", "");
options.ColumnProtect.Add("right", "");
options.GetInArray = " = ANY ";
//add singgleton
options.GetPageQuerySQL = (input, pageindex, pagesize, totalcount, orderby, pairs) =>
{
string limitsql = string.Empty;
if (pagesize > 0)
{
if (pagesize > totalcount)
{
pagesize = totalcount;
}
pairs.Add("start", (pageindex - 1) * pagesize);
pairs.Add("size", pagesize);
limitsql = "limit @size offset @start";
}

if (input.IndexOf("order by", StringComparison.CurrentCultureIgnoreCase) >= 0)
{
orderby = "";
}
else
{
if (!string.IsNullOrWhiteSpace(orderby) && orderby.IndexOf("order by", StringComparison.CurrentCultureIgnoreCase) < 0)
{
orderby = "order by " + orderby;
}
}

return $"{input} {orderby} {limitsql}";
};
return options;
}
}
}
Loading