2016-11-29 15:10:16 +01:00
|
|
|
|
using System.Security.Claims;
|
2016-09-06 17:09:19 -07:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2017-03-03 16:00:15 +01:00
|
|
|
|
using Microsoft.eShopOnContainers.WebMVC.ViewModels;
|
2016-09-07 13:52:26 -07:00
|
|
|
|
using Microsoft.eShopOnContainers.WebMVC.Services;
|
2016-11-29 15:10:16 +01:00
|
|
|
|
using Microsoft.AspNetCore.Http.Authentication;
|
2017-06-05 21:54:03 +02:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.AspNetCore.Authentication;
|
2016-09-06 17:09:19 -07:00
|
|
|
|
|
2016-09-07 13:52:26 -07:00
|
|
|
|
namespace Microsoft.eShopOnContainers.WebMVC.Controllers
|
2016-09-06 17:09:19 -07:00
|
|
|
|
{
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class AccountController : Controller
|
|
|
|
|
{
|
2016-11-28 12:58:51 +01:00
|
|
|
|
private readonly IIdentityParser<ApplicationUser> _identityParser;
|
2017-03-20 14:18:20 -04:00
|
|
|
|
public AccountController(IIdentityParser<ApplicationUser> identityParser) =>
|
2016-11-28 12:58:51 +01:00
|
|
|
|
_identityParser = identityParser;
|
2016-09-06 17:09:19 -07:00
|
|
|
|
|
2017-03-20 14:18:20 -04:00
|
|
|
|
public ActionResult Index() => View();
|
|
|
|
|
|
2016-11-28 12:58:51 +01:00
|
|
|
|
[Authorize]
|
2017-06-05 21:54:03 +02:00
|
|
|
|
public async Task<IActionResult> SignIn(string returnUrl)
|
2016-09-06 17:09:19 -07:00
|
|
|
|
{
|
2016-11-28 12:58:51 +01:00
|
|
|
|
var user = User as ClaimsPrincipal;
|
2017-06-05 21:54:03 +02:00
|
|
|
|
var token = await HttpContext.Authentication.GetTokenAsync("access_token");
|
|
|
|
|
|
2016-11-28 12:58:51 +01:00
|
|
|
|
if (token != null)
|
2016-09-06 17:09:19 -07:00
|
|
|
|
{
|
2017-06-05 21:54:03 +02:00
|
|
|
|
ViewData["access_token"] = token;
|
2016-09-06 17:09:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
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");
|
2016-09-06 17:09:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-29 15:10:16 +01:00
|
|
|
|
public IActionResult Signout()
|
2016-09-06 17:09:19 -07:00
|
|
|
|
{
|
2016-12-07 13:57:31 +01:00
|
|
|
|
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 });
|
2016-09-06 17:09:19 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|