Skip to content

Commit

Permalink
Merge pull request #40 from NerosoftDev/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Codespilot authored Dec 4, 2023
2 parents 576f028 + 3100cdf commit 89033a6
Show file tree
Hide file tree
Showing 13 changed files with 964 additions and 1,027 deletions.
68 changes: 34 additions & 34 deletions Source/Euonia.Application/Behaviors/BearerTokenBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,44 @@ namespace Nerosoft.Euonia.Application;
/// <summary>
/// A pipeline behavior that adds the bearer token to the command metadata.
/// </summary>
public class BearerTokenBehavior : IPipelineBehavior<RoutedMessage<object>, CommandResponse>
public class BearerTokenBehavior : IPipelineBehavior<IRoutedMessage, CommandResponse>
{
private readonly IRequestContextAccessor _contextAccessor;
private readonly IRequestContextAccessor _contextAccessor;

/// <summary>
/// Initializes a new instance of the <see cref="BearerTokenBehavior"/> class.
/// </summary>
public BearerTokenBehavior()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="BearerTokenBehavior"/> class.
/// </summary>
public BearerTokenBehavior()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="BearerTokenBehavior"/> class.
/// </summary>
/// <param name="contextAccessor"></param>
public BearerTokenBehavior(IRequestContextAccessor contextAccessor)
{
_contextAccessor = contextAccessor;
}
/// <summary>
/// Initializes a new instance of the <see cref="BearerTokenBehavior"/> class.
/// </summary>
/// <param name="contextAccessor"></param>
public BearerTokenBehavior(IRequestContextAccessor contextAccessor)
{
_contextAccessor = contextAccessor;
}

/// <inheritdoc />
public async Task<CommandResponse> HandleAsync(RoutedMessage<object> context, PipelineDelegate<RoutedMessage<object>, CommandResponse> next)
{
if (_contextAccessor?.RequestHeaders.TryGetValue("Authorization", out var values) == true)
{
if (values.Count > 0)
{
var value = values[0];
if (!string.IsNullOrWhiteSpace(value) && value.StartsWith("Bearer") && !value.Equals("Bearer null", StringComparison.OrdinalIgnoreCase))
{
context.Metadata.Set("$nerosoft:token", value);
}
}
}
/// <inheritdoc />
public async Task<CommandResponse> HandleAsync(IRoutedMessage context, PipelineDelegate<IRoutedMessage, CommandResponse> next)
{
if (_contextAccessor?.RequestHeaders.TryGetValue("Authorization", out var values) == true)
{
if (values.Count > 0)
{
var value = values[0];
if (!string.IsNullOrWhiteSpace(value) && value.StartsWith("Bearer") && !value.Equals("Bearer null", StringComparison.OrdinalIgnoreCase))
{
context.Metadata.Set("$nerosoft:token", value);
}
}
}

{
}
{
}

return await next(context);
}
return await next(context);
}
}
56 changes: 28 additions & 28 deletions Source/Euonia.Application/Behaviors/UserPrincipalBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,37 @@ namespace Nerosoft.Euonia.Application;
/// <summary>
/// A pipeline behavior that adds the user principal to the command metadata.
/// </summary>
public class UserPrincipalBehavior : IPipelineBehavior<RoutedMessage<object>, CommandResponse>
public class UserPrincipalBehavior : IPipelineBehavior<IRoutedMessage, CommandResponse>
{
private readonly UserPrincipal _user;
private readonly UserPrincipal _user;

/// <summary>
/// Initializes a new instance of the <see cref="UserPrincipalBehavior"/> class.
/// </summary>
public UserPrincipalBehavior()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="UserPrincipalBehavior"/> class.
/// </summary>
public UserPrincipalBehavior()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="UserPrincipalBehavior"/> class.
/// </summary>
/// <param name="user"></param>
public UserPrincipalBehavior(UserPrincipal user)
{
_user = user;
}
/// <summary>
/// Initializes a new instance of the <see cref="UserPrincipalBehavior"/> class.
/// </summary>
/// <param name="user"></param>
public UserPrincipalBehavior(UserPrincipal user)
{
_user = user;
}

/// <inheritdoc />
public async Task<CommandResponse> HandleAsync(RoutedMessage<object> context, PipelineDelegate<RoutedMessage<object>, CommandResponse> next)
{
if (_user is { IsAuthenticated: true })
{
context.Metadata.Set("$nerosoft:user.name", _user.Username);
context.Metadata.Set("$nerosoft:user.id", _user.UserId);
context.Metadata.Set("$nerosoft:user.code", _user.Code);
context.Metadata.Set("$nerosoft:user.tenant", _user.Tenant);
}
/// <inheritdoc />
public async Task<CommandResponse> HandleAsync(IRoutedMessage context, PipelineDelegate<IRoutedMessage, CommandResponse> next)
{
if (_user is { IsAuthenticated: true })
{
context.Metadata.Set("$nerosoft:user.name", _user.Username);
context.Metadata.Set("$nerosoft:user.id", _user.UserId);
context.Metadata.Set("$nerosoft:user.code", _user.Code);
context.Metadata.Set("$nerosoft:user.tenant", _user.Tenant);
}

return await next(context);
}
return await next(context);
}
}
Loading

0 comments on commit 89033a6

Please sign in to comment.