Skip to content

Commit

Permalink
lifebook.core.auth
Browse files Browse the repository at this point in the history
this service addresses #3
  • Loading branch information
mkcoder committed Feb 10, 2019
1 parent b90b69c commit 11ec3f3
Show file tree
Hide file tree
Showing 22 changed files with 298 additions and 204 deletions.
24 changes: 7 additions & 17 deletions authentication/authentication.server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Castle.Windsor.Installer;
using Castle.Windsor.MsDependencyInjection;
using IdentityServer4.EntityFramework.DbContexts;
using lifebook.authentication.core.dbcontext;
using lifebook.core.database.databaseprovider.services;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
Expand All @@ -13,16 +14,15 @@
namespace authentication.server
{
public class Startup
{
{
private IdentityServerDbContext identityServerDbContext;

public IServiceProvider ConfigureServices(IServiceCollection services)
{
WindsorContainer container = new WindsorContainer();
var currentAssembly = GetType().Assembly.GetName().Name;
container.Install(FromAssembly.InThisApplication(GetType().Assembly));
container.Register(Component.For<IdentityServerDbContext>());
var sqlServerProvider = new IdentityServerDbContext();
var dbConnection = sqlServerProvider.Database.GetDbConnection();
Console.WriteLine($"SQL SERVER CONNECT: {sqlServerProvider.Database.CanConnect()}");
container.Install(FromAssembly.Named("lifebook.authentication.core"));
identityServerDbContext = container.Resolve<IdentityServerDbContext>();
services.AddIdentityServer()
.AddInMemoryIdentityResources(InMemoryResources.GetInMemoryIdentityResources())
.AddInMemoryClients(InMemoryResources.GetInmemoryClients())
Expand All @@ -33,7 +33,6 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
builder.UseSqlServer(provider.GetRequiredService<IdentityServerDbContext>().ConnectionString,
sql => sql.MigrationsAssembly(currentAssembly
));
}
)
.AddOperationalStore(options =>
Expand Down Expand Up @@ -62,7 +61,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
}

private void InitializeDatabase(IApplicationBuilder app)
{
{
using (var serviceScope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
{
serviceScope.ServiceProvider.GetRequiredService<PersistedGrantDbContext>().Database.Migrate();
Expand All @@ -72,13 +71,4 @@ private void InitializeDatabase(IApplicationBuilder app)
}
}
}

public class IdentityServerDbContext : SqlServerDatabaseProvider
{
public IdentityServerDbContext() : base("lifebook")
{
}

public string ConnectionString => $@"Server={Host},{Port};Database={DatabaseName};User={Username};Password={Password};";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App"/>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="IdentityServer4" Version="2.3.2" />
<PackageReference Include="lifebook.core.database.repository" Version="1.0.3" />
<PackageReference Include="lifebook.core.database.databaseprovider" Version="1.0.9" />
Expand All @@ -26,4 +26,7 @@
<ItemGroup>
<Compile Remove="InMemoryResources\InmemoryResources.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\lifebook.authentication.core\lifebook.authentication.core.csproj" />
</ItemGroup>
</Project>
12 changes: 6 additions & 6 deletions authentication/authentication.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "authentication.server", "authentication.server\authentication.server.csproj", "{22FFEA0B-A8E7-40FE-BFE4-A69A5C0AE21A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "authentication.web.api", "authentication.web.api\authentication.web.api.csproj", "{CEA642F2-02D8-46B5-991D-2CF5E70BF6D3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "lifebook.authentication.web.api", "lifebook.authentication.web.api\lifebook.authentication.web.api\lifebook.authentication.web.api.csproj", "{FE321AF1-CFA9-4CF5-9ADB-E7F67CCD986C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "lifebook.authentication.core", "lifebook.authentication.core\lifebook.authentication.core.csproj", "{E9FFC457-FC75-4C19-8AC5-5E6B49C7D808}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -17,13 +17,13 @@ Global
{22FFEA0B-A8E7-40FE-BFE4-A69A5C0AE21A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{22FFEA0B-A8E7-40FE-BFE4-A69A5C0AE21A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{22FFEA0B-A8E7-40FE-BFE4-A69A5C0AE21A}.Release|Any CPU.Build.0 = Release|Any CPU
{CEA642F2-02D8-46B5-991D-2CF5E70BF6D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CEA642F2-02D8-46B5-991D-2CF5E70BF6D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CEA642F2-02D8-46B5-991D-2CF5E70BF6D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CEA642F2-02D8-46B5-991D-2CF5E70BF6D3}.Release|Any CPU.Build.0 = Release|Any CPU
{FE321AF1-CFA9-4CF5-9ADB-E7F67CCD986C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FE321AF1-CFA9-4CF5-9ADB-E7F67CCD986C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FE321AF1-CFA9-4CF5-9ADB-E7F67CCD986C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FE321AF1-CFA9-4CF5-9ADB-E7F67CCD986C}.Release|Any CPU.Build.0 = Release|Any CPU
{E9FFC457-FC75-4C19-8AC5-5E6B49C7D808}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E9FFC457-FC75-4C19-8AC5-5E6B49C7D808}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E9FFC457-FC75-4C19-8AC5-5E6B49C7D808}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E9FFC457-FC75-4C19-8AC5-5E6B49C7D808}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

This file was deleted.

This file was deleted.

24 changes: 0 additions & 24 deletions authentication/authentication.web.api/Program.cs

This file was deleted.

40 changes: 0 additions & 40 deletions authentication/authentication.web.api/Startup.cs

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions authentication/authentication.web.api/appsettings.json

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using IdentityServer4.EntityFramework.Entities;
using lifebook.core.database.databaseprovider.services;
using Microsoft.EntityFrameworkCore;

namespace lifebook.authentication.core.dbcontext
{
public class ApiResourcesDbContext : SqlServerDatabaseProvider
{
public DbSet<ApiResource> ApiResources { get; set; }

public ApiResourcesDbContext() : base("lifebook.oauth")
{
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using IdentityServer4.EntityFramework.Entities;
using lifebook.core.database.databaseprovider.services;
using Microsoft.EntityFrameworkCore;

namespace lifebook.authentication.core.dbcontext
{
public class ClientDbContext : SqlServerDatabaseProvider
{
public DbSet<Client> Clients { get; set; }

public ClientDbContext() : base("lifebook.oauth")
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using IdentityServer4.EntityFramework.DbContexts;
using IdentityServer4.EntityFramework.Entities;
using lifebook.core.database.databaseprovider.services;

namespace lifebook.authentication.core.dbcontext
{
public class IdentityServerDbContext : SqlServerDatabaseProvider
{
public ConfigurationDbContext ConfigurationDbContext { get; private set; }
public PersistedGrantDbContext PersistedGrantDbContext { get; private set; }
public string ConnectionString => $@"Server={Host},{Port};Database={DatabaseName};User={Username};Password={Password};";

public IdentityServerDbContext(ConfigurationDbContext configurationDbContext, PersistedGrantDbContext persistedGrantDbContext) : base("lifebook.oauth")

{
ConfigurationDbContext = configurationDbContext;
PersistedGrantDbContext = persistedGrantDbContext;
}
}
}
16 changes: 16 additions & 0 deletions authentication/lifebook.authentication.core/ioc/Bootloader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using Castle.MicroKernel.Registration;
using Castle.MicroKernel.SubSystems.Configuration;
using Castle.Windsor;
using Castle.Windsor.Installer;
using lifebook.authentication.core.ioc.installers;

namespace lifebook.authentication.core.ioc
{
public class Bootloader : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using Castle.MicroKernel.Registration;
using Castle.MicroKernel.SubSystems.Configuration;
using Castle.Windsor;
using IdentityServer4.EntityFramework.DbContexts;
using lifebook.authentication.core.dbcontext;
using lifebook.authentication.core.repository;

namespace lifebook.authentication.core.ioc.installers
{
public class DefaultInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(
Component.For<IdentityServerDbContext>().IsDefault().LifestyleTransient().Named("lifebook.authentication.core.IdentityServerDbContext"),
Component.For<ApiResourcesDbContext>().IsDefault().LifestyleTransient(),
Component.For<ApiRepository>().IsDefault().LifestyleTransient(),
Component.For<ClientDbContext>().IsDefault().LifestyleTransient(),
Component.For<ClientRepository>().IsDefault().LifestyleTransient()
);
}
}
}
Loading

0 comments on commit 11ec3f3

Please sign in to comment.