This repository has been archived on 2025-08-13. You can view files and clone it, but cannot push or open issues or pull requests.
Files
KTUSA-PS/KTUSAPS/Controllers/AuthMetadataController.cs
Karolis2011 cad4268b79 Some stuff
2021-12-22 22:50:09 +02:00

54 lines
1.7 KiB
C#

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
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 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.Status200OK)]
[HttpGet("Authed")]
public bool IsAuthed() => true;
[Authorize("admin")]
[ProducesResponseType(StatusCodes.Status200OK)]
[HttpGet("Admin")]
public bool IsAdmin() => true;
}
}