chore: init project
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
using System.Security.Claims;
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Authentication.Google;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace InboxIntel.Api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
public class AuthController : ControllerBase
|
||||
{
|
||||
/// <summary>Begins the Google OAuth2 login flow.</summary>
|
||||
[HttpGet("login")]
|
||||
[AllowAnonymous]
|
||||
public IActionResult Login([FromQuery] string? returnUrl = "/")
|
||||
=> Challenge(new AuthenticationProperties { RedirectUri = returnUrl }, GoogleDefaults.AuthenticationScheme);
|
||||
|
||||
[HttpPost("logout")]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> Logout()
|
||||
{
|
||||
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
/// <summary>Returns the currently signed-in user, or 401.</summary>
|
||||
[HttpGet("me")]
|
||||
[Authorize]
|
||||
public IActionResult Me() => Ok(new
|
||||
{
|
||||
UserId = User.FindFirstValue("inboxintel:uid"),
|
||||
Email = User.FindFirstValue(ClaimTypes.Email),
|
||||
Name = User.FindFirstValue(ClaimTypes.Name)
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user