Authentication finally moved to the dotnet way in webapi, ready to be added to to deal with users and such
Introspection access point properly uses basic auth of client id and secret to access
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.HttpsPolicy;
|
||||
@@ -12,6 +16,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using WebAPI.Auth;
|
||||
using WebAPI.Data;
|
||||
|
||||
namespace WebAPI
|
||||
@@ -61,8 +66,21 @@ namespace WebAPI
|
||||
});
|
||||
});
|
||||
services.AddDbContext<AppDbContext>(options => options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection")));
|
||||
services.AddSingleton<PterodactylService>();
|
||||
services.AddSingleton<OIDCService>();
|
||||
services.AddScoped<PterodactylService>();
|
||||
services.AddScoped<OIDCService>();
|
||||
services.AddScoped<CustomAuthorizationFilter>();
|
||||
services.AddAuthentication(opt =>
|
||||
{
|
||||
opt.DefaultScheme = OIDCTokenAuthenticationDefaults.DefaultScheme;
|
||||
})
|
||||
.AddScheme<OIDCTokenAuthenticationOptions, OIDCTokenAuthenticationHandler>(
|
||||
OIDCTokenAuthenticationDefaults.DefaultScheme,
|
||||
opt =>
|
||||
{
|
||||
opt.OIDCClientId = AppSettings.OIDCClientId;
|
||||
opt.OIDCClientSecret = AppSettings.OIDCClientSecret;
|
||||
opt.OIDCIntrospectionEndpoint = AppSettings.OIDCIntrospectionEndpoint;
|
||||
});
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
@@ -79,6 +97,7 @@ namespace WebAPI
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
|
||||
|
||||
Reference in New Issue
Block a user