Achieved endpoint authentication
This commit is contained in:
@@ -0,0 +1,25 @@
|
|||||||
|
using PostFundManagement.Domain.Abstractions;
|
||||||
|
using PostFundManagement.Domain.Api;
|
||||||
|
using PostFundManagement.Domain.Extensions;
|
||||||
|
|
||||||
|
namespace PostFundManagement.Api.Endpoints.Communications;
|
||||||
|
|
||||||
|
[ApiVersionTarget(1)]
|
||||||
|
public class SendInviteEndpoint : IEndpoint
|
||||||
|
{
|
||||||
|
public void Map(IEndpointRouteBuilder builder)
|
||||||
|
{
|
||||||
|
builder.MapPost("api/communications/invite", () =>
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
})
|
||||||
|
.RequireAuthorization()
|
||||||
|
.WithDescription("Trigger an invite to an organization or candidate (specifying NotificationPlatform)")
|
||||||
|
.WithName(typeof(SendInviteEndpoint).ToEndpointName())
|
||||||
|
.MapToApiVersion(new ApiVersion(1))
|
||||||
|
.Produces(StatusCodes.Status200OK)
|
||||||
|
.Produces(StatusCodes.Status400BadRequest)
|
||||||
|
.Produces(StatusCodes.Status401Unauthorized)
|
||||||
|
.WithTags(EndpointTags.Communications);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -54,18 +54,18 @@ public static class Security
|
|||||||
|
|
||||||
services.AddDataProtection().PersistKeysToDbContext<DataProtectionDbContext>()
|
services.AddDataProtection().PersistKeysToDbContext<DataProtectionDbContext>()
|
||||||
.ProtectKeysWithCertificate(certificate)
|
.ProtectKeysWithCertificate(certificate)
|
||||||
.SetApplicationName("LiteCharmsApp");
|
.SetApplicationName("PfmApp");
|
||||||
|
|
||||||
services.Configure<DataProtectionOptions>(options => options.ApplicationDiscriminator = "LiteCharmsApp");
|
services.Configure<DataProtectionOptions>(options => options.ApplicationDiscriminator = "PfmApp");
|
||||||
|
|
||||||
services.ConfigureCookieOidcSameSiteSupport();
|
services.ConfigureCookieOidcSameSiteSupport();
|
||||||
|
|
||||||
var configSection = configuration.GetSection(nameof(SecuritySettings));
|
var configSection = configuration.GetSection(nameof(SecurityClientSettings));
|
||||||
|
|
||||||
var authOptions = new SecuritySettings();
|
var authOptions = new SecurityClientSettings();
|
||||||
configSection.Bind(authOptions);
|
configSection.Bind(authOptions);
|
||||||
|
|
||||||
services.Configure<SecuritySettings>(configSection);
|
services.Configure<SecurityClientSettings>(configSection);
|
||||||
|
|
||||||
services.AddAuthentication(options =>
|
services.AddAuthentication(options =>
|
||||||
{
|
{
|
||||||
@@ -76,7 +76,7 @@ public static class Security
|
|||||||
{
|
{
|
||||||
options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
|
options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
|
||||||
options.Cookie.SameSite = SameSiteMode.Lax;
|
options.Cookie.SameSite = SameSiteMode.Lax;
|
||||||
options.Cookie.Name = "LiteCharmsApp.Session";
|
options.Cookie.Name = "PfmApp.Session";
|
||||||
})
|
})
|
||||||
.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>
|
.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>
|
||||||
{
|
{
|
||||||
@@ -123,4 +123,31 @@ public static class Security
|
|||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IServiceCollection AddApiSecurity(this IServiceCollection services, IConfiguration configuration)
|
||||||
|
{
|
||||||
|
var configSection = configuration.GetSection(nameof(SecuritySettings));
|
||||||
|
|
||||||
|
var authOptions = new SecuritySettings();
|
||||||
|
configSection.Bind(authOptions);
|
||||||
|
|
||||||
|
services.Configure<SecuritySettings>(configSection);
|
||||||
|
|
||||||
|
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||||
|
.AddJwtBearer(options =>
|
||||||
|
{
|
||||||
|
options.Authority = authOptions.Authority;
|
||||||
|
options.Audience = authOptions.Audience;
|
||||||
|
options.TokenValidationParameters = new TokenValidationParameters
|
||||||
|
{
|
||||||
|
ValidIssuer = authOptions.Authority,
|
||||||
|
ValidateAudience = true,
|
||||||
|
ValidateIssuer = true,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
services.AddAuthorization();
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -23,6 +23,8 @@
|
|||||||
<Using Include="Microsoft.AspNetCore.Authentication" />
|
<Using Include="Microsoft.AspNetCore.Authentication" />
|
||||||
<Using Include="Microsoft.AspNetCore.Authentication.Cookies" />
|
<Using Include="Microsoft.AspNetCore.Authentication.Cookies" />
|
||||||
<Using Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" />
|
<Using Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" />
|
||||||
|
<Using Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
|
||||||
|
<Using Include="Microsoft.IdentityModel.Tokens" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<!-- Health Checks -->
|
<!-- Health Checks -->
|
||||||
|
|||||||
@@ -16,17 +16,16 @@ builder.Services.AddApiServices(builder.Configuration);
|
|||||||
|
|
||||||
builder.Services.AddMediator();
|
builder.Services.AddMediator();
|
||||||
builder.Services.AddSecurityApiSdk(builder.Configuration);
|
builder.Services.AddSecurityApiSdk(builder.Configuration);
|
||||||
builder.Services.AddWebSecurity(builder.Configuration);
|
builder.Services.AddApiSecurity(builder.Configuration);
|
||||||
|
|
||||||
builder.Services.AddScoped(typeof(IPipelineBehavior<,>), typeof(TelemetryPipelineBehavior<,>));
|
builder.Services.AddScoped(typeof(IPipelineBehavior<,>), typeof(TelemetryPipelineBehavior<,>));
|
||||||
builder.Services.AddScoped(typeof(IPipelineBehavior<,>), typeof(LoggingPipelineBehavior<,>));
|
builder.Services.AddScoped(typeof(IPipelineBehavior<,>), typeof(LoggingPipelineBehavior<,>));
|
||||||
|
|
||||||
builder.Services.AddQuartzScheduler(DefaultSchedulerName, builder.Configuration);
|
builder.Services.AddQuartzScheduler(DefaultSchedulerName, builder.Configuration);
|
||||||
|
|
||||||
builder.Services.AddEmailServices(builder.Configuration);
|
builder.Services.AddEmailServices(builder.Configuration);
|
||||||
|
builder.Services.AddHashServices(builder.Configuration);
|
||||||
|
|
||||||
builder.Services.AddHttpClient();
|
builder.Services.AddHttpClient();
|
||||||
builder.Services.AddHashServices(builder.Configuration);
|
|
||||||
builder.Services.AddDataProtectionDatabase(builder.Configuration);
|
builder.Services.AddDataProtectionDatabase(builder.Configuration);
|
||||||
builder.Services.AddApplicationDbContext(builder.Configuration);
|
builder.Services.AddApplicationDbContext(builder.Configuration);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
namespace PostFundManagement.Domain.Extensions;
|
||||||
|
|
||||||
|
public static class EndpointTags
|
||||||
|
{
|
||||||
|
public const string Governance = nameof(Governance);
|
||||||
|
|
||||||
|
public const string Projects = nameof(Projects);
|
||||||
|
|
||||||
|
public const string Grants = nameof(Grants);
|
||||||
|
|
||||||
|
public const string Execution = nameof(Execution);
|
||||||
|
|
||||||
|
public const string Evidence = "Evidence & M&E";
|
||||||
|
|
||||||
|
public const string Communications = nameof(Communications);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user