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

Add Auth0 #317

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
54 changes: 7 additions & 47 deletions IGroceryStore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Products.Core", "src\Produc
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{DC323AE4-1C76-4AEB-BD0E-139B47A5F4ED}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "src\Shared\Shared\Shared.csproj", "{F086A490-C28A-4DF9-A05E-8D765CF0FD62}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API", "src\API\API.csproj", "{F8ED371D-A8D2-43C0-9526-2B5B1026E120}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Worker", "src\Worker\Worker.csproj", "{13FCD77B-95D7-4FC2-AD7F-FC557C89E08D}"
Expand All @@ -33,18 +31,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{E795DE89
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Baskets.UnitTests", "tests\Baskets\Baskets.UnitTests\Baskets.UnitTests.csproj", "{4BE58296-F624-4C03-A9D2-1E5D3061000E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Users", "Users", "{DAB96D2A-A8E0-419A-A030-A39596BC9F96}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Users.Core", "src\Users\Users.Core\Users.Core.csproj", "{705137AC-A585-4DA0-80E1-A6AEDA0A8B78}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Users.Contracts", "src\Users\Users.Contracts\Users.Contracts.csproj", "{9EFBA892-DA33-4E8B-BE43-06C2CD184732}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4257692D-0F78-4D5D-9B1D-5F7D28DB58CB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Baskets", "Baskets", "{A55FBF25-CB11-4671-8CF4-76816B19A882}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Users", "Users", "{F3EB15AF-4432-40B1-8B20-D3B257D1411E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Products", "Products", "{E59C08BA-D7AE-4726-ACED-270B35104447}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shops", "Shops", "{159E4352-BDA2-41BA-81FA-D722BDC200E5}"
Expand All @@ -55,20 +45,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Products.IntegrationTests",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shops.IntegrationTests", "tests\Shops\Shops.IntegrationTests\Shops.IntegrationTests.csproj", "{32B71E08-83CC-485E-9C2C-B49D078EE8B1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Users.IntegrationTests", "tests\Users\Users.IntegrationTests\Users.IntegrationTests.csproj", "{492E6B88-37F2-4752-A146-C37B8B3B2C8F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Products.UnitTests", "tests\Products\Products.UnitTests\Products.UnitTests.csproj", "{9B368812-B9E0-4B34-B532-AC90B95D1CBF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shops.UnitTests", "tests\Shops\Shops.UnitTests\Shops.UnitTests.csproj", "{5F1ACEEE-21C2-4F25-AC1E-B7FE4C5BF2D9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Users.UnitTests", "tests\Users\Users.UnitTests\Users.UnitTests.csproj", "{90BAF73D-97DE-4308-894D-4CFBC8546043}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "requests", "requests", "{02241B0B-8C92-40C1-A3AC-F7AC27EDD788}"
ProjectSection(SolutionItems) = preProject
requests\brands.http = requests\brands.http
requests\users.http = requests\users.http
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Notifications", "Notifications", "{C3809CC7-0AF9-4D56-B1AB-EA0E098B0ECF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notifications", "src\Notifications\Notifications\Notifications.csproj", "{7F1E1F0D-2006-42D0-8AC0-72E40FD709B6}"
Expand Down Expand Up @@ -144,6 +124,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "global", "global", "{F0E45E
tools\terraform\global\terraform.tfvars = tools\terraform\global\terraform.tfvars
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "src\Shared\Shared.csproj", "{16A1B41B-B31E-4DC6-90F3-FFF3AFF3B61D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -174,10 +156,6 @@ Global
{D8778F33-AEFD-4F9F-AE08-14BF1B13B503}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D8778F33-AEFD-4F9F-AE08-14BF1B13B503}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8778F33-AEFD-4F9F-AE08-14BF1B13B503}.Release|Any CPU.Build.0 = Release|Any CPU
{F086A490-C28A-4DF9-A05E-8D765CF0FD62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F086A490-C28A-4DF9-A05E-8D765CF0FD62}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F086A490-C28A-4DF9-A05E-8D765CF0FD62}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F086A490-C28A-4DF9-A05E-8D765CF0FD62}.Release|Any CPU.Build.0 = Release|Any CPU
{F8ED371D-A8D2-43C0-9526-2B5B1026E120}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F8ED371D-A8D2-43C0-9526-2B5B1026E120}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F8ED371D-A8D2-43C0-9526-2B5B1026E120}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -190,14 +168,6 @@ Global
{4BE58296-F624-4C03-A9D2-1E5D3061000E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4BE58296-F624-4C03-A9D2-1E5D3061000E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4BE58296-F624-4C03-A9D2-1E5D3061000E}.Release|Any CPU.Build.0 = Release|Any CPU
{705137AC-A585-4DA0-80E1-A6AEDA0A8B78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{705137AC-A585-4DA0-80E1-A6AEDA0A8B78}.Debug|Any CPU.Build.0 = Debug|Any CPU
{705137AC-A585-4DA0-80E1-A6AEDA0A8B78}.Release|Any CPU.ActiveCfg = Release|Any CPU
{705137AC-A585-4DA0-80E1-A6AEDA0A8B78}.Release|Any CPU.Build.0 = Release|Any CPU
{9EFBA892-DA33-4E8B-BE43-06C2CD184732}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9EFBA892-DA33-4E8B-BE43-06C2CD184732}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9EFBA892-DA33-4E8B-BE43-06C2CD184732}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9EFBA892-DA33-4E8B-BE43-06C2CD184732}.Release|Any CPU.Build.0 = Release|Any CPU
{0A86368E-D354-4998-8590-943EADEF867A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A86368E-D354-4998-8590-943EADEF867A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A86368E-D354-4998-8590-943EADEF867A}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -210,10 +180,6 @@ Global
{32B71E08-83CC-485E-9C2C-B49D078EE8B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{32B71E08-83CC-485E-9C2C-B49D078EE8B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{32B71E08-83CC-485E-9C2C-B49D078EE8B1}.Release|Any CPU.Build.0 = Release|Any CPU
{492E6B88-37F2-4752-A146-C37B8B3B2C8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{492E6B88-37F2-4752-A146-C37B8B3B2C8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{492E6B88-37F2-4752-A146-C37B8B3B2C8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{492E6B88-37F2-4752-A146-C37B8B3B2C8F}.Release|Any CPU.Build.0 = Release|Any CPU
{9B368812-B9E0-4B34-B532-AC90B95D1CBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B368812-B9E0-4B34-B532-AC90B95D1CBF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B368812-B9E0-4B34-B532-AC90B95D1CBF}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -222,10 +188,6 @@ Global
{5F1ACEEE-21C2-4F25-AC1E-B7FE4C5BF2D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5F1ACEEE-21C2-4F25-AC1E-B7FE4C5BF2D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5F1ACEEE-21C2-4F25-AC1E-B7FE4C5BF2D9}.Release|Any CPU.Build.0 = Release|Any CPU
{90BAF73D-97DE-4308-894D-4CFBC8546043}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{90BAF73D-97DE-4308-894D-4CFBC8546043}.Debug|Any CPU.Build.0 = Debug|Any CPU
{90BAF73D-97DE-4308-894D-4CFBC8546043}.Release|Any CPU.ActiveCfg = Release|Any CPU
{90BAF73D-97DE-4308-894D-4CFBC8546043}.Release|Any CPU.Build.0 = Release|Any CPU
{7F1E1F0D-2006-42D0-8AC0-72E40FD709B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7F1E1F0D-2006-42D0-8AC0-72E40FD709B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7F1E1F0D-2006-42D0-8AC0-72E40FD709B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -234,6 +196,10 @@ Global
{3778177C-5D1B-413E-8313-BAEFBE5B45AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3778177C-5D1B-413E-8313-BAEFBE5B45AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3778177C-5D1B-413E-8313-BAEFBE5B45AB}.Release|Any CPU.Build.0 = Release|Any CPU
{16A1B41B-B31E-4DC6-90F3-FFF3AFF3B61D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{16A1B41B-B31E-4DC6-90F3-FFF3AFF3B61D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{16A1B41B-B31E-4DC6-90F3-FFF3AFF3B61D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{16A1B41B-B31E-4DC6-90F3-FFF3AFF3B61D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -249,24 +215,17 @@ Global
{29B589AC-707B-4C53-9E88-F22888311229} = {51E807A8-E7D2-4349-B5C2-EB780D82641A}
{D8778F33-AEFD-4F9F-AE08-14BF1B13B503} = {51E807A8-E7D2-4349-B5C2-EB780D82641A}
{DC323AE4-1C76-4AEB-BD0E-139B47A5F4ED} = {4257692D-0F78-4D5D-9B1D-5F7D28DB58CB}
{F086A490-C28A-4DF9-A05E-8D765CF0FD62} = {DC323AE4-1C76-4AEB-BD0E-139B47A5F4ED}
{F8ED371D-A8D2-43C0-9526-2B5B1026E120} = {4257692D-0F78-4D5D-9B1D-5F7D28DB58CB}
{13FCD77B-95D7-4FC2-AD7F-FC557C89E08D} = {4257692D-0F78-4D5D-9B1D-5F7D28DB58CB}
{4BE58296-F624-4C03-A9D2-1E5D3061000E} = {A55FBF25-CB11-4671-8CF4-76816B19A882}
{DAB96D2A-A8E0-419A-A030-A39596BC9F96} = {4257692D-0F78-4D5D-9B1D-5F7D28DB58CB}
{705137AC-A585-4DA0-80E1-A6AEDA0A8B78} = {DAB96D2A-A8E0-419A-A030-A39596BC9F96}
{9EFBA892-DA33-4E8B-BE43-06C2CD184732} = {DAB96D2A-A8E0-419A-A030-A39596BC9F96}
{A55FBF25-CB11-4671-8CF4-76816B19A882} = {E795DE89-913A-4B75-B579-45FFB612EE53}
{F3EB15AF-4432-40B1-8B20-D3B257D1411E} = {E795DE89-913A-4B75-B579-45FFB612EE53}
{E59C08BA-D7AE-4726-ACED-270B35104447} = {E795DE89-913A-4B75-B579-45FFB612EE53}
{159E4352-BDA2-41BA-81FA-D722BDC200E5} = {E795DE89-913A-4B75-B579-45FFB612EE53}
{0A86368E-D354-4998-8590-943EADEF867A} = {A55FBF25-CB11-4671-8CF4-76816B19A882}
{B65B2EA2-E5DD-4A6A-894A-79B16961B50E} = {E59C08BA-D7AE-4726-ACED-270B35104447}
{32B71E08-83CC-485E-9C2C-B49D078EE8B1} = {159E4352-BDA2-41BA-81FA-D722BDC200E5}
{492E6B88-37F2-4752-A146-C37B8B3B2C8F} = {F3EB15AF-4432-40B1-8B20-D3B257D1411E}
{9B368812-B9E0-4B34-B532-AC90B95D1CBF} = {E59C08BA-D7AE-4726-ACED-270B35104447}
{5F1ACEEE-21C2-4F25-AC1E-B7FE4C5BF2D9} = {159E4352-BDA2-41BA-81FA-D722BDC200E5}
{90BAF73D-97DE-4308-894D-4CFBC8546043} = {F3EB15AF-4432-40B1-8B20-D3B257D1411E}
{C3809CC7-0AF9-4D56-B1AB-EA0E098B0ECF} = {4257692D-0F78-4D5D-9B1D-5F7D28DB58CB}
{7F1E1F0D-2006-42D0-8AC0-72E40FD709B6} = {C3809CC7-0AF9-4D56-B1AB-EA0E098B0ECF}
{E62041C7-7CED-415E-A320-4EB555D3223D} = {E795DE89-913A-4B75-B579-45FFB612EE53}
Expand All @@ -280,6 +239,7 @@ Global
{15F3218D-6C08-49D5-A7A7-D61FA1280565} = {02396B41-F62C-4CC3-8B8F-B2400BBDD7FC}
{6FA4FE98-D7C9-42AD-BBBF-0B4B2383733F} = {0DC74329-B279-4FE2-940C-D7224162ED46}
{F0E45EE2-0DD1-4810-B2E7-45CEE54F22AB} = {02396B41-F62C-4CC3-8B8F-B2400BBDD7FC}
{16A1B41B-B31E-4DC6-90F3-FFF3AFF3B61D} = {DC323AE4-1C76-4AEB-BD0E-139B47A5F4ED}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F83A5637-BD21-4AAC-9087-87AB61B4E0A8}
Expand Down
1 change: 1 addition & 0 deletions IGroceryStore.sln.DotSettings.user
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue">&lt;AssemblyExplorer&gt;
&lt;PhysicalFolder Path="/Users/adrianfranczak/.nuget/packages/opentelemetry.instrumentation.http/1.0.0-rc9.5" Loaded="True" /&gt;
&lt;PhysicalFolder Path="/Users/adrianfranczak/.nuget/packages/opentelemetry.instrumentation.http/1.0.0-rc9.6" Loaded="True" /&gt;
&lt;Assembly Path="/Users/adrianfranczak/.nuget/packages/fluentvalidation/11.3.0/lib/net7.0/FluentValidation.dll" /&gt;
&lt;/AssemblyExplorer&gt;</s:String>
<s:String x:Key="/Default/Environment/Highlighting/HighlightingSourceSnapshotLocation/@EntryValue">/Users/adrianfranczak/Library/Caches/JetBrains/Rider2022.2/resharper-host/temp/Rider/vAny/CoverageData/_IGroceryStore.1213299661/Snapshot/snapshot.utdcvr</s:String>

Expand Down
6 changes: 0 additions & 6 deletions requests/brands.http

This file was deleted.

11 changes: 0 additions & 11 deletions requests/users.http

This file was deleted.

8 changes: 5 additions & 3 deletions src/API/API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
<RootNamespace>IGroceryStore.API</RootNamespace>
<LangVersion>preview</LangVersion>
<AssemblyName>IGroceryStore.API</AssemblyName>
<UserSecretsId>f57debf8-2b9a-43cc-b82a-3b5be9176885</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.0" />
<PackageReference Include="Amazon.Extensions.Configuration.SystemsManager" Version="4.0.0" />
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.7.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.0" />
Expand All @@ -25,10 +27,10 @@
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.0.0-rc9.9" />
<PackageReference Include="OpenTelemetry.Instrumentation.EntityFrameworkCore" Version="1.0.0-beta.3" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.0.0-rc9.9" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.0.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.1.0-beta.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.SqlClient" Version="1.0.0-rc9.9" />
<PackageReference Include="Serilog" Version="2.12.1-dev-01587" />
<PackageReference Include="Serilog.AspNetCore" Version="6.1.0-dev-00285" />
<PackageReference Include="Serilog.AspNetCore" Version="6.1.0-dev-00289" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.1-dev-00787" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.5.0-dev-00359" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.1-dev-00896" />
Expand All @@ -41,8 +43,8 @@
<ItemGroup>
<ProjectReference Include="..\Baskets\Baskets.Core\Baskets.Core.csproj" />
<ProjectReference Include="..\Products\Products.Core\Products.Core.csproj" />
<ProjectReference Include="..\Shared\Shared.csproj" />
<ProjectReference Include="..\Shops\Shops.Core\Shops.Core.csproj" />
<ProjectReference Include="..\Users\Users.Core\Users.Core.csproj" />
</ItemGroup>


Expand Down
71 changes: 71 additions & 0 deletions src/API/Configuration/AuthenticationConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System.Security.Claims;
using FluentValidation;
using IGroceryStore.Shared.Settings;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;

namespace IGroceryStore.API.Configuration;

public class Auth0Settings : SettingsBase<Auth0Settings>, ISettings
{
public static string SectionName => "Authentication:Schemes:Bearer";

public string ValidIssuer { get; set; }
public string ValidAudience { get; set; }

public Auth0Settings()
{
RuleFor(x => ValidIssuer).NotEmpty();
RuleFor(x => ValidAudience).NotEmpty();
}
}

public static class AuthenticationConfiguration
{
public static void ConfigureAuthentication(this WebApplicationBuilder builder)
{
var options = builder.Configuration.GetOptions<Auth0Settings>();

builder.Services.AddAuthentication(o =>
{
o.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
o.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(o =>
{
o.Authority = options.ValidIssuer;
o.Audience = options.ValidAudience;
});

builder.Services.AddAuthorization(o =>
{
o.AddPolicy("read:messages", policy
=> policy.Requirements.Add(new HasScopeRequirement("read:messages"))
);
});
}
}

public class HasScopeRequirement : IAuthorizationRequirement
{
public string Scope { get; }

public HasScopeRequirement(string scope)
{
Scope = scope ?? throw new ArgumentNullException(nameof(scope));
}
}

public class HasScopeHandler : AuthorizationHandler<HasScopeRequirement>
{
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, HasScopeRequirement requirement)
{
if (!context.User.HasClaim(c => c.Type == "scope")) return Task.CompletedTask;

var scopes = context.User.FindFirstValue("scope")?
.Split(' ');
if (scopes == null) return Task.CompletedTask;

if (scopes.Any(s => s == requirement.Scope)) context.Succeed(requirement);
return Task.CompletedTask;
}
}
38 changes: 38 additions & 0 deletions src/API/Configuration/AwsConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Amazon;
using Amazon.SQS;
using IGroceryStore.API.Initializers;
using IGroceryStore.Shared.SQS;

namespace IGroceryStore.API.Configuration;

public static class AwsConfiguration
{
public static void ConfigureSystemManager(this WebApplicationBuilder builder)
{
if (!builder.Environment.IsDevelopment() && !builder.Environment.IsTestEnvironment())
{
builder.Configuration.AddSystemsManager("/Production/IGroceryStore", TimeSpan.FromSeconds(30));
}

builder.Services.AddHostedService<SqsConsumerService>();
builder.Services.AddSingleton<IAmazonSQS>(_ => new AmazonSQSClient(RegionEndpoint.EUWest2));

builder.Services.AddSingleton<MessageDispatcher>();

builder.Services.AddMessageHandlers();

// var client = new AmazonSimpleNotificationServiceClient(RegionEndpoint.EUWest2);
//
// var publisher = new SnsPublisher(client);
//
// var customerUpdated = new CustomerUpdated
// {
// Id = 1,
// FullName = "Nick Chapsas",
// LifetimeSpent = 420
// };
//
// await publisher.PublishAsync("<topicARN>",
// customerUpdated);
}
}
24 changes: 24 additions & 0 deletions src/API/Configuration/LoggingConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Serilog;
using Serilog.Sinks.Elasticsearch;

namespace IGroceryStore.API.Configuration;

public static class LoggingConfiguration
{
public static void ConfigureLogging(this WebApplicationBuilder builder)
{
builder.Host.UseSerilog((context, loggerConfiguration) =>
{
loggerConfiguration
.Enrich.FromLogContext()
.Enrich.WithMachineName()
.WriteTo.Console()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(context.Configuration["ElasticConfiguration:Uri"]))
{
IndexFormat = $"{context.Configuration["ApplicationName"]}-logs".Replace(".", "-"),
AutoRegisterTemplate = true
})
.ReadFrom.Configuration(context.Configuration);
});
}
}
Loading