Added oidc service to webapi with a dumb way of authenticating incoming tokens

This commit is contained in:
2021-10-13 22:26:45 -04:00
parent cccd609233
commit 33cbb4f136
13 changed files with 120 additions and 114 deletions

View File

@@ -0,0 +1,16 @@
using System;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Net.Http.Headers;
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()
: String.Empty;
}
}

View File

@@ -10,20 +10,26 @@ namespace WebAPI.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class HelloWorldController : ControllerBase
public class HelloWorldController : BaseController
{
private readonly PterodactylService _pterodactylService;
private readonly OIDCService _oidcService;
public HelloWorldController(PterodactylService pterodactylService)
public HelloWorldController(PterodactylService pterodactylService, OIDCService oidcService)
{
_pterodactylService = pterodactylService;
_oidcService = oidcService;
}
[HttpGet]
public async Task<string> HelloWorld()
{
await Task.Delay(5000);
return AppSettings.PterodactylAPIKey;
if (await _oidcService.ValidateAccessToken(BearerToken))
{
return "Validated";
}
return "Failed";
}
}
}