Added oidc service to webapi with a dumb way of authenticating incoming tokens
This commit is contained in:
16
WebAPI/Controllers/BaseController.cs
Normal file
16
WebAPI/Controllers/BaseController.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user