diff --git a/src/Api/Controllers/Blogspot/FileSystemApiController.cs b/src/Api/Controllers/Blogspot/FileSystemApiController.cs index e7b40dfec..2dc63d59a 100644 --- a/src/Api/Controllers/Blogspot/FileSystemApiController.cs +++ b/src/Api/Controllers/Blogspot/FileSystemApiController.cs @@ -14,6 +14,8 @@ namespace Yavsc.ApiControllers using Yavsc.Attributes.Validation; using System.IO; using Yavsc.Exceptions; + using Yavsc.Server.Helpers; + using Yavsc.Abstract.Helpers; [Authorize,Route("api/fs")] public partial class FileSystemApiController : Controller diff --git a/src/Api/Controllers/Blogspot/FileSystemStream.cs b/src/Api/Controllers/Blogspot/FileSystemStream.cs index af80fe7d5..e6b3c1590 100644 --- a/src/Api/Controllers/Blogspot/FileSystemStream.cs +++ b/src/Api/Controllers/Blogspot/FileSystemStream.cs @@ -8,6 +8,7 @@ using Yavsc.Models; using Yavsc.Models.Messaging; using Yavsc.Services; using Microsoft.AspNetCore.SignalR; +using Yavsc.Server.Helpers; namespace Yavsc.ApiControllers { diff --git a/src/Api/Controllers/Business/ActivityApiController.cs b/src/Api/Controllers/Business/ActivityApiController.cs index c661857ac..709fab7a0 100644 --- a/src/Api/Controllers/Business/ActivityApiController.cs +++ b/src/Api/Controllers/Business/ActivityApiController.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Yavsc.Helpers; +using Yavsc.Api.Helpers; using Yavsc.Models; using Yavsc.Models.Workflow; diff --git a/src/Api/Controllers/Business/BillingController.cs b/src/Api/Controllers/Business/BillingController.cs index 041359a24..5ab4a3322 100644 --- a/src/Api/Controllers/Business/BillingController.cs +++ b/src/Api/Controllers/Business/BillingController.cs @@ -15,6 +15,7 @@ namespace Yavsc.ApiControllers using Microsoft.Extensions.Options; using Microsoft.EntityFrameworkCore; using Yavsc.ViewModels.Auth; + using Yavsc.Server.Helpers; [Route("api/bill"), Authorize] public class BillingController : Controller diff --git a/src/Api/Controllers/accounting/AccountController.cs b/src/Api/Controllers/accounting/AccountController.cs index 5ae21995d..c1bb811a6 100644 --- a/src/Api/Controllers/accounting/AccountController.cs +++ b/src/Api/Controllers/accounting/AccountController.cs @@ -1,15 +1,11 @@ using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using System.Security.Claims; using Microsoft.EntityFrameworkCore; using Yavsc.Models; -using Yavsc.Models.Account; -using Yavsc.ViewModels.Account; -using Yavsc.Helpers; -using Yavsc.Abstract.Identity; -using System.Diagnostics; +using Yavsc.Api.Helpers; +using Yavsc.Server.Helpers; namespace Yavsc.WebApi.Controllers { @@ -27,8 +23,6 @@ namespace Yavsc.WebApi.Controllers _dbContext = dbContext; } - - [HttpGet("me")] public async Task Me() { diff --git a/src/Yavsc.Server/Helpers/RequestHelpers.cs b/src/Api/Helpers/RequestHelpers.cs similarity index 96% rename from src/Yavsc.Server/Helpers/RequestHelpers.cs rename to src/Api/Helpers/RequestHelpers.cs index 96f060c3c..2c2fae270 100644 --- a/src/Yavsc.Server/Helpers/RequestHelpers.cs +++ b/src/Api/Helpers/RequestHelpers.cs @@ -8,7 +8,7 @@ using Yavsc.ViewModels; using Yavsc.Models; using System.Linq; -namespace Yavsc.Helpers +namespace Yavsc.Api.Helpers { public static class RequestHelpers { diff --git a/src/Api/Helpers/UserHelpers.cs b/src/Api/Helpers/UserHelpers.cs new file mode 100644 index 000000000..2d480ea11 --- /dev/null +++ b/src/Api/Helpers/UserHelpers.cs @@ -0,0 +1,17 @@ +using System.Security.Claims; +using System.Collections.Generic; +using System.Linq; +using Microsoft.EntityFrameworkCore; +using Yavsc.Models; +using Yavsc.Models.Blog; + +namespace Yavsc.Api.Helpers +{ + public static class UserHelpers + { + public static string GetUserId(this ClaimsPrincipal user) + { + return user.FindFirstValue("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier"); + } + } +} diff --git a/src/Api/Program.cs b/src/Api/Program.cs index dd8a4606b..5ef8afdef 100644 --- a/src/Api/Program.cs +++ b/src/Api/Program.cs @@ -32,7 +32,7 @@ internal class Program // accepts any access token issued by identity server // adds an authorization policy for scope 'scope1' - + services .AddAuthorization(options => { @@ -40,7 +40,7 @@ internal class Program { policy .RequireAuthenticatedUser() - .RequireClaim(JwtClaimTypes.Scope, new string [] {"scope2"}); + .RequireClaim(JwtClaimTypes.Scope, new string[] { "scope2" }); }); }) .AddCors(options => @@ -63,21 +63,21 @@ internal class Program options.Authority = "https://localhost:5001"; options.TokenValidationParameters = new() { ValidateAudience = false }; - }); - - services.AddDbContext(options => - options.UseNpgsql(builder.Configuration.GetConnectionString("Default"))); - - services.AddTransient() - .AddTransient() - .AddTransient(); - /* - services.AddSingleton(); - services.AddSingleton(); - services.AddTransient(); - services.AddIdentityApiEndpoints(); - services.AddSession(); -*/ + }); + + services.AddDbContext(options => + options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"))); + + services.AddTransient() + .AddTransient() + .AddTransient(); + /* + services.AddSingleton(); + services.AddSingleton(); + services.AddTransient(); + services.AddIdentityApiEndpoints(); + services.AddSession(); + */ using (var app = builder.Build()) { if (app.Environment.IsDevelopment()) @@ -88,22 +88,23 @@ internal class Program .UseAuthentication() .UseAuthorization() .UseCors("default") - /* .UseEndpoints(endpoints => - { - endpoints.MapDefaultControllerRoute() - .RequireAuthorization(); - })*/ - + /* .UseEndpoints(endpoints => + { + endpoints.MapDefaultControllerRoute() + .RequireAuthorization(); + })*/ + ; - // app.MapIdentityApi().RequireAuthorization("ApiScope"); + // app.MapIdentityApi().RequireAuthorization("ApiScope"); app.MapDefaultControllerRoute(); app.MapGet("/identity", (HttpContext context) => new JsonResult(context?.User?.Claims.Select(c => new { c.Type, c.Value })) ); - // app.UseSession(); + // app.UseSession(); await app.RunAsync(); - }; + } + ; diff --git a/src/Yavsc.Abstract/Attributes/Validation/ValidRemoteUserDirAttribute.cs b/src/Yavsc.Abstract/Attributes/Validation/ValidRemoteUserDirAttribute.cs index 2c59f6890..43c440544 100644 --- a/src/Yavsc.Abstract/Attributes/Validation/ValidRemoteUserDirAttribute.cs +++ b/src/Yavsc.Abstract/Attributes/Validation/ValidRemoteUserDirAttribute.cs @@ -1,7 +1,7 @@ using System; using System.ComponentModel.DataAnnotations; -using Yavsc.Helpers; +using Yavsc.Server.Helpers; namespace Yavsc.Attributes.Validation { diff --git a/src/Yavsc.Abstract/FileSystem/AbstractFileSystemHelpers.cs b/src/Yavsc.Abstract/FileSystem/AbstractFileSystemHelpers.cs index 0b4aefbb1..5e571e249 100644 --- a/src/Yavsc.Abstract/FileSystem/AbstractFileSystemHelpers.cs +++ b/src/Yavsc.Abstract/FileSystem/AbstractFileSystemHelpers.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using Yavsc.ViewModels.UserFiles; -namespace Yavsc.Helpers +namespace Yavsc.Server.Helpers { public static class AbstractFileSystemHelpers { diff --git a/src/Yavsc.Abstract/FileSystem/FsOperationInfo.cs b/src/Yavsc.Abstract/FileSystem/FsOperationInfo.cs index ba748fbdd..63c69cb43 100644 --- a/src/Yavsc.Abstract/FileSystem/FsOperationInfo.cs +++ b/src/Yavsc.Abstract/FileSystem/FsOperationInfo.cs @@ -1,4 +1,4 @@ -namespace Yavsc.Helpers +namespace Yavsc.Abstract.Helpers { public enum ErrorCode { NotFound, diff --git a/src/Yavsc.Abstract/FileSystem/UserDirectoryInfo.cs b/src/Yavsc.Abstract/FileSystem/UserDirectoryInfo.cs index 77b7e6e45..cced9397d 100644 --- a/src/Yavsc.Abstract/FileSystem/UserDirectoryInfo.cs +++ b/src/Yavsc.Abstract/FileSystem/UserDirectoryInfo.cs @@ -2,7 +2,7 @@ using System; using System.IO; using System.Linq; using Yavsc.Abstract.FileSystem; -using Yavsc.Helpers; +using Yavsc.Server.Helpers; namespace Yavsc.ViewModels.UserFiles { diff --git a/src/Yavsc.Server/Helpers/BillingHelpers.cs b/src/Yavsc.Server/Helpers/BillingHelpers.cs index 0a8264472..c10a76155 100644 --- a/src/Yavsc.Server/Helpers/BillingHelpers.cs +++ b/src/Yavsc.Server/Helpers/BillingHelpers.cs @@ -1,10 +1,7 @@ -using System.Collections.Generic; using System.Globalization; -using System.IO; -using System.Linq; -using Yavsc.Abstract.FileSystem; using Yavsc.Billing; using Yavsc.Models.Billing; +using Yavsc.Server.Helpers; using Yavsc.Services; namespace Yavsc.Helpers diff --git a/src/Yavsc.Server/Helpers/FileSystemHelpers.cs b/src/Yavsc.Server/Helpers/FileSystemHelpers.cs index 287218156..f0d5782b7 100644 --- a/src/Yavsc.Server/Helpers/FileSystemHelpers.cs +++ b/src/Yavsc.Server/Helpers/FileSystemHelpers.cs @@ -11,8 +11,9 @@ using SixLabors.ImageSharp; using SixLabors.ImageSharp.Processing; using Microsoft.AspNetCore.Http; using Yavsc.Exceptions; - -namespace Yavsc.Helpers +using Yavsc.Helpers; +using Yavsc.Abstract.Helpers; +namespace Yavsc.Server.Helpers { public static class FileSystemHelpers { diff --git a/src/Yavsc.Server/Helpers/UserHelpers.cs b/src/Yavsc.Server/Helpers/UserHelpers.cs index e6db83139..e319239df 100644 --- a/src/Yavsc.Server/Helpers/UserHelpers.cs +++ b/src/Yavsc.Server/Helpers/UserHelpers.cs @@ -9,7 +9,6 @@ namespace Yavsc.Helpers { public static class UserHelpers { - public static string GetUserId(this ClaimsPrincipal user) { return user.FindFirstValue("sub"); diff --git a/src/Yavsc.Server/ViewModels/LiveCastHandler.cs b/src/Yavsc.Server/ViewModels/LiveCastHandler.cs index fc71e760c..e5e835064 100644 --- a/src/Yavsc.Server/ViewModels/LiveCastHandler.cs +++ b/src/Yavsc.Server/ViewModels/LiveCastHandler.cs @@ -10,6 +10,7 @@ using Newtonsoft.Json; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.FileSystem; +using Yavsc.Server.Helpers; namespace Yavsc.ViewModels.Streaming { diff --git a/src/Yavsc/Controllers/Contracting/EstimateController.cs b/src/Yavsc/Controllers/Contracting/EstimateController.cs index d68c36569..b81af7567 100644 --- a/src/Yavsc/Controllers/Contracting/EstimateController.cs +++ b/src/Yavsc/Controllers/Contracting/EstimateController.cs @@ -12,6 +12,7 @@ namespace Yavsc.Controllers using Models.Billing; using Models.Workflow; using ViewModels.Auth; + using Yavsc.Server.Helpers; [Authorize] public class EstimateController : Controller diff --git a/src/Yavsc/Controllers/Contracting/FrontOfficeController.cs b/src/Yavsc/Controllers/Contracting/FrontOfficeController.cs index 55a04fb0e..666fa501d 100644 --- a/src/Yavsc/Controllers/Contracting/FrontOfficeController.cs +++ b/src/Yavsc/Controllers/Contracting/FrontOfficeController.cs @@ -10,6 +10,7 @@ namespace Yavsc.Controllers using Microsoft.Extensions.Localization; using Models; using ViewModels.FrontOffice; + using Yavsc.Server.Helpers; using Yavsc.Services; public class FrontOfficeController : Controller diff --git a/src/Yavsc/Controllers/FileSystemController.cs b/src/Yavsc/Controllers/FileSystemController.cs index 36ebcb044..845796759 100644 --- a/src/Yavsc/Controllers/FileSystemController.cs +++ b/src/Yavsc/Controllers/FileSystemController.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Yavsc.Helpers; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Yavsc/Extensions/HostingExtensions.cs b/src/Yavsc/Extensions/HostingExtensions.cs index d781de86e..d86f82592 100644 --- a/src/Yavsc/Extensions/HostingExtensions.cs +++ b/src/Yavsc/Extensions/HostingExtensions.cs @@ -29,6 +29,7 @@ using Yavsc.Models.Workflow; using Yavsc.Services; using Yavsc.Settings; using Yavsc.ViewModels.Auth; +using Yavsc.Server.Helpers; namespace Yavsc.Extensions; @@ -335,7 +336,6 @@ public static class HostingExtensions .AddInMemoryIdentityResources(Config.IdentityResources) .AddInMemoryClients(Config.Clients) .AddInMemoryApiScopes(Config.ApiScopes) - .AddAspNetIdentity() .AddProfileService() ; diff --git a/src/Yavsc/Helpers/UserHelpers.cs b/src/Yavsc/Helpers/UserHelpers.cs new file mode 100644 index 000000000..ade8cac02 --- /dev/null +++ b/src/Yavsc/Helpers/UserHelpers.cs @@ -0,0 +1,10 @@ +using System.Security.Claims; + +namespace Yavsc.Helpers +{ + public static class UserHelpers + { + + + } +} diff --git a/src/Yavsc/Startup.cs b/src/Yavsc/Startup.cs index 1625debf2..93cf5dcff 100644 --- a/src/Yavsc/Startup.cs +++ b/src/Yavsc/Startup.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; using Yavsc.Helpers; +using Yavsc.Server.Helpers; using Yavsc.Settings; namespace Yavsc; diff --git a/src/Yavsc/ViewComponents/BillViewComponent.cs b/src/Yavsc/ViewComponents/BillViewComponent.cs index 4f7c3fc5f..d0d0b9fea 100644 --- a/src/Yavsc/ViewComponents/BillViewComponent.cs +++ b/src/Yavsc/ViewComponents/BillViewComponent.cs @@ -8,6 +8,7 @@ using Yavsc.ViewModels; using Yavsc.ViewModels.Gen; using Yavsc.Services; using Microsoft.EntityFrameworkCore; +using Yavsc.Server.Helpers; namespace Yavsc.ViewComponents { diff --git a/src/Yavsc/ViewComponents/DirectoryViewComponent.cs b/src/Yavsc/ViewComponents/DirectoryViewComponent.cs index b5f5b902b..af7f436b1 100644 --- a/src/Yavsc/ViewComponents/DirectoryViewComponent.cs +++ b/src/Yavsc/ViewComponents/DirectoryViewComponent.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc; using System.Threading.Tasks; using Yavsc.Helpers; using Yavsc.Models; +using Yavsc.Server.Helpers; using Yavsc.ViewModels.UserFiles; namespace Yavsc.ViewComponents diff --git a/src/Yavsc/app.config b/src/Yavsc/app.config deleted file mode 100644 index 8460dd432..000000000 --- a/src/Yavsc/app.config +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/src/sampleWebAsWebApiClient/Program.cs b/src/sampleWebAsWebApiClient/Program.cs index 314264839..5cc25c361 100644 --- a/src/sampleWebAsWebApiClient/Program.cs +++ b/src/sampleWebAsWebApiClient/Program.cs @@ -11,6 +11,7 @@ */ using System.IdentityModel.Tokens.Jwt; +using Microsoft.AspNetCore.Authentication; JwtSecurityTokenHandler.DefaultMapInboundClaims = false; @@ -36,7 +37,10 @@ builder.Services options.Scope.Add("openid"); options.Scope.Add("profile"); options.Scope.Add("scope2"); - + options.MapInboundClaims = true; + options.ClaimActions.MapUniqueJsonKey("preferred_username","preferred_username"); + options.ClaimActions.MapUniqueJsonKey("gender", "gender"); + options.SaveTokens = true; });