-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathMeController.cs
More file actions
31 lines (26 loc) · 931 Bytes
/
MeController.cs
File metadata and controls
31 lines (26 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System.Net.Mime;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace SimpleAuthentication.WebApi.Controllers;
[ApiController]
[Route("api/[controller]")]
[Produces(MediaTypeNames.Application.Json)]
public class MeController : ControllerBase
{
[Authorize]
[HttpGet("authorize-bearer")]
[ProducesResponseType(typeof(User), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesDefaultResponseType]
public ActionResult<User> GetWithBearer()
=> new User(User.Identity!.Name);
[Authorize(AuthenticationSchemes = "ApiKey")]
[HttpGet("authorize-apikey")]
public User GetWithApiKey()
=> new(User.Identity!.Name);
[Authorize(AuthenticationSchemes = "Auth0")]
[HttpGet("authorize-auth0")]
public User GetWithAuth0()
=> new("Auth0 default user");
}
public record class User(string? UserName);