You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
966 B
33 lines
966 B
using System.Diagnostics;
|
|
using System.Security.Claims;
|
|
using Microsoft.AspNetCore.Authentication;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using OAuthClient.Models;
|
|
|
|
namespace OAuthClient.Controllers;
|
|
|
|
public class HomeController : Controller {
|
|
public IActionResult Index() {
|
|
return View();
|
|
}
|
|
|
|
[Authorize]
|
|
public IActionResult AuthCheck() {
|
|
var userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
|
|
|
|
ViewData["UserId"] = userId;
|
|
|
|
return View();
|
|
}
|
|
|
|
[AllowAnonymous]
|
|
public IActionResult Login() {
|
|
return Challenge(new AuthenticationProperties {RedirectUri = "/Home/AuthCheck"}, "OAuth");
|
|
}
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public IActionResult Error() {
|
|
return View(new ErrorViewModel {RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier});
|
|
}
|
|
} |