38 lines
1.9 KiB
C#
38 lines
1.9 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace OpenID_API.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("[controller]")]
|
|
public class WeatherForecastController : ControllerBase
|
|
{
|
|
private static readonly string[] Summaries =
|
|
[
|
|
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
|
];
|
|
|
|
// Any authenticated user can access this endpoint, regardless of their role.
|
|
// This is the most basic level of authorization, which only checks if the user is authenticated.
|
|
[Authorize]
|
|
// The following lines are examples of how to restrict access to specific roles. Uncomment the desired line(s) to apply the restriction.
|
|
// This is the way you can specify multiple roles for an endpoint. You can use a comma-separated list to allow access to users with any of the specified roles.
|
|
// [Authorize(Roles = "user")] //Only users with the "user" role can access this endpoint
|
|
// [Authorize(Roles = "owner")] //Only users with the "owner" role can access this endpoint
|
|
// [Authorize(Roles = "admin")] //Only users with the "admin" role can access this endpoint
|
|
// [Authorize(Roles = "user,owner")] //Only users with either the "user" or "owner" role can access this endpoint
|
|
[HttpGet]
|
|
public IEnumerable<WeatherForecast> Get()
|
|
{
|
|
var xxx = User;
|
|
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
|
{
|
|
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
|
TemperatureC = Random.Shared.Next(-20, 55),
|
|
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
|
})
|
|
.ToArray();
|
|
}
|
|
}
|
|
}
|