|
@ -15,6 +15,7 @@ using Microsoft.AspNetCore.Mvc; |
|
|
using Microsoft.eShopOnContainers.Services.Identity.API.Models; |
|
|
using Microsoft.eShopOnContainers.Services.Identity.API.Models; |
|
|
using Microsoft.eShopOnContainers.Services.Identity.API.Models.AccountViewModels; |
|
|
using Microsoft.eShopOnContainers.Services.Identity.API.Models.AccountViewModels; |
|
|
using Microsoft.eShopOnContainers.Services.Identity.API.Services; |
|
|
using Microsoft.eShopOnContainers.Services.Identity.API.Services; |
|
|
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
using Microsoft.Extensions.Logging; |
|
|
using Microsoft.Extensions.Logging; |
|
|
|
|
|
|
|
|
namespace Microsoft.eShopOnContainers.Services.Identity.API.Controllers |
|
|
namespace Microsoft.eShopOnContainers.Services.Identity.API.Controllers |
|
@ -32,6 +33,7 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Controllers |
|
|
private readonly IClientStore _clientStore; |
|
|
private readonly IClientStore _clientStore; |
|
|
private readonly ILogger<AccountController> _logger; |
|
|
private readonly ILogger<AccountController> _logger; |
|
|
private readonly UserManager<ApplicationUser> _userManager; |
|
|
private readonly UserManager<ApplicationUser> _userManager; |
|
|
|
|
|
private readonly IConfiguration _configuration; |
|
|
|
|
|
|
|
|
public AccountController( |
|
|
public AccountController( |
|
|
|
|
|
|
|
@ -40,13 +42,15 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Controllers |
|
|
IIdentityServerInteractionService interaction, |
|
|
IIdentityServerInteractionService interaction, |
|
|
IClientStore clientStore, |
|
|
IClientStore clientStore, |
|
|
ILogger<AccountController> logger, |
|
|
ILogger<AccountController> logger, |
|
|
UserManager<ApplicationUser> userManager) |
|
|
|
|
|
|
|
|
UserManager<ApplicationUser> userManager, |
|
|
|
|
|
IConfiguration configuration) |
|
|
{ |
|
|
{ |
|
|
_loginService = loginService; |
|
|
_loginService = loginService; |
|
|
_interaction = interaction; |
|
|
_interaction = interaction; |
|
|
_clientStore = clientStore; |
|
|
_clientStore = clientStore; |
|
|
_logger = logger; |
|
|
_logger = logger; |
|
|
_userManager = userManager; |
|
|
_userManager = userManager; |
|
|
|
|
|
_configuration = configuration; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
@ -81,20 +85,21 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Controllers |
|
|
|
|
|
|
|
|
if (await _loginService.ValidateCredentials(user, model.Password)) |
|
|
if (await _loginService.ValidateCredentials(user, model.Password)) |
|
|
{ |
|
|
{ |
|
|
|
|
|
var tokenLifetime = _configuration.GetValue("TokenLifetimeMinutes", 120); |
|
|
|
|
|
|
|
|
var props = new AuthenticationProperties |
|
|
var props = new AuthenticationProperties |
|
|
{ |
|
|
{ |
|
|
ExpiresUtc = DateTimeOffset.UtcNow.AddHours(2), |
|
|
|
|
|
|
|
|
ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(tokenLifetime), |
|
|
AllowRefresh = true, |
|
|
AllowRefresh = true, |
|
|
RedirectUri = model.ReturnUrl |
|
|
RedirectUri = model.ReturnUrl |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
if (model.RememberMe) |
|
|
if (model.RememberMe) |
|
|
{ |
|
|
{ |
|
|
props = new AuthenticationProperties |
|
|
|
|
|
{ |
|
|
|
|
|
IsPersistent = true, |
|
|
|
|
|
ExpiresUtc = DateTimeOffset.UtcNow.AddYears(10) |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
var permanentTokenLifetime = _configuration.GetValue("PermanentTokenLifetimeDays", 365); |
|
|
|
|
|
|
|
|
|
|
|
props.ExpiresUtc = DateTimeOffset.UtcNow.AddDays(permanentTokenLifetime); |
|
|
|
|
|
props.IsPersistent = true; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
await _loginService.SignInAsync(user, props); |
|
|
await _loginService.SignInAsync(user, props); |
|
|