49 lines
1.6 KiB
C#
49 lines
1.6 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;
|
|
}
|
|
}
|