eShopOnContainers/src/Web/WebMVC/Controllers/AccountController.cs

41 lines
1.4 KiB
C#
Raw Normal View History

using System.Security.Claims;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http.Authentication;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
namespace Microsoft.eShopOnContainers.WebMVC.Controllers
{
[Authorize]
public class AccountController : Controller
2017-08-21 17:57:53 +02:00
{
[Authorize]
public async Task<IActionResult> SignIn(string returnUrl)
{
var user = User as ClaimsPrincipal;
var token = await HttpContext.Authentication.GetTokenAsync("access_token");
if (token != null)
{
ViewData["access_token"] = token;
}
2017-02-23 10:02:35 -08:00
// "Catalog" because UrlHelper doesn't support nameof() for controllers
// https://github.com/aspnet/Mvc/issues/5853
return RedirectToAction(nameof(CatalogController.Index), "Catalog");
}
public IActionResult Signout()
{
HttpContext.Authentication.SignOutAsync("Cookies");
HttpContext.Authentication.SignOutAsync("oidc");
2017-02-23 10:02:35 -08:00
// "Catalog" because UrlHelper doesn't support nameof() for controllers
// https://github.com/aspnet/Mvc/issues/5853
var homeUrl = Url.Action(nameof(CatalogController.Index), "Catalog");
return new SignOutResult("oidc", new AuthenticationProperties { RedirectUri = homeUrl });
}
}
}