-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
87 changed files
with
650 additions
and
348 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Text; | ||
using Microsoft.AspNetCore.Authentication.JwtBearer; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.IdentityModel.Tokens; | ||
using Ntrada.Core; | ||
|
||
namespace Ntrada.Extensions.Jwt | ||
{ | ||
internal class JwtExtension : IExtension | ||
{ | ||
public string Name => "jwt"; | ||
public string Description => "JSON Web Token authentication"; | ||
|
||
public void Add(IServiceCollection services, IOptionsProvider optionsProvider) | ||
{ | ||
var options = optionsProvider.GetForExtension<JwtOptions>(Name); | ||
services.AddAuthorization(); | ||
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) | ||
.AddJwtBearer(cfg => | ||
{ | ||
cfg.TokenValidationParameters = new TokenValidationParameters | ||
{ | ||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(options.Key)), | ||
ValidIssuer = options.Issuer, | ||
ValidIssuers = options.Issuers, | ||
ValidAudience = options.Audience, | ||
ValidAudiences = options.Audiences, | ||
ValidateIssuer = options.ValidateIssuer, | ||
ValidateAudience = options.ValidateAudience, | ||
ValidateLifetime = options.ValidateLifetime | ||
}; | ||
}); | ||
} | ||
|
||
public void Use(IApplicationBuilder app, IOptionsProvider optionsProvider) | ||
{ | ||
app.UseAuthentication(); | ||
} | ||
} | ||
} |
9 changes: 5 additions & 4 deletions
9
src/Ntrada/Configuration/Jwt.cs → ...sions/Ntrada.Extensions.Jwt/JwtOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
extensions/Ntrada.Extensions.Jwt/Ntrada.Extensions.Jwt.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Ntrada.Core\Ntrada.Core.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
jwt: | ||
key: eiquief5phee9pazo0Faegaez9gohThailiur5woy2befiech1oarai4aiLi6ahVecah3ie9Aiz6Peij | ||
issuer: ntrada | ||
issuers: | ||
validate_issuer: true | ||
audience: | ||
audiences: | ||
validate_audience: false | ||
validate_lifetime: true |
4 changes: 3 additions & 1 deletion
4
...rada.Handlers.RabbitMq/IContextBuilder.cs → ...da.Extensions.RabbitMq/IContextBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rada.Handlers.RabbitMq/IRabbitMqClient.cs → ...da.Extensions.RabbitMq/IRabbitMqClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Ntrada.Handlers.RabbitMq/NullContext.cs → ...Ntrada.Extensions.RabbitMq/NullContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace Ntrada.Handlers.RabbitMq | ||
namespace Ntrada.Extensions.RabbitMq | ||
{ | ||
internal sealed class NullContext | ||
{ | ||
|
4 changes: 3 additions & 1 deletion
4
...a.Handlers.RabbitMq/NullContextBuilder.cs → ...Extensions.RabbitMq/NullContextBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
extensions/Ntrada.Extensions.RabbitMq/RabbitMqExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Ntrada.Core; | ||
using RawRabbit; | ||
using RawRabbit.Configuration; | ||
using RawRabbit.Enrichers.MessageContext; | ||
using RawRabbit.Instantiation; | ||
|
||
namespace Ntrada.Extensions.RabbitMq | ||
{ | ||
public class RabbitMqExtension : IExtension | ||
{ | ||
public string Name => "rabbitmq"; | ||
public string Description => "RabbitMQ message broker"; | ||
public void Add(IServiceCollection services, IOptionsProvider optionsProvider) | ||
{ | ||
var options = optionsProvider.GetForExtension<RabbitMqOptions>(Name); | ||
services.AddTransient<IRabbitMqClient, RabbitMqClient>(); | ||
services.AddTransient<RabbitMqHandler>(); | ||
// var hasContext = typeof(TContext) != typeof(NullContext); | ||
var hasContext = false; | ||
if (!hasContext) | ||
{ | ||
services.AddSingleton<IContextBuilder, NullContextBuilder>(); | ||
} | ||
|
||
services.AddSingleton(options); | ||
var busClient = RawRabbitFactory.CreateInstanceFactory(new RawRabbitOptions | ||
{ | ||
DependencyInjection = ioc => | ||
{ | ||
ioc.AddSingleton(options); | ||
ioc.AddSingleton<RawRabbitConfiguration>(options); | ||
}, | ||
Plugins = plugins => | ||
{ | ||
plugins | ||
.UseAttributeRouting() | ||
.UseRetryLater() | ||
.UseContextForwarding(); | ||
// if (typeof(TContext) != typeof(NullContext)) | ||
// { | ||
// plugins.UseMessageContext<TContext>(); | ||
// } | ||
} | ||
}).Create(); | ||
services.AddSingleton(busClient); | ||
} | ||
|
||
public void Use(IApplicationBuilder app, IOptionsProvider optionsProvider) | ||
{ | ||
app.UseRequestHandler<RabbitMqHandler>(Name); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Ntrada.Core; | ||
using RawRabbit.Configuration; | ||
|
||
namespace Ntrada.Extensions.RabbitMq | ||
{ | ||
public class RabbitMqOptions : RawRabbitConfiguration, IOptions | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
rabbitmq: | ||
username: guest | ||
password: guest | ||
virtualHost: "/" | ||
port: 5672 | ||
hostnames: | ||
- localhost | ||
requestTimeout: '00:00:10' | ||
publishConfirmTimeout: '00:00:01' | ||
recoveryInterval: '00:00:10' | ||
persistentDeliveryMode: true | ||
autoCloseConnection: true | ||
automaticRecovery: true | ||
topologyRecovery: true | ||
exchange: | ||
durable: true | ||
autoDelete: false | ||
type: Topic | ||
queue: | ||
autoDelete: false | ||
durable: true | ||
exclusive: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.