Add project files.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
namespace MyOffice.Web.Controllers;
|
||||
|
||||
using System.Security.Authentication;
|
||||
using Core.Extensions;
|
||||
using IdentityModel;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using static IdentityServer4.Models.IdentityResources;
|
||||
|
||||
public class BaseApiController : ControllerBase
|
||||
{
|
||||
public Guid UserId
|
||||
{
|
||||
get
|
||||
{
|
||||
var subject = User.Claims.FirstOrDefault(x => x.Type == JwtClaimTypes.Subject)?.Value;
|
||||
if (subject.IsPresent() && Guid.TryParse(subject, out var guid)) return guid;
|
||||
|
||||
throw new AuthenticationException("Get UserId failed");
|
||||
}
|
||||
}
|
||||
|
||||
public ObjectResult ProblemBadRequest(string? detail = null)
|
||||
{
|
||||
return Problem(detail, statusCode: StatusCodes.Status400BadRequest);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user