Added userinfo endpoint usage and api now properly creates necessary claims to start doing database stuff
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
@@ -7,10 +9,5 @@ namespace WebAPI.Controllers
|
||||
{
|
||||
public class BaseController : ControllerBase
|
||||
{
|
||||
protected string BearerToken =>
|
||||
Request.Headers.Keys.Contains(HeaderNames.Authorization) &&
|
||||
Request.Headers[HeaderNames.Authorization].Count > 0
|
||||
? Request.Headers[HeaderNames.Authorization].First().Split(" ")[1]
|
||||
: String.Empty;
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,13 @@ using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using WebAPI.Auth;
|
||||
using WebAPI.Data;
|
||||
|
||||
namespace WebAPI.Controllers
|
||||
{
|
||||
[Authorize(Policy = "test")]
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class HelloWorldController : BaseController
|
||||
@@ -25,7 +26,14 @@ namespace WebAPI.Controllers
|
||||
[HttpGet]
|
||||
public async Task<string> HelloWorld()
|
||||
{
|
||||
return "Success";
|
||||
return JsonConvert.SerializeObject(User.Claims.Select(claim => new {claim.Type, claim.Value}));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("NameRequired")]
|
||||
public string NameRequired()
|
||||
{
|
||||
return "success";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user