Get User Id from Web API
This commit is contained in:
@ -14,6 +14,8 @@ namespace Yavsc.ApiControllers
|
|||||||
using Yavsc.Attributes.Validation;
|
using Yavsc.Attributes.Validation;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Yavsc.Exceptions;
|
using Yavsc.Exceptions;
|
||||||
|
using Yavsc.Server.Helpers;
|
||||||
|
using Yavsc.Abstract.Helpers;
|
||||||
|
|
||||||
[Authorize,Route("api/fs")]
|
[Authorize,Route("api/fs")]
|
||||||
public partial class FileSystemApiController : Controller
|
public partial class FileSystemApiController : Controller
|
||||||
|
@ -8,6 +8,7 @@ using Yavsc.Models;
|
|||||||
using Yavsc.Models.Messaging;
|
using Yavsc.Models.Messaging;
|
||||||
using Yavsc.Services;
|
using Yavsc.Services;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
using Yavsc.Server.Helpers;
|
||||||
|
|
||||||
namespace Yavsc.ApiControllers
|
namespace Yavsc.ApiControllers
|
||||||
{
|
{
|
||||||
|
@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Authorization;
|
|||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Yavsc.Helpers;
|
using Yavsc.Api.Helpers;
|
||||||
using Yavsc.Models;
|
using Yavsc.Models;
|
||||||
using Yavsc.Models.Workflow;
|
using Yavsc.Models.Workflow;
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ namespace Yavsc.ApiControllers
|
|||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Yavsc.ViewModels.Auth;
|
using Yavsc.ViewModels.Auth;
|
||||||
|
using Yavsc.Server.Helpers;
|
||||||
|
|
||||||
[Route("api/bill"), Authorize]
|
[Route("api/bill"), Authorize]
|
||||||
public class BillingController : Controller
|
public class BillingController : Controller
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Security.Claims;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
using Yavsc.Models;
|
using Yavsc.Models;
|
||||||
using Yavsc.Models.Account;
|
using Yavsc.Api.Helpers;
|
||||||
using Yavsc.ViewModels.Account;
|
using Yavsc.Server.Helpers;
|
||||||
using Yavsc.Helpers;
|
|
||||||
using Yavsc.Abstract.Identity;
|
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
namespace Yavsc.WebApi.Controllers
|
namespace Yavsc.WebApi.Controllers
|
||||||
{
|
{
|
||||||
@ -27,8 +23,6 @@ namespace Yavsc.WebApi.Controllers
|
|||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[HttpGet("me")]
|
[HttpGet("me")]
|
||||||
public async Task<IActionResult> Me()
|
public async Task<IActionResult> Me()
|
||||||
{
|
{
|
||||||
|
@ -8,7 +8,7 @@ using Yavsc.ViewModels;
|
|||||||
using Yavsc.Models;
|
using Yavsc.Models;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Yavsc.Helpers
|
namespace Yavsc.Api.Helpers
|
||||||
{
|
{
|
||||||
public static class RequestHelpers
|
public static class RequestHelpers
|
||||||
{
|
{
|
17
src/Api/Helpers/UserHelpers.cs
Normal file
17
src/Api/Helpers/UserHelpers.cs
Normal file
@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -66,7 +66,7 @@ internal class Program
|
|||||||
});
|
});
|
||||||
|
|
||||||
services.AddDbContext<ApplicationDbContext>(options =>
|
services.AddDbContext<ApplicationDbContext>(options =>
|
||||||
options.UseNpgsql(builder.Configuration.GetConnectionString("Default")));
|
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
|
||||||
|
|
||||||
services.AddTransient<ITrueEmailSender, MailSender>()
|
services.AddTransient<ITrueEmailSender, MailSender>()
|
||||||
.AddTransient<IBillingService, BillingService>()
|
.AddTransient<IBillingService, BillingService>()
|
||||||
@ -103,7 +103,8 @@ internal class Program
|
|||||||
|
|
||||||
// app.UseSession();
|
// app.UseSession();
|
||||||
await app.RunAsync();
|
await app.RunAsync();
|
||||||
};
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using Yavsc.Helpers;
|
using Yavsc.Server.Helpers;
|
||||||
|
|
||||||
namespace Yavsc.Attributes.Validation
|
namespace Yavsc.Attributes.Validation
|
||||||
{
|
{
|
||||||
|
@ -4,7 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Yavsc.ViewModels.UserFiles;
|
using Yavsc.ViewModels.UserFiles;
|
||||||
|
|
||||||
namespace Yavsc.Helpers
|
namespace Yavsc.Server.Helpers
|
||||||
{
|
{
|
||||||
public static class AbstractFileSystemHelpers
|
public static class AbstractFileSystemHelpers
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
namespace Yavsc.Helpers
|
namespace Yavsc.Abstract.Helpers
|
||||||
{
|
{
|
||||||
public enum ErrorCode {
|
public enum ErrorCode {
|
||||||
NotFound,
|
NotFound,
|
||||||
|
@ -2,7 +2,7 @@ using System;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Yavsc.Abstract.FileSystem;
|
using Yavsc.Abstract.FileSystem;
|
||||||
using Yavsc.Helpers;
|
using Yavsc.Server.Helpers;
|
||||||
|
|
||||||
namespace Yavsc.ViewModels.UserFiles
|
namespace Yavsc.ViewModels.UserFiles
|
||||||
{
|
{
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using Yavsc.Abstract.FileSystem;
|
|
||||||
using Yavsc.Billing;
|
using Yavsc.Billing;
|
||||||
using Yavsc.Models.Billing;
|
using Yavsc.Models.Billing;
|
||||||
|
using Yavsc.Server.Helpers;
|
||||||
using Yavsc.Services;
|
using Yavsc.Services;
|
||||||
|
|
||||||
namespace Yavsc.Helpers
|
namespace Yavsc.Helpers
|
||||||
|
@ -11,8 +11,9 @@ using SixLabors.ImageSharp;
|
|||||||
using SixLabors.ImageSharp.Processing;
|
using SixLabors.ImageSharp.Processing;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Yavsc.Exceptions;
|
using Yavsc.Exceptions;
|
||||||
|
using Yavsc.Helpers;
|
||||||
namespace Yavsc.Helpers
|
using Yavsc.Abstract.Helpers;
|
||||||
|
namespace Yavsc.Server.Helpers
|
||||||
{
|
{
|
||||||
public static class FileSystemHelpers
|
public static class FileSystemHelpers
|
||||||
{
|
{
|
||||||
|
@ -9,7 +9,6 @@ namespace Yavsc.Helpers
|
|||||||
{
|
{
|
||||||
public static class UserHelpers
|
public static class UserHelpers
|
||||||
{
|
{
|
||||||
|
|
||||||
public static string GetUserId(this ClaimsPrincipal user)
|
public static string GetUserId(this ClaimsPrincipal user)
|
||||||
{
|
{
|
||||||
return user.FindFirstValue("sub");
|
return user.FindFirstValue("sub");
|
||||||
|
@ -10,6 +10,7 @@ using Newtonsoft.Json;
|
|||||||
using Yavsc.Helpers;
|
using Yavsc.Helpers;
|
||||||
using Yavsc.Models;
|
using Yavsc.Models;
|
||||||
using Yavsc.Models.FileSystem;
|
using Yavsc.Models.FileSystem;
|
||||||
|
using Yavsc.Server.Helpers;
|
||||||
|
|
||||||
namespace Yavsc.ViewModels.Streaming
|
namespace Yavsc.ViewModels.Streaming
|
||||||
{
|
{
|
||||||
|
@ -12,6 +12,7 @@ namespace Yavsc.Controllers
|
|||||||
using Models.Billing;
|
using Models.Billing;
|
||||||
using Models.Workflow;
|
using Models.Workflow;
|
||||||
using ViewModels.Auth;
|
using ViewModels.Auth;
|
||||||
|
using Yavsc.Server.Helpers;
|
||||||
|
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public class EstimateController : Controller
|
public class EstimateController : Controller
|
||||||
|
@ -10,6 +10,7 @@ namespace Yavsc.Controllers
|
|||||||
using Microsoft.Extensions.Localization;
|
using Microsoft.Extensions.Localization;
|
||||||
using Models;
|
using Models;
|
||||||
using ViewModels.FrontOffice;
|
using ViewModels.FrontOffice;
|
||||||
|
using Yavsc.Server.Helpers;
|
||||||
using Yavsc.Services;
|
using Yavsc.Services;
|
||||||
|
|
||||||
public class FrontOfficeController : Controller
|
public class FrontOfficeController : Controller
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Yavsc.Helpers;
|
using Yavsc.Helpers;
|
||||||
|
using Yavsc.Server.Helpers;
|
||||||
|
|
||||||
namespace Yavsc.Controllers
|
namespace Yavsc.Controllers
|
||||||
{
|
{
|
||||||
|
@ -29,6 +29,7 @@ using Yavsc.Models.Workflow;
|
|||||||
using Yavsc.Services;
|
using Yavsc.Services;
|
||||||
using Yavsc.Settings;
|
using Yavsc.Settings;
|
||||||
using Yavsc.ViewModels.Auth;
|
using Yavsc.ViewModels.Auth;
|
||||||
|
using Yavsc.Server.Helpers;
|
||||||
|
|
||||||
namespace Yavsc.Extensions;
|
namespace Yavsc.Extensions;
|
||||||
|
|
||||||
@ -335,7 +336,6 @@ public static class HostingExtensions
|
|||||||
.AddInMemoryIdentityResources(Config.IdentityResources)
|
.AddInMemoryIdentityResources(Config.IdentityResources)
|
||||||
.AddInMemoryClients(Config.Clients)
|
.AddInMemoryClients(Config.Clients)
|
||||||
.AddInMemoryApiScopes(Config.ApiScopes)
|
.AddInMemoryApiScopes(Config.ApiScopes)
|
||||||
|
|
||||||
.AddAspNetIdentity<ApplicationUser>()
|
.AddAspNetIdentity<ApplicationUser>()
|
||||||
.AddProfileService<ProfileService>()
|
.AddProfileService<ProfileService>()
|
||||||
;
|
;
|
||||||
|
10
src/Yavsc/Helpers/UserHelpers.cs
Normal file
10
src/Yavsc/Helpers/UserHelpers.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
|
||||||
|
namespace Yavsc.Helpers
|
||||||
|
{
|
||||||
|
public static class UserHelpers
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authorization;
|
|||||||
using Microsoft.Extensions.Localization;
|
using Microsoft.Extensions.Localization;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Yavsc.Helpers;
|
using Yavsc.Helpers;
|
||||||
|
using Yavsc.Server.Helpers;
|
||||||
using Yavsc.Settings;
|
using Yavsc.Settings;
|
||||||
|
|
||||||
namespace Yavsc;
|
namespace Yavsc;
|
||||||
|
@ -8,6 +8,7 @@ using Yavsc.ViewModels;
|
|||||||
using Yavsc.ViewModels.Gen;
|
using Yavsc.ViewModels.Gen;
|
||||||
using Yavsc.Services;
|
using Yavsc.Services;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Yavsc.Server.Helpers;
|
||||||
|
|
||||||
namespace Yavsc.ViewComponents
|
namespace Yavsc.ViewComponents
|
||||||
{
|
{
|
||||||
|
@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Yavsc.Helpers;
|
using Yavsc.Helpers;
|
||||||
using Yavsc.Models;
|
using Yavsc.Models;
|
||||||
|
using Yavsc.Server.Helpers;
|
||||||
using Yavsc.ViewModels.UserFiles;
|
using Yavsc.ViewModels.UserFiles;
|
||||||
|
|
||||||
namespace Yavsc.ViewComponents
|
namespace Yavsc.ViewComponents
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<configuration>
|
|
||||||
<runtime>
|
|
||||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
</assemblyBinding>
|
|
||||||
</runtime>
|
|
||||||
</configuration>
|
|
@ -11,6 +11,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System.IdentityModel.Tokens.Jwt;
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
|
||||||
JwtSecurityTokenHandler.DefaultMapInboundClaims = false;
|
JwtSecurityTokenHandler.DefaultMapInboundClaims = false;
|
||||||
|
|
||||||
@ -36,6 +37,9 @@ builder.Services
|
|||||||
options.Scope.Add("openid");
|
options.Scope.Add("openid");
|
||||||
options.Scope.Add("profile");
|
options.Scope.Add("profile");
|
||||||
options.Scope.Add("scope2");
|
options.Scope.Add("scope2");
|
||||||
|
options.MapInboundClaims = true;
|
||||||
|
options.ClaimActions.MapUniqueJsonKey("preferred_username","preferred_username");
|
||||||
|
options.ClaimActions.MapUniqueJsonKey("gender", "gender");
|
||||||
|
|
||||||
options.SaveTokens = true;
|
options.SaveTokens = true;
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user