Skip to content

Commit

Permalink
feat(auth): enable auth
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhck committed Jun 13, 2021
1 parent 65eefc6 commit b034176
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 26 deletions.
12 changes: 12 additions & 0 deletions Micro.Starter.Api/Internal/Configs/Services.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Micro.Starter.Api.Internal.Configs
{
public class Services
{
public KeyStoreConfig KeyStore { set; get; }
}

public class KeyStoreConfig
{
public string Url { set; get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static class Configuration
public static void AddConfiguration(this IServiceCollection services, IConfiguration configuration)
{
services.Configure<DatabaseConfig>(configuration.GetSection("DatabaseConfig"));
services.Configure<Services>(configuration.GetSection("Services"));
services.Configure<SlackLoggingConfig>(configuration.GetSection("Logging").GetSection("Slack"));
}
}
Expand Down
38 changes: 19 additions & 19 deletions Micro.Starter.Api/Micro.Starter.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,37 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="App.Metrics" Version="4.2.0"/>
<PackageReference Include="App.Metrics.AspNetCore.Mvc" Version="4.2.0"/>
<PackageReference Include="App.Metrics.Extensions.Configuration" Version="4.2.0"/>
<PackageReference Include="App.Metrics.Reporting.InfluxDB" Version="4.2.0"/>
<PackageReference Include="Micro.Auth.Sdk" Version="2.1.2"/>
<PackageReference Include="Micro.GraphQL.Federation" Version="1.1.0"/>
<PackageReference Include="App.Metrics" Version="4.2.0" />
<PackageReference Include="App.Metrics.AspNetCore.Mvc" Version="4.2.0" />
<PackageReference Include="App.Metrics.Extensions.Configuration" Version="4.2.0" />
<PackageReference Include="App.Metrics.Reporting.InfluxDB" Version="4.2.0" />
<PackageReference Include="Micro.Auth.Sdk" Version="2.1.2" />
<PackageReference Include="Micro.GraphQL.Federation" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Slack" Version="1.1.0"/>
<None Include="./appsettings.ci.json" CopyToPublishDirectory="Always"/>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.4"/>
<PackageReference Include="GraphQL" Version="4.5.0"/>
<PackageReference Include="GraphQL.Server.Transports.AspNetCore" Version="5.0.2"/>
<PackageReference Include="GraphQL.Server.Transports.AspNetCore.SystemTextJson" Version="5.0.2"/>
<PackageReference Include="GraphQL.Server.Ui.GraphiQL" Version="5.0.2"/>
<PackageReference Include="GraphQL.SystemTextJson" Version="4.5.0"/>
<PackageReference Include="GraphQL.DataLoader" Version="4.5.0"/>
<PackageReference Include="GraphQL.Server.Ui.Playground" Version="5.0.2"/>
<PackageReference Include="Microsoft.Extensions.Logging.Slack" Version="1.1.0" />
<None Include="./appsettings.ci.json" CopyToPublishDirectory="Always" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.4" />
<PackageReference Include="GraphQL" Version="4.5.0" />
<PackageReference Include="GraphQL.Server.Transports.AspNetCore" Version="5.0.2" />
<PackageReference Include="GraphQL.Server.Transports.AspNetCore.SystemTextJson" Version="5.0.2" />
<PackageReference Include="GraphQL.Server.Ui.GraphiQL" Version="5.0.2" />
<PackageReference Include="GraphQL.SystemTextJson" Version="4.5.0" />
<PackageReference Include="GraphQL.DataLoader" Version="4.5.0" />
<PackageReference Include="GraphQL.Server.Ui.Playground" Version="5.0.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Micro.Starter.Storage\Micro.Starter.Storage.csproj"/>
<ProjectReference Include="..\Micro.Starter.Storage\Micro.Starter.Storage.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Internal"/>
<Folder Include="Internal" />
</ItemGroup>

<Target Name="Install githooks" BeforeTargets="Build">
<Exec Command="cp ../hooks/* ../.git/hooks/"/>
<Exec Command="cp ../hooks/* ../.git/hooks/" />
</Target>
</Project>
7 changes: 6 additions & 1 deletion Micro.Starter.Api/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Micro.Auth.Sdk;
using Micro.Starter.Api.GraphQL.Extensions;
using Micro.Starter.Api.Internal.Configs;
using Micro.Starter.Api.Internal.StartupExtensions;
Expand Down Expand Up @@ -31,6 +32,10 @@ public void ConfigureServices(IServiceCollection services)
services.ConfigureSwagger();
services.RegisterWorker();
services.ConfigureGraphql();
services.ConfigureAuthServices(new Config
{
KeyStoreUrl = Configuration.GetSection("Services").Get<Services>().KeyStore.Url
});
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand All @@ -43,7 +48,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF
}
app.SetupGraphQl();
app.UseRouting();
app.UseAuthorization();
app.SetupAuth();
app.AddSwaggerWithUi();
app.UseEndpoints(endpoints =>
{
Expand Down
5 changes: 5 additions & 0 deletions Micro.Starter.Api/appsettings.ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
"User": "starter",
"Password": "secret"
},
"Services": {
"KeyStore": {
"Url": "http://localhost:15000"
}
},
"MetricsOptions": {
"InfluxDb": {
"BaseUri": "http://influxdb:8086",
Expand Down
11 changes: 8 additions & 3 deletions Micro.Starter.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@
"LogLevel": "Warning"
}
},
"Services": {
"KeyStore": {
"Url": "http://localhost:15000"
}
},
"DatabaseConfig": {
"Host": "localhost",
"Port": 15433,
"Name": "starter_db",
"User": "starter",
"Password": "secret"
"Name": "starter",
"User": "postgres",
"Password": "postgres"
},
"MetricsOptions": {
"InfluxDb": {
Expand Down
36 changes: 33 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
version: '3'
services:
key_store:
image: fossapps/micro.keystore:1.9.1
ports:
- 15000:15000
environment:
- ASPNETCORE_URLS=http://+:15000
- DatabaseConfig__AutoMigrate=true
- DatabaseConfig__Host=postgres
- DatabaseConfig__Port=5432
- DatabaseConfig__Name=keys
- DatabaseConfig__User=postgres
- DatabaseConfig__Password=postgres
depends_on:
- postgres
auth:
image: fossapps/micro.auth:2.1.2
ports:
- 25000:25000
environment:
- ASPNETCORE_URLS=http://+:25000
- DatabaseConfig__AutoMigrate=true
- DatabaseConfig__Host=postgres
- DatabaseConfig__Port=5432
- DatabaseConfig__Name=auth
- DatabaseConfig__User=postgres
- DatabaseConfig__Password=postgres
- Services__KeyStore__Url=http://key_store:15000
depends_on:
- postgres
postgres:
image: postgres:11-alpine
ports:
- 15433:5432
volumes:
- ./extras/docker_postgres_init.sql:/docker-entrypoint-initdb.d/docker_postgres_init.sql
environment:
- POSTGRES_PASSWORD=secret
- POSTGRES_USER=starter
- POSTGRES_DB=starter_db
- POSTGRES_PASSWORD=postgres
- POSTGRES_USER=postgres
influxdb:
image: influxdb
environment:
Expand Down
3 changes: 3 additions & 0 deletions extras/docker_postgres_init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE DATABASE auth WITH OWNER = postgres ENCODING = 'UTF8' CONNECTION LIMIT = -1;
CREATE DATABASE keys WITH OWNER = postgres ENCODING = 'UTF8' CONNECTION LIMIT = -1;
CREATE DATABASE starter WITH OWNER = postgres ENCODING = 'UTF8' CONNECTION LIMIT = -1;

0 comments on commit b034176

Please sign in to comment.