Add a property to retrieve the claims (id and login) in the token

This commit is contained in:
Sébastien André
2020-03-20 19:34:27 +01:00
parent 7bad7e80d5
commit c15ad54823
11 changed files with 44 additions and 12 deletions

View File

@@ -0,0 +1,30 @@
using System;
using System.Linq;
using System.Security.Claims;
using Microsoft.AspNetCore.Mvc;
using skydiveLogs_api.Model;
namespace skydiveLogs_api.Controllers
{
public class Base : ControllerBase
{
public User ConnectedUser
{
get
{
if (_connectedUser == null)
{
_connectedUser = new User();
_connectedUser.Login = User.Claims.Single(c => c.Type == ClaimTypes.Name).Value;
_connectedUser.Id = Convert.ToInt32(User.Claims.Single(c => c.Type == ClaimTypes.UserData).Value);
}
return _connectedUser;
}
}
private User _connectedUser;
}
}