Huge work

This commit is contained in:
Karolis Kundrotas
2021-10-25 22:00:01 +03:00
parent c3bb8983ef
commit aff6f8df82
26 changed files with 578 additions and 68 deletions

View File

@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System;
@@ -10,15 +11,39 @@ namespace KTUSAPS.Controllers
{
[Route("api/[controller]")]
[ApiController]
[Produces("application/json")]
public class AuthMetadataController : ControllerBase
{
public class AuthMetadata
{
public string ClientId { get; set; }
public string Authority { get; set; }
public string Tenant { get; set; }
}
private readonly IConfiguration _configuration;
public AuthMetadataController(IConfiguration configuration)
{
_configuration = configuration;
}
/// <summary>
/// Get authethication metadata needed to obtain token.
/// </summary>
/// <returns></returns>
[HttpGet]
public object Index() => new { ClientId = _configuration["ClientId"], Authority = _configuration["Authority"], Tenant = _configuration["Tenant"] };
public AuthMetadata Index() => new AuthMetadata { ClientId = _configuration["ClientId"], Authority = _configuration["Authority"], Tenant = _configuration["Tenant"] };
/// <summary>
/// Returns true is provided token is valid, else throws exception
/// </summary>
/// <returns></returns>
/// <response code="200">Provided token is correct.</response>
/// <response code="401">No valid token provided.</response>
[Authorize]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status200OK)]
[HttpGet("Authed")]
public bool IsAuthed() => true;
}
}